Merge branch 'jk/misc-uninitialized-fixes'
authorJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:30 +0000 (13:19 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:30 +0000 (13:19 +0900)
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

builtin/am.c
builtin/pack-objects.c
bulk-checkin.c
diff-delta.c
pack-bitmap-write.c
pack-bitmap.c
pack-objects.c
pack-objects.h
t/helper/test-read-cache.c
index 1aea657a7f0b56345e1b2d5f8f32df439e278e80..ee7305eaa663ae434b44ed567661b5fd81dbe817 100644 (file)
@@ -1272,7 +1272,9 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
        buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());
 
        ident_line = find_commit_header(buffer, "author", &ident_len);
-
+       if (!ident_line)
+               die(_("missing author line in commit %s"),
+                     oid_to_hex(&commit->object.oid));
        if (split_ident_line(&id, ident_line, ident_len) < 0)
                die(_("invalid ident line: %.*s"), (int)ident_len, ident_line);
 
index c8f51bc65c3621d945ad4a11d9c08929a5250862..5876583220c7d15ace8f7d4fbc7a5c4cef7a8d3b 100644 (file)
@@ -610,12 +610,12 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
                       void *cb_data)
 {
        struct object_id peeled;
-       struct object_entry *entry = packlist_find(&to_pack, oid, NULL);
+       struct object_entry *entry = packlist_find(&to_pack, oid);
 
        if (entry)
                entry->tagged = 1;
        if (!peel_ref(path, &peeled)) {
-               entry = packlist_find(&to_pack, &peeled, NULL);
+               entry = packlist_find(&to_pack, &peeled);
                if (entry)
                        entry->tagged = 1;
        }
@@ -996,12 +996,11 @@ static int no_try_delta(const char *path)
  * few lines later when we want to add the new entry.
  */
 static int have_duplicate_entry(const struct object_id *oid,
-                               int exclude,
-                               uint32_t *index_pos)
+                               int exclude)
 {
        struct object_entry *entry;
 
-       entry = packlist_find(&to_pack, oid, index_pos);
+       entry = packlist_find(&to_pack, oid);
        if (!entry)
                return 0;
 
@@ -1141,13 +1140,12 @@ static void create_object_entry(const struct object_id *oid,
                                uint32_t hash,
                                int exclude,
                                int no_try_delta,
-                               uint32_t index_pos,
                                struct packed_git *found_pack,
                                off_t found_offset)
 {
        struct object_entry *entry;
 
-       entry = packlist_alloc(&to_pack, oid->hash, index_pos);
+       entry = packlist_alloc(&to_pack, oid);
        entry->hash = hash;
        oe_set_type(entry, type);
        if (exclude)
@@ -1171,11 +1169,10 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
 {
        struct packed_git *found_pack = NULL;
        off_t found_offset = 0;
-       uint32_t index_pos;
 
        display_progress(progress_state, ++nr_seen);
 
-       if (have_duplicate_entry(oid, exclude, &index_pos))
+       if (have_duplicate_entry(oid, exclude))
                return 0;
 
        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,
 
        create_object_entry(oid, type, pack_name_hash(name),
                            exclude, name && no_try_delta(name),
-                           index_pos, found_pack, found_offset);
+                           found_pack, found_offset);
        return 1;
 }
 
@@ -1199,17 +1196,15 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
                                        int flags, uint32_t name_hash,
                                        struct packed_git *pack, off_t offset)
 {
-       uint32_t index_pos;
-
        display_progress(progress_state, ++nr_seen);
 
-       if (have_duplicate_entry(oid, 0, &index_pos))
+       if (have_duplicate_entry(oid, 0))
                return 0;
 
        if (!want_object_in_pack(oid, 0, &pack, &offset))
                return 0;
 
-       create_object_entry(oid, type, name_hash, 0, 0, index_pos, pack, offset);
+       create_object_entry(oid, type, name_hash, 0, 0, pack, offset);
        return 1;
 }
 
@@ -1507,7 +1502,7 @@ static int can_reuse_delta(const unsigned char *base_sha1,
         * First see if we're already sending the base (or it's explicitly in
         * our "excluded" list).
         */
-       base = packlist_find(&to_pack, &base_oid, NULL);
+       base = packlist_find(&to_pack, &base_oid);
        if (base) {
                if (!in_same_island(&delta->idx.oid, &base->idx.oid))
                        return 0;
@@ -2568,7 +2563,7 @@ static void add_tag_chain(const struct object_id *oid)
         * it was included via bitmaps, we would not have parsed it
         * previously).
         */
-       if (packlist_find(&to_pack, oid, NULL))
+       if (packlist_find(&to_pack, oid))
                return;
 
        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,
 
        if (starts_with(path, "refs/tags/") && /* is a tag? */
            !peel_ref(path, &peeled)    && /* peelable? */
-           packlist_find(&to_pack, &peeled, NULL))      /* object packed? */
+           packlist_find(&to_pack, &peeled))      /* object packed? */
                add_tag_chain(oid);
        return 0;
 }
@@ -2788,7 +2783,7 @@ static void show_object(struct object *obj, const char *name, void *data)
                for (p = strchr(name, '/'); p; p = strchr(p + 1, '/'))
                        depth++;
 
-               ent = packlist_find(&to_pack, &obj->oid, NULL);
+               ent = packlist_find(&to_pack, &obj->oid);
                if (ent && depth > oe_tree_depth(&to_pack, ent))
                        oe_set_tree_depth(&to_pack, ent, depth);
        }
@@ -3019,7 +3014,7 @@ static void loosen_unused_packed_objects(void)
 
                for (i = 0; i < p->num_objects; i++) {
                        nth_packed_object_oid(&oid, p, i);
-                       if (!packlist_find(&to_pack, &oid, NULL) &&
+                       if (!packlist_find(&to_pack, &oid) &&
                            !has_sha1_pack_kept_or_nonlocal(&oid) &&
                            !loosened_object_can_be_discarded(&oid, p->mtime))
                                if (force_object_loose(&oid, p->mtime))
index 39ee7d6107c15f3e5e439992bea8a8f3413aae05..583aacb9e36bded9047d5f18219637ba1613a612 100644 (file)
@@ -197,7 +197,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
        git_hash_ctx ctx;
        unsigned char obuf[16384];
        unsigned header_len;
-       struct hashfile_checkpoint checkpoint;
+       struct hashfile_checkpoint checkpoint = {0};
        struct pack_idx_entry *idx = NULL;
 
        seekback = lseek(fd, 0, SEEK_CUR);
index e49643353bf56807b3d4ac4011784b5d8dd6f7a4..77fea08dfb04d3a6ec12e11dbd321084d9028722 100644 (file)
@@ -326,6 +326,8 @@ create_delta(const struct delta_index *index,
        const unsigned char *ref_data, *ref_top, *data, *top;
        unsigned char *out;
 
+       *delta_size = 0;
+
        if (!trg_buf || !trg_size)
                return NULL;
 
index fa78a460c9aa5dd3b0c89960a23b7a410fca83d9..a7a4964b50d1936be0d769724c1b0b5fa5420672 100644 (file)
@@ -144,7 +144,7 @@ static inline void reset_all_seen(void)
 
 static uint32_t find_object_pos(const struct object_id *oid)
 {
-       struct object_entry *entry = packlist_find(writer.to_pack, oid, NULL);
+       struct object_entry *entry = packlist_find(writer.to_pack, oid);
 
        if (!entry) {
                die("Failed to write bitmap index. Packfile doesn't have full closure "
index 30842e1e742e112ed920ebf8a51f54e9c139c13c..e07c798879b7277797b093a3eac6b4aece9ee4d2 100644 (file)
@@ -1061,7 +1061,7 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git,
 
                entry = &bitmap_git->pack->revindex[i];
                nth_packed_object_oid(&oid, bitmap_git->pack, entry->nr);
-               oe = packlist_find(mapping, &oid, NULL);
+               oe = packlist_find(mapping, &oid);
 
                if (oe)
                        reposition[i] = oe_in_pack_pos(mapping, oe) + 1;
index 52560293b6268b792803e5b2c89b3a96840c0bf9..c6250d77f4dec714de1073ccc0260309c24f6312 100644 (file)
@@ -68,8 +68,7 @@ static void rehash_objects(struct packing_data *pdata)
 }
 
 struct object_entry *packlist_find(struct packing_data *pdata,
-                                  const struct object_id *oid,
-                                  uint32_t *index_pos)
+                                  const struct object_id *oid)
 {
        uint32_t i;
        int found;
@@ -79,9 +78,6 @@ struct object_entry *packlist_find(struct packing_data *pdata,
 
        i = locate_object_entry_hash(pdata, oid, &found);
 
-       if (index_pos)
-               *index_pos = i;
-
        if (!found)
                return NULL;
 
@@ -153,8 +149,7 @@ void prepare_packing_data(struct repository *r, struct packing_data *pdata)
 }
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
-                                   const unsigned char *sha1,
-                                   uint32_t index_pos)
+                                   const struct object_id *oid)
 {
        struct object_entry *new_entry;
 
@@ -177,12 +172,19 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
        new_entry = pdata->objects + pdata->nr_objects++;
 
        memset(new_entry, 0, sizeof(*new_entry));
-       hashcpy(new_entry->idx.oid.hash, sha1);
+       oidcpy(&new_entry->idx.oid, oid);
 
        if (pdata->index_size * 3 <= pdata->nr_objects * 4)
                rehash_objects(pdata);
-       else
-               pdata->index[index_pos] = pdata->nr_objects;
+       else {
+               int found;
+               uint32_t pos = locate_object_entry_hash(pdata,
+                                                       &new_entry->idx.oid,
+                                                       &found);
+               if (found)
+                       BUG("duplicate object inserted into hash");
+               pdata->index[pos] = pdata->nr_objects;
+       }
 
        if (pdata->in_pack)
                pdata->in_pack[pdata->nr_objects - 1] = NULL;
index 857d43850b6258696d506a23cabd1adc187d8159..6fe6ae5ee86ccaa6ffe619ab5c4280a76841f340 100644 (file)
@@ -183,12 +183,10 @@ static inline void packing_data_unlock(struct packing_data *pdata)
 }
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
-                                   const unsigned char *sha1,
-                                   uint32_t index_pos);
+                                   const struct object_id *oid);
 
 struct object_entry *packlist_find(struct packing_data *pdata,
-                                  const struct object_id *oid,
-                                  uint32_t *index_pos);
+                                  const struct object_id *oid);
 
 static inline uint32_t pack_name_hash(const char *name)
 {
index 7e79b555de8059fae8f47ae1d2382d14b830a4d1..244977a29bdfda7839c62b97e7f1ba591b02abff 100644 (file)
@@ -4,11 +4,10 @@
 
 int cmd__read_cache(int argc, const char **argv)
 {
-       int i, cnt = 1, namelen;
+       int i, cnt = 1;
        const char *name = NULL;
 
        if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
-               namelen = strlen(name);
                argc--;
                argv++;
        }
@@ -24,7 +23,7 @@ int cmd__read_cache(int argc, const char **argv)
 
                        refresh_index(&the_index, REFRESH_QUIET,
                                      NULL, NULL, NULL);
-                       pos = index_name_pos(&the_index, name, namelen);
+                       pos = index_name_pos(&the_index, name, strlen(name));
                        if (pos < 0)
                                die("%s not in index", name);
                        printf("%s is%s up to date\n", name,