@matheusbsbs / matheus-bagliano / commits / b4b1550315
Fork 0

Don't instantiate structures with FAMs.

Since structures with `flexible array members' are an incomplete datatype ANSI C99 forbids creating instances of them. This patch removes such an instance from `diff-lib.c' and replaces it with a pointer to a `struct combine_diff_path'. Since all neccessary memory is allocated at once the number of calls to `xmalloc' is not increased. Signed-off-by: Florian Forster <octo@verplant.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Florian Forster committed Jun 18, 2006 at 17:18 UTC b4b1550315c6184ea50936be305a4f1c78ad16a8
1 file changed +22 -19
diff-lib.c
+22 -19
@@ -34,21 +34,23 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
34 continue;
35
36 if (ce_stage(ce)) {
37 - struct {
38 - struct combine_diff_path p;
39 - struct combine_diff_parent filler[5];
40 - } combine;
37 + struct combine_diff_path *dpath;
38 int num_compare_stages = 0;
39 + size_t path_len;
40
43 - combine.p.next = NULL;
44 - combine.p.len = ce_namelen(ce);
45 - combine.p.path = xmalloc(combine.p.len + 1);
46 - memcpy(combine.p.path, ce->name, combine.p.len);
47 - combine.p.path[combine.p.len] = 0;
48 - combine.p.mode = 0;
49 - memset(combine.p.sha1, 0, 20);
50 - memset(&combine.p.parent[0], 0,
51 - sizeof(combine.filler));
41 + path_len = ce_namelen(ce);
42 +
43 + dpath = xmalloc (combine_diff_path_size (5, path_len));
44 + dpath->path = (char *) &(dpath->parent[5]);
45 +
46 + dpath->next = NULL;
47 + dpath->len = path_len;
48 + memcpy(dpath->path, ce->name, path_len);
49 + dpath->path[path_len] = '\0';
50 + dpath->mode = 0;
51 + memset(dpath->sha1, 0, 20);
52 + memset(&(dpath->parent[0]), 0,
53 + sizeof(struct combine_diff_parent)*5);
54
55 while (i < entries) {
56 struct cache_entry *nce = active_cache[i];
@@ -64,11 +66,11 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
66 if (2 <= stage) {
67 int mode = ntohl(nce->ce_mode);
68 num_compare_stages++;
67 - memcpy(combine.p.parent[stage-2].sha1,
69 + memcpy(dpath->parent[stage-2].sha1,
70 nce->sha1, 20);
69 - combine.p.parent[stage-2].mode =
71 + dpath->parent[stage-2].mode =
72 canon_mode(mode);
71 - combine.p.parent[stage-2].status =
73 + dpath->parent[stage-2].status =
74 DIFF_STATUS_MODIFIED;
75 }
76
@@ -83,13 +85,14 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
85 i--;
86
87 if (revs->combine_merges && num_compare_stages == 2) {
86 - show_combined_diff(&combine.p, 2,
88 + show_combined_diff(dpath, 2,
89 revs->dense_combined_merges,
90 revs);
89 - free(combine.p.path);
91 + free(dpath);
92 continue;
93 }
92 - free(combine.p.path);
94 + free(dpath);
95 + dpath = NULL;
96
97 /*
98 * Show the diff for the 'ce' if we found the one