-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Copy link
Description
#include <stddef.h>
int test(size_t nel, size_t elsz) {
size_t nbytes;
int overflow = __builtin_mul_overflow(nel, elsz, &nbytes);
int overflow2 = __builtin_add_overflow(nel, nbytes, &nbytes);
return overflow * overflow2;
}
> clang++ --analyze -Xclang -analyzer-output=text -std=c++20
clang++: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
<source>:6:19: warning: 2nd function call argument is an uninitialized value [core.CallAndMessage]
6 | int overflow2 = __builtin_add_overflow(nel, nbytes, &nbytes);
| ^ ~~~~~~
<source>:4:3: note: 'nbytes' declared without an initial value
4 | size_t nbytes;
| ^~~~~~~~~~~~~
<source>:5:18: note: Assuming overflow
5 | int overflow = __builtin_mul_overflow(nel, elsz, &nbytes);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:19: note: 2nd function call argument is an uninitialized value
6 | int overflow2 = __builtin_add_overflow(nel, nbytes, &nbytes);
| ^ ~~~~~~
1 warning generated.
Compiler returned: 0
Godbolt: https://godbolt.org/z/4q4Efcax8
Metadata
Metadata
Assignees
Type
Projects
Status
Done