Fix warnings in unit test BSP by pcolberg · Pull Request #204 · intel/fpga-runtime-for-opencl (original) (raw)
GCC 11 correctly points out that there is no point in limiting strnlen() to a size that is greater than the length of the string literal argument.
test/fake_bsp/fakegoodbsp.cpp:47:26: warning: 'size_t strnlen(const char*, size_t)' specified bound 1204 exceeds source size 16 [-Wstringop-overread]
47 | size_t Xlen = strnlen(X, MAX_NAME_SIZE) + 1;
| ~~~~~~~^~~~~~~~~~~~~~~~~~
strnlen() is commonly used with an input buffer that is possibly not null-terminated, i.e., contains a truncated string. strnlen() is also useful to set an upper bound on the length to consume, e.g., to avoid a denial of service. Neither of these use cases apply here.
MAX_NAME_SIZE was previously introduced in acl.h to address Klocwork issues relating to missing null termination of strings. The chosen 1204 is a typo of 1024, but even then, it should be 1023 such that a buffer with the trailing null byte occupies 1023 + 1 = 1024 bytes.
Signed-off-by: Peter Colberg peter.colberg@intel.com