{"thread":{"id":"4553","subject":"[PATCH] Fix git to be (more) ANSI C99 compliant.","startedAt":"2006-06-18T05:50:31Z","lastAt":"2006-06-21T11:15:26Z","messageCount":15,"participants":["Florian Forster","Timo Hirvonen","Thomas Glanzmann","Rene Scharfe","Junio C Hamano","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"21990","messageId":"1150609831500-git-send-email-octo@verplant.org","threadId":"4553","inReplyTo":null,"subject":"[PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Florian Forster","fromEmail":"octo@verplant.org","sentAt":"2006-06-18T05:50:31Z","receivedAt":"2006-06-18T05:50:31Z","isPatch":true,"sender":{"key":"octo@verplant.org","avatar":null},"body":"Using this patch I was able to build git with\n$ make CFLAGS=\"-Wall -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE\"\n\nWhile most of this patch fixes void-pointer arithmetic and is therefore\ntrivial, I had to change the use of a struct with FAMs in `diff-lib.c'. Since\nthis is the first time I encountered FAMs it'd probably be a good idea if\nsomeone who knows would take a look at that.\n\nSigned-off-by: Florian Forster <octo@verplant.org>\n\n\n---\n\n blame.c             |    4 ++--\n builtin-apply.c     |    6 +++---\n builtin-read-tree.c |    3 +--\n builtin-tar-tree.c  |    6 +++---\n convert-objects.c   |   22 +++++++++++-----------\n csum-file.c         |    4 ++--\n diff-delta.c        |    5 +++--\n diff-lib.c          |   41 ++++++++++++++++++++++-------------------\n diff.c              |    2 +-\n diffcore-order.c    |    2 +-\n http-fetch.c        |   15 ++++++++-------\n http-push.c         |   15 ++++++++-------\n http.c              |    4 ++--\n imap-send.c         |    2 +-\n pack-check.c        |    6 +++---\n pack-objects.c      |    4 ++--\n pack-redundant.c    |   16 ++++++++--------\n patch-delta.c       |    4 ++--\n pkt-line.c          |    4 ++--\n quote.c             |    9 ++++++++-\n read-cache.c        |   13 +++++++------\n sha1_file.c         |   27 ++++++++++++++-------------\n ssh-fetch.c         |    2 +-\n tag.c               |    4 ++--\n tree-walk.c         |   11 ++++++-----\n 25 files changed, 123 insertions(+), 108 deletions(-)\n\n714b7eca861ad3b6863209f0298d55c0c2292116\ndiff --git a/blame.c b/blame.c\nindex 25d3bcf..51eab2e 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -301,9 +301,9 @@ static void fill_line_map(struct commit \n \t\t\t\tif (DEBUG)\n \t\t\t\t\tprintf(\"map: i1: %d %d %p i2: %d %d %p\\n\",\n \t\t\t\t\t       i1, map[i1],\n-\t\t\t\t\t       i1 != -1 ? blame_lines[map[i1]] : NULL,\n+\t\t\t\t\t       (void *) (i1 != -1 ? blame_lines[map[i1]] : NULL),\n \t\t\t\t\t       i2, map2[i2],\n-\t\t\t\t\t       i2 != -1 ? blame_lines[map2[i2]] : NULL);\n+\t\t\t\t\t       (void *) (i2 != -1 ? blame_lines[map2[i2]] : NULL));\n \t\t\t\tif (map2[i2] != -1 &&\n \t\t\t\t    blame_lines[map[i1]] &&\n \t\t\t\t    !blame_lines[map2[i2]])\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex e113c74..6dd0472 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -148,7 +148,7 @@ static void *read_patch_file(int fd, uns\n \t\t\tbuffer = xrealloc(buffer, alloc);\n \t\t\tnr = alloc - size;\n \t\t}\n-\t\tnr = xread(fd, buffer + size, nr);\n+\t\tnr = xread(fd, (char *) buffer + size, nr);\n \t\tif (!nr)\n \t\t\tbreak;\n \t\tif (nr < 0)\n@@ -164,7 +164,7 @@ static void *read_patch_file(int fd, uns\n \t */\n \tif (alloc < size + SLOP)\n \t\tbuffer = xrealloc(buffer, size + SLOP);\n-\tmemset(buffer + size, 0, SLOP);\n+\tmemset((char *) buffer + size, 0, SLOP);\n \treturn buffer;\n }\n \n@@ -1194,7 +1194,7 @@ static int read_old_data(struct stat *st\n \t\t\treturn error(\"unable to open %s\", path);\n \t\tgot = 0;\n \t\tfor (;;) {\n-\t\t\tint ret = xread(fd, buf + got, size - got);\n+\t\t\tint ret = xread(fd, (char *) buf + got, size - got);\n \t\t\tif (ret <= 0)\n \t\t\t\tbreak;\n \t\t\tgot += ret;\ndiff --git a/builtin-read-tree.c b/builtin-read-tree.c\nindex bb50fbd..fdd6706 100644\n--- a/builtin-read-tree.c\n+++ b/builtin-read-tree.c\n@@ -30,8 +30,7 @@ static int merge_size = 0;\n \n static struct object_list *trees = NULL;\n \n-static struct cache_entry df_conflict_entry = {\n-};\n+static struct cache_entry df_conflict_entry;\n \n struct tree_entry_list {\n \tstruct tree_entry_list *next;\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex f6310b9..646322d 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -34,7 +34,7 @@ static void reliable_write(void *buf, un\n \t\t\tdie(\"git-tar-tree: disk full?\");\n \t\t}\n \t\tsize -= ret;\n-\t\tbuf += ret;\n+\t\tbuf   = (char *) buf + ret;\n \t}\n }\n \n@@ -87,13 +87,13 @@ static void write_blocked(void *buf, uns\n \t\tmemcpy(block + offset, buf, chunk);\n \t\tsize -= chunk;\n \t\toffset += chunk;\n-\t\tbuf += chunk;\n+\t\tbuf     = (char *) buf + chunk;\n \t\twrite_if_needed();\n \t}\n \twhile (size >= BLOCKSIZE) {\n \t\treliable_write(buf, BLOCKSIZE);\n \t\tsize -= BLOCKSIZE;\n-\t\tbuf += BLOCKSIZE;\n+\t\tbuf   = (char *) buf + BLOCKSIZE;\n \t}\n \tif (size) {\n \t\tmemcpy(block + offset, buf, size);\ndiff --git a/convert-objects.c b/convert-objects.c\nindex a67d6b4..0fabd89 100644\n--- a/convert-objects.c\n+++ b/convert-objects.c\n@@ -103,12 +103,12 @@ static int write_subdirectory(void *buff\n \t\tif (!slash) {\n \t\t\tnewlen += sprintf(new + newlen, \"%o %s\", mode, path);\n \t\t\tnew[newlen++] = '\\0';\n-\t\t\tmemcpy(new + newlen, buffer + len - 20, 20);\n+\t\t\tmemcpy(new + newlen, (char *) buffer + len - 20, 20);\n \t\t\tnewlen += 20;\n \n \t\t\tused += len;\n \t\t\tsize -= len;\n-\t\t\tbuffer += len;\n+\t\t\tbuffer = (char *) buffer + len;\n \t\t\tcontinue;\n \t\t}\n \n@@ -121,7 +121,7 @@ static int write_subdirectory(void *buff\n \n \t\tused += len;\n \t\tsize -= len;\n-\t\tbuffer += len;\n+\t\tbuffer = (char *) buffer + len;\n \t}\n \n \twrite_sha1_file(new, newlen, tree_type, result_sha1);\n@@ -137,13 +137,13 @@ static void convert_tree(void *buffer, u\n \twhile (size) {\n \t\tint len = 1+strlen(buffer);\n \n-\t\tconvert_binary_sha1(buffer + len);\n+\t\tconvert_binary_sha1((char *) buffer + len);\n \n \t\tlen += 20;\n \t\tif (len > size)\n \t\t\tdie(\"corrupt tree object\");\n \t\tsize -= len;\n-\t\tbuffer += len;\n+\t\tbuffer = (char *) buffer + len;\n \t}\n \n \twrite_subdirectory(orig_buffer, orig_size, \"\", 0, result_sha1);\n@@ -244,14 +244,14 @@ static void convert_date(void *buffer, u\n \t// \"tree <sha1>\\n\"\n \tmemcpy(new + newlen, buffer, 46);\n \tnewlen += 46;\n-\tbuffer += 46;\n+\tbuffer = (char *) buffer + 46;\n \tsize -= 46;\n \n \t// \"parent <sha1>\\n\"\n \twhile (!memcmp(buffer, \"parent \", 7)) {\n \t\tmemcpy(new + newlen, buffer, 48);\n \t\tnewlen += 48;\n-\t\tbuffer += 48;\n+\t\tbuffer = (char *) buffer + 48;\n \t\tsize -= 48;\n \t}\n \n@@ -275,11 +275,11 @@ static void convert_commit(void *buffer,\n \n \tif (memcmp(buffer, \"tree \", 5))\n \t\tdie(\"Bad commit '%s'\", (char*) buffer);\n-\tconvert_ascii_sha1(buffer+5);\n-\tbuffer += 46;    /* \"tree \" + \"hex sha1\" + \"\\n\" */\n+\tconvert_ascii_sha1((char *) buffer + 5);\n+\tbuffer = (char *) buffer + 46;    /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \twhile (!memcmp(buffer, \"parent \", 7)) {\n-\t\tconvert_ascii_sha1(buffer+7);\n-\t\tbuffer += 48;\n+\t\tconvert_ascii_sha1((char *) buffer + 7);\n+\t\tbuffer = (char *) buffer + 48;\n \t}\n \tconvert_date(orig_buffer, orig_size, result_sha1);\n }\ndiff --git a/csum-file.c b/csum-file.c\nindex 5f9249a..ebaad03 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -17,7 +17,7 @@ static int sha1flush(struct sha1file *f,\n \tfor (;;) {\n \t\tint ret = xwrite(f->fd, buf, count);\n \t\tif (ret > 0) {\n-\t\t\tbuf += ret;\n+\t\t\tbuf = (char *) buf + ret;\n \t\t\tcount -= ret;\n \t\t\tif (count)\n \t\t\t\tcontinue;\n@@ -57,7 +57,7 @@ int sha1write(struct sha1file *f, void *\n \t\tmemcpy(f->buffer + offset, buf, nr);\n \t\tcount -= nr;\n \t\toffset += nr;\n-\t\tbuf += nr;\n+\t\tbuf = (char *) buf + nr;\n \t\tleft -= nr;\n \t\tif (!left) {\n \t\t\tSHA1_Update(&f->ctx, f->buffer, offset);\ndiff --git a/diff-delta.c b/diff-delta.c\nindex 25a798d..8b9172a 100644\n--- a/diff-delta.c\n+++ b/diff-delta.c\n@@ -22,6 +22,7 @@ #include <stdlib.h>\n #include <string.h>\n #include \"delta.h\"\n \n+#include \"git-compat-util.h\"\n \n /* maximum hash entry list for the same hash bucket */\n #define HASH_LIMIT 64\n@@ -131,7 +132,7 @@ struct delta_index {\n \tconst void *src_buf;\n \tunsigned long src_size;\n \tunsigned int hash_mask;\n-\tstruct index_entry *hash[0];\n+\tstruct index_entry *hash[FLEX_ARRAY];\n };\n \n struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)\n@@ -283,7 +284,7 @@ create_delta(const struct delta_index *i\n \tref_data = index->src_buf;\n \tref_top = ref_data + index->src_size;\n \tdata = trg_buf;\n-\ttop = trg_buf + trg_size;\n+\ttop = (const unsigned char *) trg_buf + trg_size;\n \n \toutpos++;\n \tval = 0;\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 2183b41..fdc1173 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -34,21 +34,23 @@ int run_diff_files(struct rev_info *revs\n \t\t\tcontinue;\n \n \t\tif (ce_stage(ce)) {\n-\t\t\tstruct {\n-\t\t\t\tstruct combine_diff_path p;\n-\t\t\t\tstruct combine_diff_parent filler[5];\n-\t\t\t} combine;\n+\t\t\tstruct combine_diff_path *dpath;\n \t\t\tint num_compare_stages = 0;\n+\t\t\tsize_t path_len;\n \n-\t\t\tcombine.p.next = NULL;\n-\t\t\tcombine.p.len = ce_namelen(ce);\n-\t\t\tcombine.p.path = xmalloc(combine.p.len + 1);\n-\t\t\tmemcpy(combine.p.path, ce->name, combine.p.len);\n-\t\t\tcombine.p.path[combine.p.len] = 0;\n-\t\t\tcombine.p.mode = 0;\n-\t\t\tmemset(combine.p.sha1, 0, 20);\n-\t\t\tmemset(&combine.p.parent[0], 0,\n-\t\t\t       sizeof(combine.filler));\n+\t\t\tpath_len = ce_namelen(ce);\n+\n+\t\t\tdpath = xmalloc (combine_diff_path_size (5, path_len));\n+\t\t\tdpath->path = (char *) &(dpath->parent[5]);\n+\n+\t\t\tdpath->next = NULL;\n+\t\t\tdpath->len = path_len;\n+\t\t\tmemcpy(dpath->path, ce->name, path_len);\n+\t\t\tdpath->path[path_len] = '\\0';\n+\t\t\tdpath->mode = 0;\n+\t\t\tmemset(dpath->sha1, 0, 20);\n+\t\t\tmemset(&(dpath->parent[0]), 0,\n+\t\t\t\t\tsizeof(struct combine_diff_parent)*5);\n \n \t\t\twhile (i < entries) {\n \t\t\t\tstruct cache_entry *nce = active_cache[i];\n@@ -64,11 +66,11 @@ int run_diff_files(struct rev_info *revs\n \t\t\t\tif (2 <= stage) {\n \t\t\t\t\tint mode = ntohl(nce->ce_mode);\n \t\t\t\t\tnum_compare_stages++;\n-\t\t\t\t\tmemcpy(combine.p.parent[stage-2].sha1,\n+\t\t\t\t\tmemcpy(dpath->parent[stage-2].sha1,\n \t\t\t\t\t       nce->sha1, 20);\n-\t\t\t\t\tcombine.p.parent[stage-2].mode =\n+\t\t\t\t\tdpath->parent[stage-2].mode =\n \t\t\t\t\t\tcanon_mode(mode);\n-\t\t\t\t\tcombine.p.parent[stage-2].status =\n+\t\t\t\t\tdpath->parent[stage-2].status =\n \t\t\t\t\t\tDIFF_STATUS_MODIFIED;\n \t\t\t\t}\n \n@@ -83,13 +85,14 @@ int run_diff_files(struct rev_info *revs\n \t\t\ti--;\n \n \t\t\tif (revs->combine_merges && num_compare_stages == 2) {\n-\t\t\t\tshow_combined_diff(&combine.p, 2,\n+\t\t\t\tshow_combined_diff(dpath, 2,\n \t\t\t\t\t\t   revs->dense_combined_merges,\n \t\t\t\t\t\t   revs);\n-\t\t\t\tfree(combine.p.path);\n+\t\t\t\tfree(dpath);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tfree(combine.p.path);\n+\t\t\tfree(dpath);\n+\t\t\tdpath = NULL;\n \n \t\t\t/*\n \t\t\t * Show the diff for the 'ce' if we found the one\ndiff --git a/diff.c b/diff.c\nindex 9e9cfc8..fb1411c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -515,7 +515,7 @@ static void emit_binary_diff(mmfile_t *o\n \t\telse\n \t\t\tline[0] = bytes - 26 + 'a' - 1;\n \t\tencode_85(line + 1, cp, bytes);\n-\t\tcp += bytes;\n+\t\tcp = (char *) cp + bytes;\n \t\tputs(line);\n \t}\n \tprintf(\"\\n\");\ndiff --git a/diffcore-order.c b/diffcore-order.c\nindex 0bc2b22..aef6da6 100644\n--- a/diffcore-order.c\n+++ b/diffcore-order.c\n@@ -30,7 +30,7 @@ static void prepare_order(const char *or\n \tclose(fd);\n \tif (map == MAP_FAILED)\n \t\treturn;\n-\tendp = map + st.st_size;\n+\tendp = (char *) map + st.st_size;\n \tfor (pass = 0; pass < 2; pass++) {\n \t\tcnt = 0;\n \t\tcp = map;\ndiff --git a/http-fetch.c b/http-fetch.c\nindex da1a7f5..2b63d89 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -123,7 +123,7 @@ static size_t fwrite_sha1_file(void *ptr\n \tstruct object_request *obj_req = (struct object_request *)data;\n \tdo {\n \t\tssize_t retval = write(obj_req->local,\n-\t\t\t\t       ptr + posn, size - posn);\n+\t\t\t\t       (char *) ptr + posn, size - posn);\n \t\tif (retval < 0)\n \t\t\treturn posn;\n \t\tposn += retval;\n@@ -1136,13 +1136,14 @@ int fetch(unsigned char *sha1)\n \n static inline int needs_quote(int ch)\n {\n-\tswitch (ch) {\n-\tcase '/': case '-': case '.':\n-\tcase 'A'...'Z':\tcase 'a'...'z':\tcase '0'...'9':\n+\tif (((ch >= 'A') && (ch <= 'Z'))\n+\t\t\t|| ((ch >= 'a') && (ch <= 'z'))\n+\t\t\t|| ((ch >= '0') && (ch <= '9'))\n+\t\t\t|| (ch == '/')\n+\t\t\t|| (ch == '-')\n+\t\t\t|| (ch == '.'))\n \t\treturn 0;\n-\tdefault:\n-\t\treturn 1;\n-\t}\n+\treturn 1;\n }\n \n static inline int hex(int v)\ndiff --git a/http-push.c b/http-push.c\nindex 2d9441e..0684e46 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -196,7 +196,7 @@ static size_t fwrite_sha1_file(void *ptr\n \tstruct transfer_request *request = (struct transfer_request *)data;\n \tdo {\n \t\tssize_t retval = write(request->local_fileno,\n-\t\t\t\t       ptr + posn, size - posn);\n+\t\t\t\t       (char *) ptr + posn, size - posn);\n \t\tif (retval < 0)\n \t\t\treturn posn;\n \t\tposn += retval;\n@@ -1077,13 +1077,14 @@ static int fetch_indices(void)\n \n static inline int needs_quote(int ch)\n {\n-\tswitch (ch) {\n-\tcase '/': case '-': case '.':\n-\tcase 'A'...'Z':\tcase 'a'...'z':\tcase '0'...'9':\n+\tif (((ch >= 'A') && (ch <= 'Z'))\n+\t\t\t|| ((ch >= 'a') && (ch <= 'z'))\n+\t\t\t|| ((ch >= '0') && (ch <= '9'))\n+\t\t\t|| (ch == '/')\n+\t\t\t|| (ch == '-')\n+\t\t\t|| (ch == '.'))\n \t\treturn 0;\n-\tdefault:\n-\t\treturn 1;\n-\t}\n+\treturn 1;\n }\n \n static inline int hex(int v)\ndiff --git a/http.c b/http.c\nindex 08769cc..6c1937b 100644\n--- a/http.c\n+++ b/http.c\n@@ -34,7 +34,7 @@ size_t fread_buffer(void *ptr, size_t el\n \tsize_t size = eltsize * nmemb;\n \tif (size > buffer->size - buffer->posn)\n \t\tsize = buffer->size - buffer->posn;\n-\tmemcpy(ptr, buffer->buffer + buffer->posn, size);\n+\tmemcpy(ptr, (char *) buffer->buffer + buffer->posn, size);\n \tbuffer->posn += size;\n \treturn size;\n }\n@@ -49,7 +49,7 @@ size_t fwrite_buffer(const void *ptr, si\n \t\t\tbuffer->size = buffer->posn + size;\n \t\tbuffer->buffer = xrealloc(buffer->buffer, buffer->size);\n \t}\n-\tmemcpy(buffer->buffer + buffer->posn, ptr, size);\n+\tmemcpy((char *) buffer->buffer + buffer->posn, ptr, size);\n \tbuffer->posn += size;\n \tdata_received++;\n \treturn size;\ndiff --git a/imap-send.c b/imap-send.c\nindex 285ad29..87db8e2 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -93,7 +93,7 @@ typedef struct {\n \tchar *data;\n \tint len;\n \tunsigned char flags;\n-\tunsigned char crlf:1;\n+\tunsigned int  crlf:1;\n } msg_data_t;\n \n #define DRV_OK          0\ndiff --git a/pack-check.c b/pack-check.c\nindex e575879..3a62e1b 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -29,10 +29,10 @@ static int verify_packfile(struct packed\n \tpack_base = p->pack_base;\n \tSHA1_Update(&ctx, pack_base, pack_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, pack_base + pack_size - 20, 20))\n+\tif (memcmp(sha1, (char *) pack_base + pack_size - 20, 20))\n \t\treturn error(\"Packfile %s SHA1 mismatch with itself\",\n \t\t\t     p->pack_name);\n-\tif (memcmp(sha1, index_base + index_size - 40, 20))\n+\tif (memcmp(sha1, (char *) index_base + index_size - 40, 20))\n \t\treturn error(\"Packfile %s SHA1 mismatch with idx\",\n \t\t\t     p->pack_name);\n \n@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, in\n \tSHA1_Init(&ctx);\n \tSHA1_Update(&ctx, index_base, index_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, index_base + index_size - 20, 20))\n+\tif (memcmp(sha1, (char *) index_base + index_size - 20, 20))\n \t\tret = error(\"Packfile index for %s SHA1 mismatch\",\n \t\t\t    p->pack_name);\n \ndiff --git a/pack-objects.c b/pack-objects.c\nindex 179560f..ba6525d 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -156,7 +156,7 @@ static void prepare_pack_revindex(struct\n \n \trix->revindex = xmalloc(sizeof(unsigned long) * (num_ent + 1));\n \tfor (i = 0; i < num_ent; i++) {\n-\t\tunsigned int hl = *((unsigned int *)(index + 24 * i));\n+\t\tunsigned int hl = *((unsigned int *)((char *) index + 24*i));\n \t\trix->revindex[i] = ntohl(hl);\n \t}\n \t/* This knows the pack format -- the 20-byte trailer\n@@ -300,7 +300,7 @@ static unsigned long write_object(struct\n \t\tuse_packed_git(p);\n \n \t\tdatalen = find_packed_object_size(p, entry->in_pack_offset);\n-\t\tbuf = p->pack_base + entry->in_pack_offset;\n+\t\tbuf = (char *) p->pack_base + entry->in_pack_offset;\n \t\tsha1write(f, buf, datalen);\n \t\tunuse_packed_git(p);\n \t\thdrlen = 0; /* not really */\ndiff --git a/pack-redundant.c b/pack-redundant.c\nindex cd81f5a..4864a2b 100644\n--- a/pack-redundant.c\n+++ b/pack-redundant.c\n@@ -246,12 +246,12 @@ static struct pack_list * pack_list_diff\n static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)\n {\n \tint p1_off, p2_off;\n-\tvoid *p1_base, *p2_base;\n+\tunsigned char *p1_base, *p2_base;\n \tstruct llist_item *p1_hint = NULL, *p2_hint = NULL;\n \t\n \tp1_off = p2_off = 256 * 4 + 4;\n-\tp1_base = (void *)p1->pack->index_base;\n-\tp2_base = (void *)p2->pack->index_base;\n+\tp1_base = (unsigned char *) p1->pack->index_base;\n+\tp2_base = (unsigned char *) p2->pack->index_base;\n \n \twhile (p1_off <= p1->pack->index_size - 3 * 20 &&\n \t       p2_off <= p2->pack->index_size - 3 * 20)\n@@ -351,11 +351,11 @@ static size_t sizeof_union(struct packed\n {\n \tsize_t ret = 0;\n \tint p1_off, p2_off;\n-\tvoid *p1_base, *p2_base;\n+\tchar *p1_base, *p2_base;\n \n \tp1_off = p2_off = 256 * 4 + 4;\n-\tp1_base = (void *)p1->index_base;\n-\tp2_base = (void *)p2->index_base;\n+\tp1_base = (char *)p1->index_base;\n+\tp2_base = (char *)p2->index_base;\n \n \twhile (p1_off <= p1->index_size - 3 * 20 &&\n \t       p2_off <= p2->index_size - 3 * 20)\n@@ -534,7 +534,7 @@ static struct pack_list * add_pack(struc\n {\n \tstruct pack_list l;\n \tsize_t off;\n-\tvoid *base;\n+\tunsigned char *base;\n \n \tif (!p->pack_local && !(alt_odb || verbose))\n \t\treturn NULL;\n@@ -543,7 +543,7 @@ static struct pack_list * add_pack(struc\n \tllist_init(&l.all_objects);\n \n \toff = 256 * 4 + 4;\n-\tbase = (void *)p->index_base;\n+\tbase = (unsigned char *)p->index_base;\n \twhile (off <= p->index_size - 3 * 20) {\n \t\tllist_insert_back(l.all_objects, base + off);\n \t\toff += 24;\ndiff --git a/patch-delta.c b/patch-delta.c\nindex 8f318ed..e3a1d42 100644\n--- a/patch-delta.c\n+++ b/patch-delta.c\n@@ -25,7 +25,7 @@ void *patch_delta(const void *src_buf, u\n \t\treturn NULL;\n \n \tdata = delta_buf;\n-\ttop = delta_buf + delta_size;\n+\ttop = (const unsigned char *) delta_buf + delta_size;\n \n \t/* make sure the orig file size matches what we expect */\n \tsize = get_delta_hdr_size(&data, top);\n@@ -56,7 +56,7 @@ void *patch_delta(const void *src_buf, u\n \t\t\t    cp_off + cp_size > src_size ||\n \t\t\t    cp_size > size)\n \t\t\t\tgoto bad;\n-\t\t\tmemcpy(out, src_buf + cp_off, cp_size);\n+\t\t\tmemcpy(out, (char *) src_buf + cp_off, cp_size);\n \t\t\tout += cp_size;\n \t\t\tsize -= cp_size;\n \t\t} else if (cmd) {\ndiff --git a/pkt-line.c b/pkt-line.c\nindex bb3bab0..44d4296 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -21,7 +21,7 @@ static void safe_write(int fd, const voi\n \twhile (n) {\n \t\tint ret = xwrite(fd, buf, n);\n \t\tif (ret > 0) {\n-\t\t\tbuf += ret;\n+\t\t\tbuf = (char *) buf + ret;\n \t\t\tn -= ret;\n \t\t\tcontinue;\n \t\t}\n@@ -66,7 +66,7 @@ static void safe_read(int fd, void *buff\n \tint n = 0;\n \n \twhile (n < size) {\n-\t\tint ret = xread(fd, buffer + n, size - n);\n+\t\tint ret = xread(fd, (char *) buffer + n, size - n);\n \t\tif (ret < 0)\n \t\t\tdie(\"read error (%s)\", strerror(errno));\n \t\tif (!ret)\ndiff --git a/quote.c b/quote.c\nindex 06792d4..dcc2326 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -206,7 +206,14 @@ #define EMIT(c) (outp ? (*outp++ = (c)) \n \t\t\t\tcase '\\\\': case '\"':\n \t\t\t\t\tbreak; /* verbatim */\n \n-\t\t\t\tcase '0'...'7':\n+\t\t\t\tcase '0':\n+\t\t\t\tcase '1':\n+\t\t\t\tcase '2':\n+\t\t\t\tcase '3':\n+\t\t\t\tcase '4':\n+\t\t\t\tcase '5':\n+\t\t\t\tcase '6':\n+\t\t\t\tcase '7':\n \t\t\t\t\t/* octal */\n \t\t\t\t\tac = ((ch - '0') << 6);\n \t\t\t\t\tif ((ch = *sp++) < '0' || '7' < ch)\ndiff --git a/read-cache.c b/read-cache.c\nindex c499c51..3c32aae 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -706,7 +706,7 @@ static int verify_hdr(struct cache_heade\n \tSHA1_Init(&c);\n \tSHA1_Update(&c, hdr, size - 20);\n \tSHA1_Final(sha1, &c);\n-\tif (memcmp(sha1, (void *)hdr + size - 20, 20))\n+\tif (memcmp(sha1, (char *) hdr + size - 20, 20))\n \t\treturn error(\"bad index file sha1 signature\");\n \treturn 0;\n }\n@@ -770,7 +770,7 @@ int read_cache(void)\n \n \toffset = sizeof(*hdr);\n \tfor (i = 0; i < active_nr; i++) {\n-\t\tstruct cache_entry *ce = map + offset;\n+\t\tstruct cache_entry *ce = (struct cache_entry *) ((char *) map + offset);\n \t\toffset = offset + ce_size(ce);\n \t\tactive_cache[i] = ce;\n \t}\n@@ -783,10 +783,11 @@ int read_cache(void)\n \t\t * in 4-byte network byte order.\n \t\t */\n \t\tunsigned long extsize;\n-\t\tmemcpy(&extsize, map + offset + 4, 4);\n+\t\tmemcpy(&extsize, (char *) map + offset + 4, 4);\n \t\textsize = ntohl(extsize);\n-\t\tif (read_index_extension(map + offset,\n-\t\t\t\t\t map + offset + 8, extsize) < 0)\n+\t\tif (read_index_extension(((const char *) map) + offset,\n+\t\t\t\t\t (char *) map + offset + 8,\n+\t\t\t\t\t extsize) < 0)\n \t\t\tgoto unmap;\n \t\toffset += 8;\n \t\toffset += extsize;\n@@ -820,7 +821,7 @@ static int ce_write(SHA_CTX *context, in\n \t\t}\n \t\twrite_buffer_len = buffered;\n \t\tlen -= partial;\n-\t\tdata += partial;\n+\t\tdata = (char *) data + partial;\n  \t}\n  \treturn 0;\n }\ndiff --git a/sha1_file.c b/sha1_file.c\nindex b4ff233..3c001d7 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -486,7 +486,8 @@ int use_packed_git(struct packed_git *p)\n \t\t * this is cheap.\n \t\t */\n \t\tif (memcmp((char*)(p->index_base) + p->index_size - 40,\n-\t\t\t   p->pack_base + p->pack_size - 20, 20)) {\n+\t\t\t   (char *) p->pack_base + p->pack_size - 20,\n+\t\t\t   20)) {\n \t\t\t      \n \t\t\tdie(\"packfile %s does not match index.\", p->pack_name);\n \t\t}\n@@ -701,7 +702,7 @@ static void *unpack_sha1_rest(z_stream *\n \tint bytes = strlen(buffer) + 1;\n \tunsigned char *buf = xmalloc(1+size);\n \n-\tmemcpy(buf, buffer + bytes, stream->total_out - bytes);\n+\tmemcpy(buf, (char *) buffer + bytes, stream->total_out - bytes);\n \tbytes = stream->total_out - bytes;\n \tif (bytes < size) {\n \t\tstream->next_out = buf + bytes;\n@@ -853,7 +854,7 @@ static unsigned long unpack_object_heade\n \tif (offset >= p->pack_size)\n \t\tdie(\"object offset outside of pack file\");\n \n-\tpack =  p->pack_base + offset;\n+\tpack =  (unsigned char *) p->pack_base + offset;\n \tc = *pack++;\n \toffset++;\n \t*type = (c >> 4) & 7;\n@@ -883,7 +884,7 @@ int check_reuse_pack_delta(struct packed\n \tptr = unpack_object_header(p, ptr, kindp, sizep);\n \tif (*kindp != OBJ_DELTA)\n \t\tgoto done;\n-\tmemcpy(base, p->pack_base + ptr, 20);\n+\tmemcpy(base, (char *) p->pack_base + ptr, 20);\n \tstatus = 0;\n  done:\n \tunuse_packed_git(p);\n@@ -903,7 +904,7 @@ void packed_object_info_detail(struct pa\n \tenum object_type kind;\n \n \toffset = unpack_object_header(p, e->offset, &kind, size);\n-\tpack = p->pack_base + offset;\n+\tpack = (unsigned char *) p->pack_base + offset;\n \tif (kind != OBJ_DELTA)\n \t\t*delta_chain_length = 0;\n \telse {\n@@ -919,7 +920,7 @@ void packed_object_info_detail(struct pa\n \t\t\tfind_pack_entry_one(pack, &base_ent, p);\n \t\t\toffset = unpack_object_header(p, base_ent.offset,\n \t\t\t\t\t\t      &kind, &junk);\n-\t\t\tpack = p->pack_base + offset;\n+\t\t\tpack = (unsigned char *) p->pack_base + offset;\n \t\t\tchain_length++;\n \t\t} while (kind == OBJ_DELTA);\n \t\t*delta_chain_length = chain_length;\n@@ -957,7 +958,7 @@ static int packed_object_info(struct pac\n \t\tdie(\"cannot map packed file\");\n \n \toffset = unpack_object_header(p, entry->offset, &kind, &size);\n-\tpack = p->pack_base + offset;\n+\tpack = (unsigned char *) p->pack_base + offset;\n \tleft = p->pack_size - offset;\n \n \tswitch (kind) {\n@@ -1096,7 +1097,7 @@ void *unpack_entry_gently(struct pack_en\n \tvoid *retval;\n \n \toffset = unpack_object_header(p, entry->offset, &kind, &size);\n-\tpack = p->pack_base + offset;\n+\tpack = (unsigned char *) p->pack_base + offset;\n \tleft = p->pack_size - offset;\n \tswitch (kind) {\n \tcase OBJ_DELTA:\n@@ -1134,7 +1135,7 @@ int nth_packed_object_sha1(const struct \n \tvoid *index = p->index_base + 256;\n \tif (n < 0 || num_packed_objects(p) <= n)\n \t\treturn -1;\n-\tmemcpy(sha1, (index + 24 * n + 4), 20);\n+\tmemcpy(sha1, (char *) index + (24 * n) + 4, 20);\n \treturn 0;\n }\n \n@@ -1148,9 +1149,9 @@ int find_pack_entry_one(const unsigned c\n \n \tdo {\n \t\tint mi = (lo + hi) / 2;\n-\t\tint cmp = memcmp(index + 24 * mi + 4, sha1, 20);\n+\t\tint cmp = memcmp((char *) index + (24 * mi) + 4, sha1, 20);\n \t\tif (!cmp) {\n-\t\t\te->offset = ntohl(*((unsigned int *)(index + 24 * mi)));\n+\t\t\te->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi))));\n \t\t\tmemcpy(e->sha1, sha1, 20);\n \t\t\te->p = p;\n \t\t\treturn 1;\n@@ -1290,7 +1291,7 @@ void *read_object_with_reference(const u\n \t\tref_length = strlen(ref_type);\n \n \t\tif (memcmp(buffer, ref_type, ref_length) ||\n-\t\t    get_sha1_hex(buffer + ref_length, actual_sha1)) {\n+\t\t    get_sha1_hex((char *) buffer + ref_length, actual_sha1)) {\n \t\t\tfree(buffer);\n \t\t\treturn NULL;\n \t\t}\n@@ -1408,7 +1409,7 @@ static int write_buffer(int fd, const vo\n \t\t\treturn error(\"file write error (%s)\", strerror(errno));\n \t\t}\n \t\tlen -= size;\n-\t\tbuf += size;\n+\t\tbuf = (char *) buf + size;\n \t}\n \treturn 0;\n }\ndiff --git a/ssh-fetch.c b/ssh-fetch.c\nindex e3067b8..1e59cd2 100644\n--- a/ssh-fetch.c\n+++ b/ssh-fetch.c\n@@ -24,7 +24,7 @@ static ssize_t force_write(int fd, void \n {\n \tssize_t ret = 0;\n \twhile (ret < length) {\n-\t\tssize_t size = write(fd, buffer + ret, length - ret);\n+\t\tssize_t size = write(fd, (char *) buffer + ret, length - ret);\n \t\tif (size < 0) {\n \t\t\treturn size;\n \t\t}\ndiff --git a/tag.c b/tag.c\nindex f390ee7..13c364d 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -47,10 +47,10 @@ int parse_tag_buffer(struct tag *item, v\n \n \tif (size < 64)\n \t\treturn -1;\n-\tif (memcmp(\"object \", data, 7) || get_sha1_hex(data + 7, object))\n+\tif (memcmp(\"object \", data, 7) || get_sha1_hex((char *) data + 7, object))\n \t\treturn -1;\n \n-\ttype_line = data + 48;\n+\ttype_line = (char *) data + 48;\n \tif (memcmp(\"\\ntype \", type_line-1, 6))\n \t\treturn -1;\n \ndiff --git a/tree-walk.c b/tree-walk.c\nindex 297c697..3f83e98 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -43,7 +43,7 @@ void update_tree_entry(struct tree_desc \n \n \tif (size < len)\n \t\tdie(\"corrupt tree file\");\n-\tdesc->buf = buf + len;\n+\tdesc->buf = (char *) buf + len;\n \tdesc->size = size - len;\n }\n \n@@ -66,7 +66,7 @@ const unsigned char *tree_entry_extract(\n \tconst void *tree = desc->buf;\n \tunsigned long size = desc->size;\n \tint len = strlen(tree)+1;\n-\tconst unsigned char *sha1 = tree + len;\n+\tconst unsigned char *sha1 = (unsigned char *) tree + len;\n \tconst char *path;\n \tunsigned int mode;\n \n@@ -80,7 +80,8 @@ const unsigned char *tree_entry_extract(\n \n int tree_entry(struct tree_desc *desc, struct name_entry *entry)\n {\n-\tconst void *tree = desc->buf, *path;\n+\tconst void *tree = desc->buf;\n+\tconst char *path;\n \tunsigned long len, size = desc->size;\n \n \tif (!size)\n@@ -95,10 +96,10 @@ int tree_entry(struct tree_desc *desc, s\n \tentry->pathlen = len;\n \n \tpath += len + 1;\n-\tentry->sha1 = path;\n+\tentry->sha1 = (const unsigned char *) path;\n \n \tpath += 20;\n-\tlen = path - tree;\n+\tlen = path - (char *) tree;\n \tif (len > size)\n \t\tdie(\"corrupt tree file\");\n \n-- \n1.3.3\n"},{"id":"21993","messageId":"20060618110749.e6fb9030.tihirvon@gmail.com","threadId":"4553","inReplyTo":"1150609831500-git-send-email-octo@verplant.org","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Timo Hirvonen","fromEmail":"tihirvon@gmail.com","sentAt":"2006-06-18T08:07:49Z","receivedAt":"2006-06-18T08:07:49Z","isPatch":true,"sender":{"key":"tihirvon@gmail.com","avatar":null},"body":"Florian Forster <octo@verplant.org> wrote:\n\n> Using this patch I was able to build git with\n> $ make CFLAGS=\"-Wall -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE\"\n> \n> While most of this patch fixes void-pointer arithmetic and is therefore\n> trivial, I had to change the use of a struct with FAMs in `diff-lib.c'. Since\n> this is the first time I encountered FAMs it'd probably be a good idea if\n> someone who knows would take a look at that.\n\nMany of the void-pointer arithmetic warnings could be fixed by changing\nthe variable types to char * instead of casting them in many places.\n\n> --- a/diff-lib.c\n> +++ b/diff-lib.c\n> @@ -34,21 +34,23 @@ int run_diff_files(struct rev_info *revs\n>  \t\t\tcontinue;\n>  \n>  \t\tif (ce_stage(ce)) {\n> -\t\t\tstruct {\n> -\t\t\t\tstruct combine_diff_path p;\n> -\t\t\t\tstruct combine_diff_parent filler[5];\n> -\t\t\t} combine;\n\nYes this is somewhat ugly but avoids a malloc.  You could use alloca but\nthe man-page says:\n\n    \"The alloca() function is machine and compiler dependent. On many systems\n     its implementation is buggy. Its use is discouraged.\"\n\nLeave the code as it is now unless it causes real problems.\n\n>  static inline int needs_quote(int ch)\n>  {\n> -\tswitch (ch) {\n> -\tcase '/': case '-': case '.':\n> -\tcase 'A'...'Z':\tcase 'a'...'z':\tcase '0'...'9':\n> +\tif (((ch >= 'A') && (ch <= 'Z'))\n> +\t\t\t|| ((ch >= 'a') && (ch <= 'z'))\n> +\t\t\t|| ((ch >= '0') && (ch <= '9'))\n> +\t\t\t|| (ch == '/')\n> +\t\t\t|| (ch == '-')\n> +\t\t\t|| (ch == '.'))\n\n'A'...'Z' is more readable.  Does some compiler fail to compile it?\n\n> +++ b/http-push.c\n\n>  static inline int needs_quote(int ch)\n\nHmm.. same function in http-fetch.c.  Lots of common code could be moved\nto http.h.\n\n-- \nhttp://onion.dynserv.net/~timo/\n"},{"id":"21994","messageId":"20060618081440.GD22641@cip.informatik.uni-erlangen.de","threadId":"4553","inReplyTo":"20060618110749.e6fb9030.tihirvon@gmail.com","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Thomas Glanzmann","fromEmail":"sithglan@stud.uni-erlangen.de","sentAt":"2006-06-18T08:14:40Z","receivedAt":"2006-06-18T08:14:40Z","isPatch":true,"sender":{"key":"sithglan@stud.uni-erlangen.de","avatar":null},"body":"Hello,\n\n> 'A'...'Z' is more readable.  Does some compiler fail to compile it?\n\nyes, it is GCC (GNU) specific IIRC. So for example the Sun Compiler will\nchoke on this one.\n\n        Thomas\n"},{"id":"21995","messageId":"20060618082103.GA1331@verplant.org","threadId":"4553","inReplyTo":"20060618110749.e6fb9030.tihirvon@gmail.com","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Florian Forster","fromEmail":"octo@verplant.org","sentAt":"2006-06-18T08:21:04Z","receivedAt":"2006-06-18T08:21:04Z","isPatch":true,"sender":{"key":"octo@verplant.org","avatar":null},"body":"Hi,\n\nOn Sun, Jun 18, 2006 at 11:07:49AM +0300, Timo Hirvonen wrote:\n> Many of the void-pointer arithmetic warnings could be fixed by\n> changing the variable types to char * instead of casting them in many\n> places.\n\ntrue. Casting to a void-pointer can be done implicitely (even according\nto the standard), so changing a function's argument from `void *' to\n`char *' might break code somewhere else.\n\n> > -\t\t\tstruct {\n> > -\t\t\t\tstruct combine_diff_path p;\n> > -\t\t\t\tstruct combine_diff_parent filler[5];\n> > -\t\t\t} combine;\n> \n> Yes this is somewhat ugly but avoids a malloc.\n\nNo, malloc is still needed to allocate `combine.p.path'. My change does\nallocate all memory in one pass, so the number of calls to malloc\ndoesn't differ.\n\n> Leave the code as it is now unless it causes real problems.\n\n`struct combine_diff_path' has a flexible array member (FAM) and is\ntherefore an incomplete type. This means you may not instanciate it.\n\nGCC ignores the FAM in this case and allocates `sizeof (struct\ncombine_diff_path)' bytes. However, this is not correct according to\nANSI and prevents building using other compilers (e.g. Sun cc).\n\nTo be honest, I don't get the point of FAMs anyways. Why don't we just\nuse a pointer to `struct combine_diff_parent' there in the first place?\n\n> 'A'...'Z' is more readable.  Does some compiler fail to compile it?\n\nIt's not in ANSI, therefore GCC with `-ansi' failes, so does the Sun cc.\n\n> >  static inline int needs_quote(int ch)\n> \n> Hmm.. same function in http-fetch.c.  Lots of common code could be\n> moved to http.h.\n\nRight, I wanted to keep the changes as minimal as possible, though.\n\nAs you can probably tell my goal is building a Solaris version of git\nusing the Sun cc. I'm not quite there yet and don't have time to look\ninto the remaining issue(s) today nor tomorrow, but I might have some\ntime at the end of the week.\n\nRegards,\n-octo\n-- \nFlorian octo Forster\nHacker in training\nGnuPG: 0x91523C3D\nhttp://verplant.org/\n"},{"id":"21996","messageId":"44950E32.10904@lsrfire.ath.cx","threadId":"4553","inReplyTo":"1150609831500-git-send-email-octo@verplant.org","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Rene Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2006-06-18T08:26:26Z","receivedAt":"2006-06-18T08:26:26Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Florian Forster schrieb:\n> Using this patch I was able to build git with\n> $ make CFLAGS=\"-Wall -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE\"\n> \n> While most of this patch fixes void-pointer arithmetic and is therefore\n> trivial, I had to change the use of a struct with FAMs in `diff-lib.c'. Since\n> this is the first time I encountered FAMs it'd probably be a good idea if\n> someone who knows would take a look at that.\n\nNice work!  However, could you split it up a bit?  I.e. please send one\npatch per error class/topic.  A comment on why the changes are needed\nwould be nice too, e.g. \"void pointer arithmetic is a GNU extension, get\nrid of it\".\n\nThanks,\nRené\n"},{"id":"21997","messageId":"7vac8a50ji.fsf@assigned-by-dhcp.cox.net","threadId":"4553","inReplyTo":"1150609831500-git-send-email-octo@verplant.org","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-18T08:29:53Z","receivedAt":"2006-06-18T08:29:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Florian Forster <octo@verplant.org> writes:\n\n> While most of this patch fixes void-pointer arithmetic and is therefore\n> trivial, I had to change the use of a struct with FAMs in `diff-lib.c'. Since\n> this is the first time I encountered FAMs it'd probably be a good idea if\n> someone who knows would take a look at that.\n\nThanks.  I am very tempted to apply it, but I started to wonder\nthat in some places it might make sense to convert void* to\nchar* instead of casting.  Undecided.\n\n> diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\n> index f6310b9..646322d 100644\n> --- a/builtin-tar-tree.c\n> +++ b/builtin-tar-tree.c\n> @@ -34,7 +34,7 @@ static void reliable_write(void *buf, un\n>  \t\t\tdie(\"git-tar-tree: disk full?\");\n>  \t\t}\n>  \t\tsize -= ret;\n> -\t\tbuf += ret;\n> +\t\tbuf   = (char *) buf + ret;\n\nPlease do not add the extra whitespace to align \"=\".\n\n> @@ -244,14 +244,14 @@ static void convert_date(void *buffer, u\n>  \t// \"tree <sha1>\\n\"\n>  \tmemcpy(new + newlen, buffer, 46);\n>  \tnewlen += 46;\n> -\tbuffer += 46;\n> +\tbuffer = (char *) buffer + 46;\n>  \tsize -= 46;\n>  \n>  \t// \"parent <sha1>\\n\"\n>  \twhile (!memcmp(buffer, \"parent \", 7)) {\n>  \t\tmemcpy(new + newlen, buffer, 48);\n>  \t\tnewlen += 48;\n> -\t\tbuffer += 48;\n> +\t\tbuffer = (char *) buffer + 48;\n>  \t\tsize -= 48;\n>  \t}\n>  \n> @@ -275,11 +275,11 @@ static void convert_commit(void *buffer,\n>  \n>  \tif (memcmp(buffer, \"tree \", 5))\n>  \t\tdie(\"Bad commit '%s'\", (char*) buffer);\n> -\tconvert_ascii_sha1(buffer+5);\n> -\tbuffer += 46;    /* \"tree \" + \"hex sha1\" + \"\\n\" */\n> +\tconvert_ascii_sha1((char *) buffer + 5);\n> +\tbuffer = (char *) buffer + 46;    /* \"tree \" + \"hex sha1\" + \"\\n\" */\n>  \twhile (!memcmp(buffer, \"parent \", 7)) {\n> -\t\tconvert_ascii_sha1(buffer+7);\n> -\t\tbuffer += 48;\n> +\t\tconvert_ascii_sha1((char *) buffer + 7);\n> +\t\tbuffer = (char *) buffer + 48;\n>  \t}\n>  \tconvert_date(orig_buffer, orig_size, result_sha1);\n>  }\n\nHmmmmmmm.  Now I start to wonder if changing the type of \"void *buffer\"\nto \"char *buffer\" is cleaner.\n\n> diff --git a/diff-delta.c b/diff-delta.c\n> index 25a798d..8b9172a 100644\n> --- a/diff-delta.c\n> +++ b/diff-delta.c\n> @@ -22,6 +22,7 @@ #include <stdlib.h>\n>  #include <string.h>\n>  #include \"delta.h\"\n>  \n> +#include \"git-compat-util.h\"\n>  \n>  /* maximum hash entry list for the same hash bucket */\n>  #define HASH_LIMIT 64\n> @@ -131,7 +132,7 @@ struct delta_index {\n>  \tconst void *src_buf;\n>  \tunsigned long src_size;\n>  \tunsigned int hash_mask;\n> -\tstruct index_entry *hash[0];\n> +\tstruct index_entry *hash[FLEX_ARRAY];\n>  };\n\nGood -- I missed this when we did FLEX_ARRAY.  Thanks.\n\n> diff --git a/diff-lib.c b/diff-lib.c\n> index 2183b41..fdc1173 100644\n> --- a/diff-lib.c\n> +++ b/diff-lib.c\n> @@ -34,21 +34,23 @@ int run_diff_files(struct rev_info *revs\n>  \t\t\tcontinue;\n>  \n>  \t\tif (ce_stage(ce)) {\n> -\t\t\tstruct {\n> -\t\t\t\tstruct combine_diff_path p;\n> -\t\t\t\tstruct combine_diff_parent filler[5];\n> -\t\t\t} combine;\n\nI admit this part was ugly.  The new code does not do any extra\nallocations and matches the other use of \"struct combine_diff_path\"\nmore closely.  Good change.\n\n> @@ -1136,13 +1136,14 @@ int fetch(unsigned char *sha1)\n>  \n>  static inline int needs_quote(int ch)\n>  {\n> -\tswitch (ch) {\n> -\tcase '/': case '-': case '.':\n> -\tcase 'A'...'Z':\tcase 'a'...'z':\tcase '0'...'9':\n> +\tif (((ch >= 'A') && (ch <= 'Z'))\n> +\t\t\t|| ((ch >= 'a') && (ch <= 'z'))\n> +\t\t\t|| ((ch >= '0') && (ch <= '9'))\n> +\t\t\t|| (ch == '/')\n> +\t\t\t|| (ch == '-')\n> +\t\t\t|| (ch == '.'))\n>  \t\treturn 0;\n> -\tdefault:\n> -\t\treturn 1;\n> -\t}\n> +\treturn 1;\n>  }\n\nUgh.  Delight of standard compliance X-<.\n\n> diff --git a/http-push.c b/http-push.c\n> index 2d9441e..0684e46 100644\n> --- a/http-push.c\n> +++ b/http-push.c\n> @@ -1077,13 +1077,14 @@ static int fetch_indices(void)\n>  \n>  static inline int needs_quote(int ch)\n\nHmph.  Thanks for noticing the duplicated code; maybe move it to\ncache.h perhaps?\n"},{"id":"21999","messageId":"20060618083502.GB1331@verplant.org","threadId":"4553","inReplyTo":"44950E32.10904@lsrfire.ath.cx","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Florian Forster","fromEmail":"octo@verplant.org","sentAt":"2006-06-18T08:35:03Z","receivedAt":"2006-06-18T08:35:03Z","isPatch":true,"sender":{"key":"octo@verplant.org","avatar":null},"body":"Hi Rene,\n\nOn Sun, Jun 18, 2006 at 10:26:26AM +0200, Rene Scharfe wrote:\n> However, could you split it up a bit?\n\nSure, I'll follow up on this in a short while..\n\n-octo\n-- \nFlorian octo Forster\nHacker in training\nGnuPG: 0x91523C3D\nhttp://verplant.org/\n"},{"id":"22001","messageId":"20060618114352.15191199.tihirvon@gmail.com","threadId":"4553","inReplyTo":"20060618082103.GA1331@verplant.org","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Timo Hirvonen","fromEmail":"tihirvon@gmail.com","sentAt":"2006-06-18T08:43:52Z","receivedAt":"2006-06-18T08:43:52Z","isPatch":true,"sender":{"key":"tihirvon@gmail.com","avatar":null},"body":"Florian Forster <octo@verplant.org> wrote:\n\n> GCC ignores the FAM in this case and allocates `sizeof (struct\n> combine_diff_path)' bytes. However, this is not correct according to\n> ANSI and prevents building using other compilers (e.g. Sun cc).\n\nFair enough.\n\n> To be honest, I don't get the point of FAMs anyways. Why don't we just\n> use a pointer to `struct combine_diff_parent' there in the first place?\n\nIn general FAMs are used to replace two mallocs with one.\n\n    x = malloc(sizeof(struct foo) + 100)\n\ninstead of \n\n    x = malloc(sizeof(struct foo));\n    x->y = malloc(100);\n\n-- \nhttp://onion.dynserv.net/~timo/\n"},{"id":"22023","messageId":"11506438892865-git-send-email-octo@verplant.org","threadId":"4553","inReplyTo":"20060618083502.GB1331@verplant.org","subject":"[PATCH 0/7] Improve ANSI C99 compliance","fromName":"Florian Forster","fromEmail":"octo@verplant.org","sentAt":"2006-06-18T15:18:02Z","receivedAt":"2006-06-18T15:18:02Z","isPatch":true,"sender":{"key":"octo@verplant.org","avatar":null},"body":"Hi,\n\nas promised I've split up the changes into several smaller patches. The changes\nare grouped by type of problem they fix, as requested. The patches should not\ndepend on each other, but I didn't actually test that.\n\nRegards,\n-octo\n"},{"id":"22031","messageId":"Pine.LNX.4.64.0606180946090.5498@g5.osdl.org","threadId":"4553","inReplyTo":"1150609831500-git-send-email-octo@verplant.org","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-06-18T16:50:37Z","receivedAt":"2006-06-18T16:50:37Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sun, 18 Jun 2006, Florian Forster wrote:\n>\n> Using this patch I was able to build git with\n> $ make CFLAGS=\"-Wall -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE\"\n\n\"-ansi -pedantic\" is really not useful.\n\n> While most of this patch fixes void-pointer arithmetic\n\nThis one I disagree with. Doing arithmetic on \"void *\" is _really_ useful, \nand I think most compilers end up supporting it either to be compatible \nwith gcc, or just because it's hard to not do it.\n\nIt makes code a _lot_ cleaner.\n\nIn general, explicit casts are a sign of bad programming, and \"void *\" is \nthere exactly to avoid it. And doing arithmetic on pointers is useful and \nfairly common, and if you accept void-pointer arithmetic, it avoids a lot \nof ugly and useless casts.\n\n> @@ -301,9 +301,9 @@ static void fill_line_map(struct commit \n>  \t\t\t\tif (DEBUG)\n>  \t\t\t\t\tprintf(\"map: i1: %d %d %p i2: %d %d %p\\n\",\n>  \t\t\t\t\t       i1, map[i1],\n> -\t\t\t\t\t       i1 != -1 ? blame_lines[map[i1]] : NULL,\n> +\t\t\t\t\t       (void *) (i1 != -1 ? blame_lines[map[i1]] : NULL),\n>  \t\t\t\t\t       i2, map2[i2],\n> -\t\t\t\t\t       i2 != -1 ? blame_lines[map2[i2]] : NULL);\n> +\t\t\t\t\t       (void *) (i2 != -1 ? blame_lines[map2[i2]] : NULL));\n\nGaah. This is another case of casting that I'm sure is technically \ncorrect, but that I wonder whether there is any machine that actually \ncares..\n\nBut at least in that case I suspect the cast _may_ be required due to \ndifferent pointer representations.\n\n\t\tLinus\n"},{"id":"22075","messageId":"20060619212116.GL1331@verplant.org","threadId":"4553","inReplyTo":"Pine.LNX.4.64.0606180946090.5498@g5.osdl.org","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Florian Forster","fromEmail":"octo@verplant.org","sentAt":"2006-06-19T21:21:16Z","receivedAt":"2006-06-19T21:21:16Z","isPatch":true,"sender":{"key":"octo@verplant.org","avatar":null},"body":"On Sun, Jun 18, 2006 at 09:50:37AM -0700, Linus Torvalds wrote:\n> > While most of this patch fixes void-pointer arithmetic\n> \n> This one I disagree with. Doing arithmetic on \"void *\" is _really_ useful, \n\nAgreed: If you want to walk over the memory pointed to by a void-pointer\nyou want to do that byte-wise in the great majority of all cases.\n\n> and I think most compilers end up supporting it either to be\n> compatible with gcc, or just because it's hard to not do it.\n\nNow this statement I don't agree with. (And by that I don't mean I\nassume it to be false.)\n\nI didn't start writing the patch because I like C99 so much. In fact, in\nmy opinion it introduces some possibilities I'd rather not have in C\nbecause people might actually use them. But by default the Sun cc\ncomplains about void-pointer arithmetic and I feel awkward to force the\ncompiler to accept broken code.\n\nMaybe Rene Scharfe's method (as used in the patch to git-tar-tree) is a\ngood way around it? There are no explicit casts involved and standard-\ncompliant compilers like it, too. The downside is that you have two\nvariables for the same thing/memory.\n\nRegards,\n-octo\n-- \nFlorian octo Forster\nHacker in training\nGnuPG: 0x91523C3D\nhttp://verplant.org/\n"},{"id":"22095","messageId":"7vac8860z9.fsf@assigned-by-dhcp.cox.net","threadId":"4553","inReplyTo":"20060619212116.GL1331@verplant.org","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-20T01:59:38Z","receivedAt":"2006-06-20T01:59:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Florian Forster <octo@verplant.org> writes:\n\n> I didn't start writing the patch because I like C99 so much. In fact, in\n> my opinion it introduces some possibilities I'd rather not have in C\n> because people might actually use them. But by default the Sun cc\n> complains about void-pointer arithmetic...\n\nI am reasonably sympathetic to that, and judging from the number\nof lines the patch touches, I am not as strongly opposed to it\nas Linus seems to be.\n\n> Maybe Rene Scharfe's method (as used in the patch to git-tar-tree) is a\n> good way around it? There are no explicit casts involved and standard-\n> compliant compilers like it, too. The downside is that you have two\n> variables for the same thing/memory.\n\nI think Rene's patch makes sense primarily because the functions\naffected are small and we can easily see that the aliased input\nvariable (\"data\") is not used -- IOW, there is no confusion.\n\nIf it were a big function and the code used one variable for\nsome purpose and the other one for another purpose, it would be\nfar worse than having to cast the same variable occasionally.\n\nBTW, I think we would probably want to have this patch on top of\nRene's patch.  In all instances, the variable \"buf\" is of type\n\"const char *\" and the existing casts do not make sense to me.\n\n\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex 5c8a5f0..39a61b6 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -36,7 +36,7 @@ static void reliable_write(const void *d\n \t\t\tdie(\"git-tar-tree: disk full?\");\n \t\t}\n \t\tsize -= ret;\n-\t\tbuf = (char *) buf + ret;\n+\t\tbuf += ret;\n \t}\n }\n \n@@ -65,13 +65,13 @@ static void write_blocked(const void *da\n \t\tmemcpy(block + offset, buf, chunk);\n \t\tsize -= chunk;\n \t\toffset += chunk;\n-\t\tbuf = (char *) buf + chunk;\n+\t\tbuf += chunk;\n \t\twrite_if_needed();\n \t}\n \twhile (size >= BLOCKSIZE) {\n \t\treliable_write(buf, BLOCKSIZE);\n \t\tsize -= BLOCKSIZE;\n-\t\tbuf = (char *) buf + BLOCKSIZE;\n+\t\tbuf += BLOCKSIZE;\n \t}\n \tif (size) {\n \t\tmemcpy(block + offset, buf, size);\n"},{"id":"22117","messageId":"4497AED4.5060505@lsrfire.ath.cx","threadId":"4553","inReplyTo":"7vac8860z9.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Rene Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2006-06-20T08:16:20Z","receivedAt":"2006-06-20T08:16:20Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Junio C Hamano schrieb:\n> BTW, I think we would probably want to have this patch on top of\n> Rene's patch.  In all instances, the variable \"buf\" is of type\n> \"const char *\" and the existing casts do not make sense to me.\n> \n> \n> diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\n> index 5c8a5f0..39a61b6 100644\n\nYour patch reverts builtin-tar-tree.c to the version which is\ncurrently both in master and next, which I think is a good\nchange.  However, could it be avoided at merge time?\n\nOT: I found the blobs 5c8a5f0 and 39a61b6 by guessing (they are\nbuiltin-tar-tree.c in pu and master, respectively).  OK, that\nwas easy.  But is there a way to reversely look up an object\nwithout guessing, i.e. find out which commit(s) introduced a\ncertain blob?\n\nThanks,\nRené\n"},{"id":"22119","messageId":"7vr71kcien.fsf@assigned-by-dhcp.cox.net","threadId":"4553","inReplyTo":"4497AED4.5060505@lsrfire.ath.cx","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-20T08:58:56Z","receivedAt":"2006-06-20T08:58:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rene Scharfe <rene.scharfe@lsrfire.ath.cx> writes:\n\n> Junio C Hamano schrieb:\n>> BTW, I think we would probably want to have this patch on top of\n>> Rene's patch.  In all instances, the variable \"buf\" is of type\n>> \"const char *\" and the existing casts do not make sense to me.\n>> \n>> diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\n>> index 5c8a5f0..39a61b6 100644\n>\n> Your patch reverts builtin-tar-tree.c to the version which is\n> currently both in master and next, which I think is a good\n> change.  However, could it be avoided at merge time?\n\nSorry for attributing those \"casts [that] do not make sense to\nme\" to you -- it is not your code but part of Florian's patch.\n\nI think applying the patch in question on top of Florian's 11172e\nwould be the most sensible, since that is currently the tip of ff/c99\ntopic branch whose early parts have been merged to \"next\" and\nthe tip to \"pu\".  When Linus feels as sympathetic as I do, we\ncan pull the rest of ff/c99 branch to \"next\" and then eventually\nto \"master\" and the patch will be merged together without\nintroducing the nonsense casts.\n\nAnother possibility is to amend the tip of ff/c99 topic branch,\nsince it is not merged to \"next\" yet.  I promised not to rewind\n\"master\" nor \"next\", but never made promises not to rewind \"pu\",\nso it is a fair game.  I think it is simpler and cleaner, so\nthat will be what I will do.\n\n> OT: I found the blobs 5c8a5f0 and 39a61b6 by guessing (they are\n> builtin-tar-tree.c in pu and master, respectively).  OK, that\n> was easy.  But is there a way to reversely look up an object\n> without guessing, i.e. find out which commit(s) introduced a\n> certain blob?\n\nYou could do something like this (totally untested).\n\nGoing from the above \"diff --git\" index line you have object\nname abbreviations and pathnames as clues.  To take advantage of\nit, you could use \"git rev-list pu -- builtin-tar-tree.c\"\ninstead of unlimited list.\n\n$ git rev-list pu |\n  git diff-tree -r --stdin --pretty |\n  perl -e '\n\tmy @lines = ();\n        sub flush_em {\n        \tmy @found = ();\n                my @comment = ();\n\t\tfor my $l (@lines) {\n                \tif ($l !~ /^:/) {\n\t\t\t\tpush @comment, $l;\n\t\t\t\tnext;\n\t\t\t}\n                        for (@ARGV) {\n                        \tif ($l =~ / $_/) {\n                                \tpush @found, $l;\n\t\t\t\t\tlast;\n\t\t\t\t}\n                        }\n                }\n\t\tif (@found) {\n\t\t\tprint join(\"\", @comment, @found);\n                }\n                @lines = ();\n\t}\n        while (<STDIN>) {\n        \tif (/^commit [0-9a-f]{40}$/) { flush_em(); }\n                push @lines, $_;\n\t}\n        flush_em();\n  ' 39a61b6 5c8a5f0\n"},{"id":"22199","messageId":"7vodwmzrn5.fsf@assigned-by-dhcp.cox.net","threadId":"4553","inReplyTo":"7vr71kcien.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Fix git to be (more) ANSI C99 compliant.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-21T11:15:26Z","receivedAt":"2006-06-21T11:15:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> I think applying the patch in question on top of Florian's 11172e\n> would be the most sensible, since that is currently the tip of ff/c99\n> topic branch whose early parts have been merged to \"next\" and\n> the tip to \"pu\".  When Linus feels as sympathetic as I do, we\n> can pull the rest of ff/c99 branch to \"next\" and then eventually\n> to \"master\" and the patch will be merged together without\n> introducing the nonsense casts.\n\nNow, without asking Linus about this further, I felt sympathetic\nenough to decide that void-pointer arithmetic avoidance is not\nso bad (touches only 70 lines or so in 19 files); tonight's\n\"next\" should be compilable with the default Solaris compiler.\n"}]}