Skip to content

Commit d8ce144

Browse files
committed
Merge branch 'jk/misc-uninitialized-fixes'
Various fixes to codepaths gcc 9 had trouble following dataflow. * jk/misc-uninitialized-fixes: pack-objects: drop packlist index_pos optimization test-read-cache: drop namelen variable diff-delta: set size out-parameter to 0 for NULL delta bulk-checkin: zero-initialize hashfile_checkpoint pack-objects: use object_id in packlist_alloc() git-am: handle missing "author" when parsing commit
2 parents 2be6ccc + 3a37876 commit d8ce144

9 files changed

+38
-40
lines changed

builtin/am.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,9 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
12721272
buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());
12731273

12741274
ident_line = find_commit_header(buffer, "author", &ident_len);
1275-
1275+
if (!ident_line)
1276+
die(_("missing author line in commit %s"),
1277+
oid_to_hex(&commit->object.oid));
12761278
if (split_ident_line(&id, ident_line, ident_len) < 0)
12771279
die(_("invalid ident line: %.*s"), (int)ident_len, ident_line);
12781280

builtin/pack-objects.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
610610
void *cb_data)
611611
{
612612
struct object_id peeled;
613-
struct object_entry *entry = packlist_find(&to_pack, oid, NULL);
613+
struct object_entry *entry = packlist_find(&to_pack, oid);
614614

615615
if (entry)
616616
entry->tagged = 1;
617617
if (!peel_ref(path, &peeled)) {
618-
entry = packlist_find(&to_pack, &peeled, NULL);
618+
entry = packlist_find(&to_pack, &peeled);
619619
if (entry)
620620
entry->tagged = 1;
621621
}
@@ -996,12 +996,11 @@ static int no_try_delta(const char *path)
996996
* few lines later when we want to add the new entry.
997997
*/
998998
static int have_duplicate_entry(const struct object_id *oid,
999-
int exclude,
1000-
uint32_t *index_pos)
999+
int exclude)
10011000
{
10021001
struct object_entry *entry;
10031002

1004-
entry = packlist_find(&to_pack, oid, index_pos);
1003+
entry = packlist_find(&to_pack, oid);
10051004
if (!entry)
10061005
return 0;
10071006

@@ -1141,13 +1140,12 @@ static void create_object_entry(const struct object_id *oid,
11411140
uint32_t hash,
11421141
int exclude,
11431142
int no_try_delta,
1144-
uint32_t index_pos,
11451143
struct packed_git *found_pack,
11461144
off_t found_offset)
11471145
{
11481146
struct object_entry *entry;
11491147

1150-
entry = packlist_alloc(&to_pack, oid->hash, index_pos);
1148+
entry = packlist_alloc(&to_pack, oid);
11511149
entry->hash = hash;
11521150
oe_set_type(entry, type);
11531151
if (exclude)
@@ -1171,11 +1169,10 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
11711169
{
11721170
struct packed_git *found_pack = NULL;
11731171
off_t found_offset = 0;
1174-
uint32_t index_pos;
11751172

11761173
display_progress(progress_state, ++nr_seen);
11771174

1178-
if (have_duplicate_entry(oid, exclude, &index_pos))
1175+
if (have_duplicate_entry(oid, exclude))
11791176
return 0;
11801177

11811178
if (!want_object_in_pack(oid, exclude, &found_pack, &found_offset)) {
@@ -1190,7 +1187,7 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
11901187

11911188
create_object_entry(oid, type, pack_name_hash(name),
11921189
exclude, name && no_try_delta(name),
1193-
index_pos, found_pack, found_offset);
1190+
found_pack, found_offset);
11941191
return 1;
11951192
}
11961193

@@ -1199,17 +1196,15 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
11991196
int flags, uint32_t name_hash,
12001197
struct packed_git *pack, off_t offset)
12011198
{
1202-
uint32_t index_pos;
1203-
12041199
display_progress(progress_state, ++nr_seen);
12051200

1206-
if (have_duplicate_entry(oid, 0, &index_pos))
1201+
if (have_duplicate_entry(oid, 0))
12071202
return 0;
12081203

12091204
if (!want_object_in_pack(oid, 0, &pack, &offset))
12101205
return 0;
12111206

1212-
create_object_entry(oid, type, name_hash, 0, 0, index_pos, pack, offset);
1207+
create_object_entry(oid, type, name_hash, 0, 0, pack, offset);
12131208
return 1;
12141209
}
12151210

@@ -1507,7 +1502,7 @@ static int can_reuse_delta(const unsigned char *base_sha1,
15071502
* First see if we're already sending the base (or it's explicitly in
15081503
* our "excluded" list).
15091504
*/
1510-
base = packlist_find(&to_pack, &base_oid, NULL);
1505+
base = packlist_find(&to_pack, &base_oid);
15111506
if (base) {
15121507
if (!in_same_island(&delta->idx.oid, &base->idx.oid))
15131508
return 0;
@@ -2568,7 +2563,7 @@ static void add_tag_chain(const struct object_id *oid)
25682563
* it was included via bitmaps, we would not have parsed it
25692564
* previously).
25702565
*/
2571-
if (packlist_find(&to_pack, oid, NULL))
2566+
if (packlist_find(&to_pack, oid))
25722567
return;
25732568

25742569
tag = lookup_tag(the_repository, oid);
@@ -2592,7 +2587,7 @@ static int add_ref_tag(const char *path, const struct object_id *oid, int flag,
25922587

25932588
if (starts_with(path, "refs/tags/") && /* is a tag? */
25942589
!peel_ref(path, &peeled) && /* peelable? */
2595-
packlist_find(&to_pack, &peeled, NULL)) /* object packed? */
2590+
packlist_find(&to_pack, &peeled)) /* object packed? */
25962591
add_tag_chain(oid);
25972592
return 0;
25982593
}
@@ -2788,7 +2783,7 @@ static void show_object(struct object *obj, const char *name, void *data)
27882783
for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
27892784
depth++;
27902785

2791-
ent = packlist_find(&to_pack, &obj->oid, NULL);
2786+
ent = packlist_find(&to_pack, &obj->oid);
27922787
if (ent && depth > oe_tree_depth(&to_pack, ent))
27932788
oe_set_tree_depth(&to_pack, ent, depth);
27942789
}
@@ -3019,7 +3014,7 @@ static void loosen_unused_packed_objects(void)
30193014

30203015
for (i = 0; i < p->num_objects; i++) {
30213016
nth_packed_object_oid(&oid, p, i);
3022-
if (!packlist_find(&to_pack, &oid, NULL) &&
3017+
if (!packlist_find(&to_pack, &oid) &&
30233018
!has_sha1_pack_kept_or_nonlocal(&oid) &&
30243019
!loosened_object_can_be_discarded(&oid, p->mtime))
30253020
if (force_object_loose(&oid, p->mtime))

bulk-checkin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
197197
git_hash_ctx ctx;
198198
unsigned char obuf[16384];
199199
unsigned header_len;
200-
struct hashfile_checkpoint checkpoint;
200+
struct hashfile_checkpoint checkpoint = {0};
201201
struct pack_idx_entry *idx = NULL;
202202

203203
seekback = lseek(fd, 0, SEEK_CUR);

diff-delta.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ create_delta(const struct delta_index *index,
326326
const unsigned char *ref_data, *ref_top, *data, *top;
327327
unsigned char *out;
328328

329+
*delta_size = 0;
330+
329331
if (!trg_buf || !trg_size)
330332
return NULL;
331333

pack-bitmap-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static inline void reset_all_seen(void)
144144

145145
static uint32_t find_object_pos(const struct object_id *oid)
146146
{
147-
struct object_entry *entry = packlist_find(writer.to_pack, oid, NULL);
147+
struct object_entry *entry = packlist_find(writer.to_pack, oid);
148148

149149
if (!entry) {
150150
die("Failed to write bitmap index. Packfile doesn't have full closure "

pack-bitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
10611061

10621062
entry = &bitmap_git->pack->revindex[i];
10631063
nth_packed_object_oid(&oid, bitmap_git->pack, entry->nr);
1064-
oe = packlist_find(mapping, &oid, NULL);
1064+
oe = packlist_find(mapping, &oid);
10651065

10661066
if (oe)
10671067
reposition[i] = oe_in_pack_pos(mapping, oe) + 1;

pack-objects.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ static void rehash_objects(struct packing_data *pdata)
6868
}
6969

7070
struct object_entry *packlist_find(struct packing_data *pdata,
71-
const struct object_id *oid,
72-
uint32_t *index_pos)
71+
const struct object_id *oid)
7372
{
7473
uint32_t i;
7574
int found;
@@ -79,9 +78,6 @@ struct object_entry *packlist_find(struct packing_data *pdata,
7978

8079
i = locate_object_entry_hash(pdata, oid, &found);
8180

82-
if (index_pos)
83-
*index_pos = i;
84-
8581
if (!found)
8682
return NULL;
8783

@@ -153,8 +149,7 @@ void prepare_packing_data(struct repository *r, struct packing_data *pdata)
153149
}
154150

155151
struct object_entry *packlist_alloc(struct packing_data *pdata,
156-
const unsigned char *sha1,
157-
uint32_t index_pos)
152+
const struct object_id *oid)
158153
{
159154
struct object_entry *new_entry;
160155

@@ -177,12 +172,19 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
177172
new_entry = pdata->objects + pdata->nr_objects++;
178173

179174
memset(new_entry, 0, sizeof(*new_entry));
180-
hashcpy(new_entry->idx.oid.hash, sha1);
175+
oidcpy(&new_entry->idx.oid, oid);
181176

182177
if (pdata->index_size * 3 <= pdata->nr_objects * 4)
183178
rehash_objects(pdata);
184-
else
185-
pdata->index[index_pos] = pdata->nr_objects;
179+
else {
180+
int found;
181+
uint32_t pos = locate_object_entry_hash(pdata,
182+
&new_entry->idx.oid,
183+
&found);
184+
if (found)
185+
BUG("duplicate object inserted into hash");
186+
pdata->index[pos] = pdata->nr_objects;
187+
}
186188

187189
if (pdata->in_pack)
188190
pdata->in_pack[pdata->nr_objects - 1] = NULL;

pack-objects.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,10 @@ static inline void packing_data_unlock(struct packing_data *pdata)
183183
}
184184

185185
struct object_entry *packlist_alloc(struct packing_data *pdata,
186-
const unsigned char *sha1,
187-
uint32_t index_pos);
186+
const struct object_id *oid);
188187

189188
struct object_entry *packlist_find(struct packing_data *pdata,
190-
const struct object_id *oid,
191-
uint32_t *index_pos);
189+
const struct object_id *oid);
192190

193191
static inline uint32_t pack_name_hash(const char *name)
194192
{

t/helper/test-read-cache.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
int cmd__read_cache(int argc, const char **argv)
66
{
7-
int i, cnt = 1, namelen;
7+
int i, cnt = 1;
88
const char *name = NULL;
99

1010
if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
11-
namelen = strlen(name);
1211
argc--;
1312
argv++;
1413
}
@@ -24,7 +23,7 @@ int cmd__read_cache(int argc, const char **argv)
2423

2524
refresh_index(&the_index, REFRESH_QUIET,
2625
NULL, NULL, NULL);
27-
pos = index_name_pos(&the_index, name, namelen);
26+
pos = index_name_pos(&the_index, name, strlen(name));
2827
if (pos < 0)
2928
die("%s not in index", name);
3029
printf("%s is%s up to date\n", name,

0 commit comments

Comments
 (0)