{"thread":{"id":"22963","subject":"Portability patches vs 1.7.0.2 [4/6]","startedAt":"2010-03-09T16:11:32Z","lastAt":"2010-03-09T16:11:32Z","messageCount":1,"participants":["Gary V. Vaughan"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"136450","messageId":"20100309161132.GE99172@thor.il.thewrittenword.com","threadId":"22963","inReplyTo":null,"subject":"Portability patches vs 1.7.0.2 [4/6]","fromName":"Gary V. Vaughan","fromEmail":"git@mlists.thewrittenword.com","sentAt":"2010-03-09T16:11:32Z","receivedAt":"2010-03-09T16:11:32Z","isPatch":false,"sender":{"key":"git@mlists.thewrittenword.com","avatar":null},"body":"## Dynamic expressions in compound declarations are not portable\n\nUnfortunately, there are still plenty of production systems with\nvendor compilers that choke unless all compound declarations can be\ndetermined statically at compile time, for example hpux10.20 (I can\nprovide a comprehensive list of our supported platforms that exhibit\nthis problem if necessary).\n\nThis patch simply breaks apart any compound declarations with dynamic\ninitialisation expressions, and moves the initialisation until after\nthe last declaration in the same block, in all the places necessary to\nhave the offending compilers accept the code.\n\nCheers,\n-- \nGary V. Vaughan (gary@thewrittenword.com)\n\n\nIndex: convert.c\n===================================================================\n--- convert.c.orig\n+++ convert.c\n@@ -249,7 +249,10 @@ static int filter_buffer(int fd, void *d\n \tstruct child_process child_process;\n \tstruct filter_params *params = (struct filter_params *)data;\n \tint write_err, status;\n-\tconst char *argv[] = { params->cmd, NULL };\n+\tconst char *argv[2];\n+\n+\targv[0] = params->cmd;\n+\targv[1] = NULL;\n \n \tmemset(&child_process, 0, sizeof(child_process));\n \tchild_process.argv = argv;\nIndex: remote.c\n===================================================================\n--- remote.c.orig\n+++ remote.c\n@@ -476,7 +476,7 @@ static void read_config(void)\n \tunsigned char sha1[20];\n \tconst char *head_ref;\n \tint flag;\n-\tif (default_remote_name) // did this already\n+\tif (default_remote_name) /* did this already */\n \t\treturn;\n \tdefault_remote_name = xstrdup(\"origin\");\n \tcurrent_branch = NULL;\n@@ -657,9 +657,10 @@ static struct refspec *parse_refspec_int\n \n int valid_fetch_refspec(const char *fetch_refspec_str)\n {\n-\tconst char *fetch_refspec[] = { fetch_refspec_str };\n+\tchar *fetch_refspec[1];\n \tstruct refspec *refspec;\n \n+\tfetch_refspec[0] = fetch_refspec_str;\n \trefspec = parse_refspec_internal(1, fetch_refspec, 1, 1);\n \tfree_refspecs(refspec, 1);\n \treturn !!refspec;\nIndex: unpack-trees.c\n===================================================================\n--- unpack-trees.c.orig\n+++ unpack-trees.c\n@@ -287,9 +287,11 @@ static void add_same_unmerged(struct cac\n static int unpack_index_entry(struct cache_entry *ce,\n \t\t\t      struct unpack_trees_options *o)\n {\n-\tstruct cache_entry *src[5] = { ce, NULL, };\n+\tstruct cache_entry *src[5] = { NULL, NULL };\n \tint ret;\n \n+\tsrc[0] = ce;\n+\n \tmark_ce_used(ce, o);\n \tif (ce_stage(ce)) {\n \t\tif (o->skip_unmerged) {\nIndex: daemon.c\n===================================================================\n--- daemon.c.orig\n+++ daemon.c\n@@ -141,15 +141,14 @@ static char *path_ok(char *directory)\n \t}\n \telse if (interpolated_path && saw_extended_args) {\n \t\tstruct strbuf expanded_path = STRBUF_INIT;\n-\t\tstruct strbuf_expand_dict_entry dict[] = {\n-\t\t\t{ \"H\", hostname },\n-\t\t\t{ \"CH\", canon_hostname },\n-\t\t\t{ \"IP\", ip_address },\n-\t\t\t{ \"P\", tcp_port },\n-\t\t\t{ \"D\", directory },\n-\t\t\t{ NULL }\n-\t\t};\n+\t\tstruct strbuf_expand_dict_entry dict[6];\n \n+\t\tdict[0].placeholder = \"H\"; dict[0].value = hostname;\n+\t\tdict[1].placeholder = \"CH\"; dict[1].value = canon_hostname;\n+\t\tdict[2].placeholder = \"IP\"; dict[2].value = ip_address;\n+\t\tdict[3].placeholder = \"P\"; dict[3].value = tcp_port;\n+\t\tdict[4].placeholder = \"D\"; dict[4].value = directory;\n+\t\tdict[5].placeholder = NULL; dict[5].value = NULL;\n \t\tif (*dir != '/') {\n \t\t\t/* Allow only absolute */\n \t\t\tlogerror(\"'%s': Non-absolute path denied (interpolated-path active)\", dir);\n@@ -343,7 +342,9 @@ static int upload_pack(void)\n {\n \t/* Timeout as string */\n \tchar timeout_buf[64];\n-\tconst char *argv[] = { \"upload-pack\", \"--strict\", timeout_buf, \".\", NULL };\n+\tchar *argv[] = { \"upload-pack\", \"--strict\", \"<timeout_buf>\", \".\", NULL };\n+\n+\targv[2] = timeout_buf;\n \n \tsnprintf(timeout_buf, sizeof timeout_buf, \"--timeout=%u\", timeout);\n \treturn run_service_command(argv);\n@@ -885,7 +886,7 @@ static int service_loop(int socknum, int\n \t\tfor (i = 0; i < socknum; i++) {\n \t\t\tif (pfd[i].revents & POLLIN) {\n \t\t\t\tstruct sockaddr_storage ss;\n-\t\t\t\tunsigned int sslen = sizeof(ss);\n+\t\t\t\tsize_t sslen = sizeof(ss);\n \t\t\t\tint incoming = accept(pfd[i].fd, (struct sockaddr *)&ss, &sslen);\n \t\t\t\tif (incoming < 0) {\n \t\t\t\t\tswitch (errno) {\nIndex: wt-status.c\n===================================================================\n--- wt-status.c.orig\n+++ wt-status.c\n@@ -464,17 +464,18 @@ static void wt_status_print_submodule_su\n \tstruct child_process sm_summary;\n \tchar summary_limit[64];\n \tchar index[PATH_MAX];\n-\tconst char *env[] = { index, NULL };\n-\tconst char *argv[] = {\n-\t\t\"submodule\",\n-\t\t\"summary\",\n-\t\tuncommitted ? \"--files\" : \"--cached\",\n-\t\t\"--for-status\",\n-\t\t\"--summary-limit\",\n-\t\tsummary_limit,\n-\t\tuncommitted ? NULL : (s->amend ? \"HEAD^\" : \"HEAD\"),\n-\t\tNULL\n-\t};\n+\tconst char *env[2] = { NULL, NULL };\n+\tconst char *argv[8];\n+\n+\tenv[0] =\tindex;\n+\targv[0] =\t\"submodule\";\n+\targv[1] =\t\"summary\";\n+\targv[2] =\tuncommitted ? \"--files\" : \"--cached\";\n+\targv[3] =\t\"--for-status\";\n+\targv[4] =\t\"--summary-limit\";\n+\targv[5] =\tsummary_limit;\n+\targv[6] =\tuncommitted ? NULL : (s->amend ? \"HEAD^\" : \"HEAD\");\n+\targv[7] =\tNULL;\n \n \tsprintf(summary_limit, \"%d\", s->submodule_summary);\n \tsnprintf(index, sizeof(index), \"GIT_INDEX_FILE=%s\", s->index_file);\nIndex: ll-merge.c\n===================================================================\n--- ll-merge.c.orig\n+++ ll-merge.c\n@@ -172,17 +172,17 @@ static int ll_ext_merge(const struct ll_\n {\n \tchar temp[4][50];\n \tstruct strbuf cmd = STRBUF_INIT;\n-\tstruct strbuf_expand_dict_entry dict[] = {\n-\t\t{ \"O\", temp[0] },\n-\t\t{ \"A\", temp[1] },\n-\t\t{ \"B\", temp[2] },\n-\t\t{ \"L\", temp[3] },\n-\t\t{ NULL }\n-\t};\n+\tstruct strbuf_expand_dict_entry dict[5];\n \tconst char *args[] = { NULL, NULL };\n \tint status, fd, i;\n \tstruct stat st;\n \n+\tdict[0].placeholder = \"O\"; dict[0].value = temp[0];\n+\tdict[1].placeholder = \"A\"; dict[1].value = temp[1];\n+\tdict[2].placeholder = \"B\"; dict[2].value = temp[2];\n+\tdict[3].placeholder = \"L\"; dict[3].value = temp[3];\n+\tdict[3].placeholder = NULL; dict[3].value = NULL;\n+\n \tif (fn->cmdline == NULL)\n \t\tdie(\"custom merge driver %s lacks command line.\", fn->name);\n \nIndex: builtin-commit.c\n===================================================================\n--- builtin-commit.c.orig\n+++ builtin-commit.c\n@@ -715,7 +715,8 @@ static int prepare_to_commit(const char \n \n \tif (use_editor) {\n \t\tchar index[PATH_MAX];\n-\t\tconst char *env[2] = { index, NULL };\n+\t\tchar *env[2];\n+\t\tenv[0] =  index; env[1] = NULL;\n \t\tsnprintf(index, sizeof(index), \"GIT_INDEX_FILE=%s\", index_file);\n \t\tif (launch_editor(git_path(commit_editmsg), NULL, env)) {\n \t\t\tfprintf(stderr,\nIndex: builtin-remote.c\n===================================================================\n--- builtin-remote.c.orig\n+++ builtin-remote.c\n@@ -705,11 +705,14 @@ static int rm(int argc, const char **arg\n \tstruct known_remotes known_remotes = { NULL, NULL };\n \tstruct string_list branches = { NULL, 0, 0, 1 };\n \tstruct string_list skipped = { NULL, 0, 0, 1 };\n-\tstruct branches_for_remote cb_data = {\n-\t\tNULL, &branches, &skipped, &known_remotes\n-\t};\n+\tstruct branches_for_remote cb_data;\n \tint i, result;\n \n+\tmemset(&cb_data,0,sizeof(cb_data));\n+\tcb_data.branches = &branches;\n+\tcb_data.skipped = &skipped;\n+\tcb_data.keep = &known_remotes;\n+\n \tif (argc != 2)\n \t\tusage_with_options(builtin_remote_rm_usage, options);\n \nIndex: builtin-blame.c\n===================================================================\n--- builtin-blame.c.orig\n+++ builtin-blame.c\n@@ -733,10 +733,11 @@ static int pass_blame_to_parent(struct s\n {\n \tint last_in_target;\n \tmmfile_t file_p, file_o;\n-\tstruct blame_chunk_cb_data d = { sb, target, parent, 0, 0 };\n+\tstruct blame_chunk_cb_data d;\n \txpparam_t xpp;\n \txdemitconf_t xecfg;\n-\n+\tmemset(&d,0,sizeof(d));\n+\td.sb = sb; d.target = target; d.parent=parent;\n \tlast_in_target = find_last_in_target(sb, target);\n \tif (last_in_target < 0)\n \t\treturn 1; /* nothing remains for this target */\n@@ -875,10 +876,11 @@ static void find_copy_in_blob(struct sco\n \tconst char *cp;\n \tint cnt;\n \tmmfile_t file_o;\n-\tstruct handle_split_cb_data d = { sb, ent, parent, split, 0, 0 };\n+\tstruct handle_split_cb_data d;\n \txpparam_t xpp;\n \txdemitconf_t xecfg;\n-\n+\tmemset(&d,0,sizeof(d));\n+\td.sb = sb; d.ent = ent; d.parent = parent; d.split = split;\n \t/*\n \t * Prepare mmfile that contains only the lines in ent.\n \t */\nIndex: builtin-cat-file.c\n===================================================================\n--- builtin-cat-file.c.orig\n+++ builtin-cat-file.c\n@@ -118,7 +118,10 @@ static int cat_one_file(int opt, const c\n \n \t\t/* custom pretty-print here */\n \t\tif (type == OBJ_TREE) {\n-\t\t\tconst char *ls_args[3] = {\"ls-tree\", obj_name, NULL};\n+\t\t\tchar *ls_args[3];\n+\t\t\tls_args[0] =  \"ls-tree\";\n+\t\t\tls_args[1] =  obj_name;\n+\t\t\tls_args[2] = NULL;\n \t\t\treturn cmd_ls_tree(2, ls_args, NULL);\n \t\t}\n \nIndex: refs.c\n===================================================================\n--- refs.c.orig\n+++ refs.c\n@@ -311,7 +311,11 @@ static int warn_if_dangling_symref(const\n \n void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)\n {\n-\tstruct warn_if_dangling_data data = { fp, refname, msg_fmt };\n+\tstruct warn_if_dangling_data data;\n+\n+\tdata.fp = fp;\n+\tdata.refname = refname;\n+\tdata.msg_fmt = msg_fmt;\n \tfor_each_rawref(warn_if_dangling_symref, &data);\n }\n \nIndex: builtin-pack-objects.c\n===================================================================\n--- builtin-pack-objects.c.orig\n+++ builtin-pack-objects.c\n@@ -1651,6 +1651,8 @@ static void ll_find_deltas(struct object\n \t\t\t\tdelta_search_threads);\n \tp = xcalloc(delta_search_threads, sizeof(*p));\n \n+\tp = xmalloc(delta_search_threads * sizeof(struct thread_params));\n+\n \t/* Partition the work amongst work threads. */\n \tfor (i = 0; i < delta_search_threads; i++) {\n \t\tunsigned sub_size = list_size / (delta_search_threads - i);\n@@ -2085,6 +2087,8 @@ static void loosen_unused_packed_objects\n \t\t\t\t\tdie(\"unable to force loose object\");\n \t\t}\n \t}\n+\n+\tfree(p);\n }\n \n static void get_object_list(int ac, const char **av)\nIndex: builtin-add.c\n===================================================================\n--- builtin-add.c.orig\n+++ builtin-add.c\n@@ -254,13 +254,15 @@ int interactive_add(int argc, const char\n static int edit_patch(int argc, const char **argv, const char *prefix)\n {\n \tchar *file = xstrdup(git_path(\"ADD_EDIT.patch\"));\n-\tconst char *apply_argv[] = { \"apply\", \"--recount\", \"--cached\",\n-\t\tfile, NULL };\n+\tchar *apply_argv[] = { \"apply\", \"--recount\", \"--cached\",\n+\t\t\"<file>\", NULL };\n \tstruct child_process child;\n \tstruct rev_info rev;\n \tint out;\n \tstruct stat st;\n \n+\tapply_argv[3] = file;\n+\n \tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n \n \tif (read_cache() < 0)\nIndex: builtin-checkout.c\n===================================================================\n--- builtin-checkout.c.orig\n+++ builtin-checkout.c\n@@ -612,7 +612,8 @@ static int check_tracking_name(const cha\n \n static const char *unique_tracking_name(const char *name)\n {\n-\tstruct tracking_name_data cb_data = { name, NULL, 1 };\n+\tstruct tracking_name_data cb_data = { NULL, NULL, 1 };\n+        cb_data.name = name;\n \tfor_each_ref(check_tracking_name, &cb_data);\n \tif (cb_data.unique)\n \t\treturn cb_data.remote;\nIndex: builtin-fetch.c\n===================================================================\n--- builtin-fetch.c.orig\n+++ builtin-fetch.c\n@@ -573,9 +573,10 @@ static void find_non_local_tags(struct t\n {\n \tstruct string_list existing_refs = { NULL, 0, 0, 0 };\n \tstruct string_list remote_refs = { NULL, 0, 0, 0 };\n-\tstruct tag_data data = {head, tail};\n+\tstruct tag_data data;\n \tconst struct ref *ref;\n \tstruct string_list_item *item = NULL;\n+\tdata.head = head; data.tail = tail;\n \n \tfor_each_ref(add_existing, &existing_refs);\n \tfor (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {\n@@ -768,7 +769,8 @@ static int get_remote_group(const char *\n static int add_remote_or_group(const char *name, struct string_list *list)\n {\n \tint prev_nr = list->nr;\n-\tstruct remote_group_data g = { name, list };\n+\tstruct remote_group_data g;\n+\tg.name = name; g.list = list;\n \n \tgit_config(get_remote_group, &g);\n \tif (list->nr == prev_nr) {\n"}]}