Open jiridanek opened 1 year ago
I'm seeing these warnings also, but they appear to be false-positives. In every case the input string is null terminated and won't exceed the max passed in. What's funny is that the compiler is "smart" enough to determine the array size used by the caller, but not smart enough to determine that the code properly null-terminates the input string and avoid the warning.
Or just as likely I'm not smart enough to see the actual error path the compiler is concerned about.
Should the vanflow code be changed to use plain old strlen() and assert if the return value is > MAX_STRING_VALUE? Or disable the warning flag?
@ted-ross your call.
I'm seeing these warnings also, but they appear to be false-positives. In every case the input string is null terminated and won't exceed the max passed in. What's funny is that the compiler is "smart" enough to determine the array size used by the caller, but not smart enough to determine that the code properly null-terminates the input string and avoid the warning.
Or just as likely I'm not smart enough to see the actual error path the compiler is concerned about.
Should the vanflow code be changed to use plain old strlen() and assert if the return value is > MAX_STRING_VALUE? Or disable the warning flag?
@ted-ross your call.
I think I sort of get the point. If you inline the calls in one of the places that emit the warning, you get
#define MAX_STRING_VALUE 300
char code_str[32];
snprintf(code_str, 32, "%d", status_code);
struct vflow_work_t *work = ...;
// [...]
work->value.string_val = !!code_str ? strndup(code_str, strnlen(code_str, MAX_STRING_VALUE)) : 0;
So, the compiler wonders: "I know code_str won't be longer than 32 characters, so why I am getting that 300 as a length bound? Lets throw a warning."
https://github.com/skupperproject/skupper-router/actions/runs/4511575739/jobs/7943886750#step:23:423
https://github.com/skupperproject/skupper-router/actions/runs/4511575739/jobs/7943886750#step:23:448