opengit
opengit copied to clipboard
Clang Static Analyzer has 31 warnings
$ pkg install llvm10
$ scan-build10 --status-bugs make -s
scan-build: Using '/usr/local/llvm10/bin/clang-10' for static analysis
===> lib (all)
index.c:124:2: warning: Value stored to 'dircentry' is never read
dircentry = (struct dircentry *)((char *)indexmap + *offset);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
ini.c:52:18: warning: Value stored to 'current_section' during its initialization is never read
struct section *current_section = sections;
^~~~~~~~~~~~~~~ ~~~~~~~~
ini.c:96:27: warning: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'current_section')
current_section->next = new_section;
~~~~~~~~~~~~~~~ ^
2 warnings generated.
loose.c:119:8: warning: Assigned value is garbage or undefined
*type = loosearg.type;
^ ~~~~~~~~~~~~~
1 warning generated.
pack.c:423:28: warning: Assigned value is garbage or undefined
objectinfo->deflated_size = delta_object.deflated_size;
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
pack.c:602:20: warning: 1st function call argument is an uninitialized value
objectinfo->crc = crc32(objectinfo->crc, &c, 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
protocol.c:212:22: warning: Result of 'realloc' is converted to a pointer of type 'struct ref', which is incompatible with sizeof operand type 'struct smart_head'
smart_head->refs = realloc(smart_head->refs, sizeof(struct smart_head) * (count+1));
^~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
index.c:124:2: warning: Value stored to 'dircentry' is never read
dircentry = (struct dircentry *)((char *)indexmap + *offset);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
ini.c:52:18: warning: Value stored to 'current_section' during its initialization is never read
struct section *current_section = sections;
^~~~~~~~~~~~~~~ ~~~~~~~~
ini.c:96:27: warning: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'current_section')
current_section->next = new_section;
~~~~~~~~~~~~~~~ ^
2 warnings generated.
loose.c:119:8: warning: Assigned value is garbage or undefined
*type = loosearg.type;
^ ~~~~~~~~~~~~~
1 warning generated.
pack.c:423:28: warning: Assigned value is garbage or undefined
objectinfo->deflated_size = delta_object.deflated_size;
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
pack.c:602:20: warning: 1st function call argument is an uninitialized value
objectinfo->crc = crc32(objectinfo->crc, &c, 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
protocol.c:212:22: warning: Result of 'realloc' is converted to a pointer of type 'struct ref', which is incompatible with sizeof operand type 'struct smart_head'
smart_head->refs = realloc(smart_head->refs, sizeof(struct smart_head) * (count+1));
^~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
index.c:124:2: warning: Value stored to 'dircentry' is never read
dircentry = (struct dircentry *)((char *)indexmap + *offset);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
ini.c:52:18: warning: Value stored to 'current_section' during its initialization is never read
struct section *current_section = sections;
^~~~~~~~~~~~~~~ ~~~~~~~~
ini.c:96:27: warning: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'current_section')
current_section->next = new_section;
~~~~~~~~~~~~~~~ ^
2 warnings generated.
loose.c:119:8: warning: Assigned value is garbage or undefined
*type = loosearg.type;
^ ~~~~~~~~~~~~~
1 warning generated.
pack.c:423:28: warning: Assigned value is garbage or undefined
objectinfo->deflated_size = delta_object.deflated_size;
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
pack.c:602:20: warning: 1st function call argument is an uninitialized value
objectinfo->crc = crc32(objectinfo->crc, &c, 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
protocol.c:212:22: warning: Result of 'realloc' is converted to a pointer of type 'struct ref', which is incompatible with sizeof operand type 'struct smart_head'
smart_head->refs = realloc(smart_head->refs, sizeof(struct smart_head) * (count+1));
^~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
===> src (all)
init.c:204:4: warning: Value stored to 'reinit' is never read
reinit = 1;
^ ~
1 warning generated.
hash-object.c:171:34: warning: The third argument allows to potentially copy more bytes than it should. Replace with the value sizeof(<destination buffer>) or lower
strlcat(objpath+3, checksum+2, PATH_MAX);
^~~~~~~~
/usr/include/sys/syslimits.h:68:20: note: expanded from macro 'PATH_MAX'
#define PATH_MAX 1024 /* max bytes in pathname */
^~~~
hash-object.c:205:2: warning: Value stored to 'argc' is never read
argc = argc - q;
^ ~~~~~~~~
2 warnings generated.
update-index.c:110:2: warning: Value stored to 'argc' is never read
argc = argc - q;
^ ~~~~~~~~
update-index.c:111:2: warning: Value stored to 'argv' is never read
argv = argv + q;
^ ~~~~~~~~
2 warnings generated.
log.c:234:2: warning: Value stored to 'argc' is never read
argc = argc - q;
^ ~~~~~~~~
log.c:235:2: warning: Value stored to 'argv' is never read
argv = argv + q;
^ ~~~~~~~~
2 warnings generated.
clone.c:150:2: warning: Value stored to 'sections' is never read
sections = malloc(sizeof(struct section) * 3);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clone.c:152:12: warning: Potential leak of memory pointed to by 'sections'
core.type = CORE;
~~~~~~~~~~^~~~~~
clone.c:296:11: warning: Access to field 'run_service' results in a dereference of a null pointer (loaded from variable 'chandler')
stream = chandler->run_service(chandler, "git-upload-pack");
^~~~~~~~~~~~~~~~~~~~~
clone.c:355:2: warning: Value stored to 'ret' is never read
ret = proto_parse_response(response, smart_head);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clone.c:366:2: warning: Value stored to 'offset' is never read
offset = pack_get_object_meta(packfd, offset, &packfileinfo, index_entry,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clone.c:463:2: warning: Value stored to 'argc' is never read
argc = argc - q;
^ ~~~~~~~~
clone.c:466:8: warning: Although the value stored to 'repopath' is used in the enclosing expression, the value is never actually read from 'repopath'
uri = repopath = argv[1];
^ ~~~~~~~
clone.c:568:2: warning: 1st function call argument is an uninitialized value
free(treeleaf.subtree); /* Allocated by index_generate_treedata */
^~~~~~~~~~~~~~~~~~~~~~
8 warnings generated.
index-pack.c:90:2: warning: Value stored to 'argc' is never read
argc = argc - q;
^ ~~~~~~~~
index-pack.c:117:2: warning: Value stored to 'offset' is never read
offset = pack_get_object_meta(packfd, offset, &packfileinfo, index_entry, &packctx, &idxctx);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
===> src/tests (all)
scan-build: 31 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-...' to examine bug reports.
Exit 1
Reducing this to a lot fewer warnings:
$ scan-build15 --status-bugs make -s -j 5
scan-build: Using '/usr/local/llvm15/bin/clang-15' for static analysis
===> lib (all)
protocol.c:212:22: warning: Result of 'realloc' is converted to a pointer of type 'struct ref', which is incompatible with sizeof operand type 'struct smart_head' [unix.MallocSizeof]
smart_head->refs = realloc(smart_head->refs, sizeof(struct smart_head) * (count+1));
^~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
protocol.c:212:22: warning: Result of 'realloc' is converted to a pointer of type 'struct ref', which is incompatible with sizeof operand type 'struct smart_head' [unix.MallocSizeof]
smart_head->refs = realloc(smart_head->refs, sizeof(struct smart_head) * (count+1));
^~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
===> src (all)
===> src/tests (all)
index-pack.c:90:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores]
argc = argc - q;
^ ~~~~~~~~
1 warning generated.
update-index.c:110:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores]
argc = argc - q;
^ ~~~~~~~~
update-index.c:111:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores]
argv = argv + q;
^ ~~~~~~~~
2 warnings generated.
hash-object.c:205:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores]
argc = argc - q;
^ ~~~~~~~~
1 warning generated.
log.c:234:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores]
argc = argc - q;
^ ~~~~~~~~
log.c:235:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores]
argv = argv + q;
^ ~~~~~~~~
2 warnings generated.
clone.c:473:2: warning: Value stored to 'argc' is never read [deadcode.DeadStores]
argc = argc - q;
^ ~~~~~~~~
1 warning generated.
scan-build: Analysis run complete.
scan-build: 8 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2023-12-28-155650-19121-1' to examine bug reports.