[PATCH] Compilation: zero-length array declaration.
ISO C99 (and GCC 3.x or later) lets you write a flexible array at the end of a structure, like this: struct frotz { int xyzzy; char nitfol[]; /* more */ }; GCC 2.95 and 2.96 let you to do this with "char nitfol[0]"; unfortunately this is not allowed by ISO C90. This declares such construct like this: struct frotz { int xyzzy; char nitfol[FLEX_ARRAY]; /* more */ }; and git-compat-util.h defines FLEX_ARRAY to 0 for gcc 2.95 and empty for others. If you are using a C90 C compiler, you should be able to override this with CFLAGS=-DFLEX_ARRAY=1 from the command line of "make". Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 7, 2006 at 01:33 UTC
8f1d2e6f49ee51ac062ab38337a6a70dd1998def
10 files changed
+21
-12
blob.c
+1
-1
@@ -1,5 +1,5 @@
1
-#include "blob.h"
1
#include "cache.h"
2
+#include "blob.h"
3
#include <stdlib.h>
4
5
const char *blob_type = "blob";
cache.h
+5
-4
@@ -81,7 +81,7 @@ struct cache_entry {
81
unsigned int ce_size;
82
unsigned char sha1[20];
83
unsigned short ce_flags;
84
- char name[0];
84
+ char name[FLEX_ARRAY]; /* more */
85
};
86
87
#define CE_NAMEMASK (0x0fff)
@@ -257,7 +257,7 @@ extern int checkout_entry(struct cache_entry *ce, struct checkout *state);
257
extern struct alternate_object_database {
258
struct alternate_object_database *next;
259
char *name;
260
- char base[0]; /* more */
260
+ char base[FLEX_ARRAY]; /* more */
261
} *alt_odb_list;
262
extern void prepare_alt_odb(void);
263
@@ -271,7 +271,8 @@ extern struct packed_git {
271
unsigned int pack_use_cnt;
272
int pack_local;
273
unsigned char sha1[20];
274
- char pack_name[0]; /* something like ".git/objects/pack/xxxxx.pack" */
274
+ /* something like ".git/objects/pack/xxxxx.pack" */
275
+ char pack_name[FLEX_ARRAY]; /* more */
276
} *packed_git;
277
278
struct pack_entry {
@@ -286,7 +287,7 @@ struct ref {
287
unsigned char new_sha1[20];
288
unsigned char force;
289
struct ref *peer_ref; /* when renaming */
289
- char name[0];
290
+ char name[FLEX_ARRAY]; /* more */
291
};
292
293
extern int git_connect(int fd[2], char *url, const char *prog);
commit.c
+1
-1
@@ -1,6 +1,6 @@
1
+#include "cache.h"
2
#include "tag.h"
3
#include "commit.h"
3
-#include "cache.h"
4
5
int save_commit_buffer = 1;
6
git-compat-util.h
+8
@@ -1,6 +1,14 @@
1
#ifndef GIT_COMPAT_UTIL_H
2
#define GIT_COMPAT_UTIL_H
3
4
+#ifndef FLEX_ARRAY
5
+#if defined(__GNUC__) && (__GNUC__ < 3)
6
+#define FLEX_ARRAY 0
7
+#else
8
+#define FLEX_ARRAY /* empty */
9
+#endif
10
+#endif
11
+
12
#include <unistd.h>
13
#include <stdio.h>
14
#include <sys/stat.h>
ls-files.c
+1
-1
@@ -208,7 +208,7 @@ static int excluded(const char *pathname)
208
209
struct nond_on_fs {
210
int len;
211
- char name[0];
211
+ char name[FLEX_ARRAY]; /* more */
212
};
213
214
static struct nond_on_fs **dir;
object.c
+1
-1
@@ -1,8 +1,8 @@
1
+#include "cache.h"
2
#include "object.h"
3
#include "blob.h"
4
#include "tree.h"
5
#include "commit.h"
5
-#include "cache.h"
6
#include "tag.h"
7
8
struct object **objs;
object.h
+1
-1
@@ -9,7 +9,7 @@ struct object_list {
9
10
struct object_refs {
11
unsigned count;
12
- struct object *ref[0];
12
+ struct object *ref[FLEX_ARRAY]; /* more */
13
};
14
15
struct object {
receive-pack.c
+1
-1
@@ -24,7 +24,7 @@ struct command {
24
unsigned char updated;
25
unsigned char old_sha1[20];
26
unsigned char new_sha1[20];
27
- char ref_name[0];
27
+ char ref_name[FLEX_ARRAY]; /* more */
28
};
29
30
static struct command *commands = NULL;
tag.c
+1
-1
@@ -1,5 +1,5 @@
1
-#include "tag.h"
1
#include "cache.h"
2
+#include "tag.h"
3
4
const char *tag_type = "tag";
5
tree.c
+1
-1
@@ -1,8 +1,8 @@
1
+#include "cache.h"
2
#include "tree.h"
3
#include "blob.h"
4
#include "commit.h"
5
#include "tag.h"
5
-#include "cache.h"
6
#include <stdlib.h>
7
8
const char *tree_type = "tree";