Skip to content

Commit 8f1d2e6

Browse files
author
Junio C Hamano
committed
[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>
1 parent 3be7098 commit 8f1d2e6

File tree

10 files changed

+21
-12
lines changed

10 files changed

+21
-12
lines changed

blob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "blob.h"
21
#include "cache.h"
2+
#include "blob.h"
33
#include <stdlib.h>
44

55
const char *blob_type = "blob";

cache.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct cache_entry {
8181
unsigned int ce_size;
8282
unsigned char sha1[20];
8383
unsigned short ce_flags;
84-
char name[0];
84+
char name[FLEX_ARRAY]; /* more */
8585
};
8686

8787
#define CE_NAMEMASK (0x0fff)
@@ -257,7 +257,7 @@ extern int checkout_entry(struct cache_entry *ce, struct checkout *state);
257257
extern struct alternate_object_database {
258258
struct alternate_object_database *next;
259259
char *name;
260-
char base[0]; /* more */
260+
char base[FLEX_ARRAY]; /* more */
261261
} *alt_odb_list;
262262
extern void prepare_alt_odb(void);
263263

@@ -271,7 +271,8 @@ extern struct packed_git {
271271
unsigned int pack_use_cnt;
272272
int pack_local;
273273
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 */
275276
} *packed_git;
276277

277278
struct pack_entry {
@@ -286,7 +287,7 @@ struct ref {
286287
unsigned char new_sha1[20];
287288
unsigned char force;
288289
struct ref *peer_ref; /* when renaming */
289-
char name[0];
290+
char name[FLEX_ARRAY]; /* more */
290291
};
291292

292293
extern int git_connect(int fd[2], char *url, const char *prog);

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
#include "cache.h"
12
#include "tag.h"
23
#include "commit.h"
3-
#include "cache.h"
44

55
int save_commit_buffer = 1;
66

git-compat-util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#ifndef GIT_COMPAT_UTIL_H
22
#define GIT_COMPAT_UTIL_H
33

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+
412
#include <unistd.h>
513
#include <stdio.h>
614
#include <sys/stat.h>

ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int excluded(const char *pathname)
208208

209209
struct nond_on_fs {
210210
int len;
211-
char name[0];
211+
char name[FLEX_ARRAY]; /* more */
212212
};
213213

214214
static struct nond_on_fs **dir;

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
#include "cache.h"
12
#include "object.h"
23
#include "blob.h"
34
#include "tree.h"
45
#include "commit.h"
5-
#include "cache.h"
66
#include "tag.h"
77

88
struct object **objs;

object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct object_list {
99

1010
struct object_refs {
1111
unsigned count;
12-
struct object *ref[0];
12+
struct object *ref[FLEX_ARRAY]; /* more */
1313
};
1414

1515
struct object {

receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct command {
2424
unsigned char updated;
2525
unsigned char old_sha1[20];
2626
unsigned char new_sha1[20];
27-
char ref_name[0];
27+
char ref_name[FLEX_ARRAY]; /* more */
2828
};
2929

3030
static struct command *commands = NULL;

tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "tag.h"
21
#include "cache.h"
2+
#include "tag.h"
33

44
const char *tag_type = "tag";
55

tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
#include "cache.h"
12
#include "tree.h"
23
#include "blob.h"
34
#include "commit.h"
45
#include "tag.h"
5-
#include "cache.h"
66
#include <stdlib.h>
77

88
const char *tree_type = "tree";

0 commit comments

Comments
 (0)