siva-msft / libgit2

Other
0 stars 1 forks source link

Potential issue in src/indexer.c: Return Value Not Checked from Function Call #49

Open monocle-ai opened 4 years ago

monocle-ai commented 4 years ago

In this codebase, you often check the return value of the implicated function when calling it, but in this instance, it appears that you didn’t. Using a consistent return value checking and/or error handling approach can improve code robustness and readability.

1 instance of this defect were found in the following locations:


Instance 1 File : src/indexer.c Enclosing Function : git_indexer_commit Function : git_hash_final https://github.com/siva-msft/libgit2/blob/1e987525b3bd86fc29e7ff67d973861efd22faf7/src/indexer.c#L1137 Code extract:

    git_oid_fromraw(&file_hash, packfile_trailer);
    git_mwindow_close(&w);

    git_hash_final(&trailer_hash, &idx->trailer); <------ HERE
    if (git_oid_cmp(&file_hash, &trailer_hash)) {
        git_error_set(GIT_ERROR_INDEXER, "packfile trailer mismatch");

How can I fix it? Correct reference usage found in src/pack-objects.c at line 669. https://github.com/siva-msft/libgit2/blob/1e987525b3bd86fc29e7ff67d973861efd22faf7/src/pack-objects.c#L669 Code extract:

        pb->nr_remaining -= pb->nr_written;
    } while (pb->nr_remaining && i < pb->nr_objects);

    if ((error = git_hash_final(&entry_oid, &pb->ctx)) < 0) <------ HERE
        goto done;