Anonymous avatar Anonymous committed 8f1d2e6

[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>;

Comments (0)

Files changed (10)

-#include "blob.h"
 #include "cache.h"
+#include "blob.h"
 #include <stdlib.h>
 
 const char *blob_type = "blob";
 	unsigned int ce_size;
 	unsigned char sha1[20];
 	unsigned short ce_flags;
-	char name[0];
+	char name[FLEX_ARRAY]; /* more */
 };
 
 #define CE_NAMEMASK  (0x0fff)
 extern struct alternate_object_database {
 	struct alternate_object_database *next;
 	char *name;
-	char base[0]; /* more */
+	char base[FLEX_ARRAY]; /* more */
 } *alt_odb_list;
 extern void prepare_alt_odb(void);
 
 	unsigned int pack_use_cnt;
 	int pack_local;
 	unsigned char sha1[20];
-	char pack_name[0]; /* something like ".git/objects/pack/xxxxx.pack" */
+	/* something like ".git/objects/pack/xxxxx.pack" */
+	char pack_name[FLEX_ARRAY]; /* more */
 } *packed_git;
 
 struct pack_entry {
 	unsigned char new_sha1[20];
 	unsigned char force;
 	struct ref *peer_ref; /* when renaming */
-	char name[0];
+	char name[FLEX_ARRAY]; /* more */
 };
 
 extern int git_connect(int fd[2], char *url, const char *prog);
+#include "cache.h"
 #include "tag.h"
 #include "commit.h"
-#include "cache.h"
 
 int save_commit_buffer = 1;
 

git-compat-util.h

 #ifndef GIT_COMPAT_UTIL_H
 #define GIT_COMPAT_UTIL_H
 
+#ifndef FLEX_ARRAY
+#if defined(__GNUC__) && (__GNUC__ < 3)
+#define FLEX_ARRAY 0
+#else
+#define FLEX_ARRAY /* empty */
+#endif
+#endif
+
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
 
 struct nond_on_fs {
 	int len;
-	char name[0];
+	char name[FLEX_ARRAY]; /* more */
 };
 
 static struct nond_on_fs **dir;
+#include "cache.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
-#include "cache.h"
 #include "tag.h"
 
 struct object **objs;
 
 struct object_refs {
 	unsigned count;
-	struct object *ref[0];
+	struct object *ref[FLEX_ARRAY]; /* more */
 };
 
 struct object {
 	unsigned char updated;
 	unsigned char old_sha1[20];
 	unsigned char new_sha1[20];
-	char ref_name[0];
+	char ref_name[FLEX_ARRAY]; /* more */
 };
 
 static struct command *commands = NULL;
-#include "tag.h"
 #include "cache.h"
+#include "tag.h"
 
 const char *tag_type = "tag";
 
+#include "cache.h"
 #include "tree.h"
 #include "blob.h"
 #include "commit.h"
 #include "tag.h"
-#include "cache.h"
 #include <stdlib.h>
 
 const char *tree_type = "tree";
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.