Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static analysis (Infer) complains #462

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yanovich
Copy link

Infer выдаёт четыре замечания к коду, все несущественные, три точно ложно положительные. На случай, если будет желание включить статический анализ в тесты, я все четыре починил.

$ infer run --compilation-database build/compile_commands.json
Capturing using compilation database...
Starting translating 53 files
53/53 [##############################################################################] 100% 5.34s

Found 53 source files to analyze in /home/s/src/crypto/engine/infer-out
Skipped large procedure (__infer_globals_initializer_grasshopper_pil_enc128, size:65543) in pulse.
Skipped large procedure (__infer_globals_initializer_grasshopper_pil_dec128, size:65543) in pulse.
Skipped large procedure (__infer_globals_initializer_grasshopper_l_dec128, size:65543) in pulse.
1161/1161 [##########################################################################] 100% 15.5s

gost12sum.c:253: error: Dead Store
  The value written to `&ptr` is never used. 
  251. {
  252.     int i, len;
  253.     char *ptr = filename;
           ^
  254.     char *spacepos = NULL;
  255. 

test_digest.c:662: error: Dead Store
  The value written to `&p` is never used. 
  660.     if (t->truncate) {
  661.         outsize = t->truncate;
  662. 	*p++ = OSSL_PARAM_construct_size_t("size", &outsize);
         ^
  663.     }
  664.     else

test_tls.c:172: error: Uninitialized Value
  `_.cert` is read without initialization. 
  170. 
  171.     T(sctx = SSL_CTX_new(TLS_server_method()));
  172.     T(SSL_CTX_use_certificate(sctx, ck.cert));
           ^
  173.     T(SSL_CTX_use_PrivateKey(sctx, ck.pkey));
  174.     T(SSL_CTX_check_private_key(sctx));

test_tls.c:173: error: Uninitialized Value
  `_.pkey` is read without initialization. 
  171.     T(sctx = SSL_CTX_new(TLS_server_method()));
  172.     T(SSL_CTX_use_certificate(sctx, ck.cert));
  173.     T(SSL_CTX_use_PrivateKey(sctx, ck.pkey));
           ^
  174.     T(SSL_CTX_check_private_key(sctx));
  175. 


Found 4 issues
                      Issue Type(ISSUED_TYPE_ID): #
  Uninitialized Value(PULSE_UNINITIALIZED_VALUE): 2
                          Dead Store(DEAD_STORE): 2

yanovich added 3 commits July 30, 2024 14:33
Infer complains:
```
test_tls.c:172: error: Uninitialized Value
  `_.cert` is read without initialization.
  170.
  171.     T(sctx = SSL_CTX_new(TLS_server_method()));
  172.     T(SSL_CTX_use_certificate(sctx, ck.cert));
           ^
  173.     T(SSL_CTX_use_PrivateKey(sctx, ck.pkey));
  174.     T(SSL_CTX_check_private_key(sctx));

test_tls.c:173: error: Uninitialized Value
  `_.pkey` is read without initialization.
  171.     T(sctx = SSL_CTX_new(TLS_server_method()));
  172.     T(SSL_CTX_use_certificate(sctx, ck.cert));
  173.     T(SSL_CTX_use_PrivateKey(sctx, ck.pkey));
           ^
  174.     T(SSL_CTX_check_private_key(sctx));
  175.
```

Altough the complain is false positive, fixing it will allow for future
use of the tools in automated tests.
Infer complains:
```
test_digest.c:662: error: Dead Store
  The value written to `&p` is never used.
  660.     if (t->truncate) {
  661.         outsize = t->truncate;
  662. 	params[p++] = OSSL_PARAM_construct_size_t("size", &outsize);
               ^
  663.     }
  664.     else
```

Altough the complain is false positive, fixing it will allow for future
use of the tools in automated tests.
Infer correctly complains that `ptr` is initialized twice before first
use. The fix is trivial.
```
gost12sum.c:253: error: Dead Store
  The value written to `&ptr` is never used.
  251. {
  252.     int i, len;
  253.     char *ptr = filename;
           ^
  254.     char *spacepos = NULL;
  255.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant