[Nut-upsdev] common/common.c snprintf warning
Jim Klimov
jimklimov+nut at gmail.com
Mon Mar 31 15:10:37 BST 2025
Thanks, I'll post a PR for fixes. Somehow I missed that NetBSD is not a
regular runner of NUT CI farm, gotta address that too - great to have more
points of view on code quality, especially when those extra eyes are not
blind and quiet :)
It seems bumping all those buffers to [NUT_PATH_MAX+1]` (for the NUL ending
char) helps, and seems a reasonable thing to do safely.
FWIW, the truncation problem showed up with default ./ci_build.sh run which
found GCC (7), but the char subscripts only with CLANG (13), on my dormant
NetBSD 9.2 VM.
Jim
On Mon, Mar 31, 2025 at 3:06 PM Greg Troxel via Nut-upsdev <
nut-upsdev at alioth-lists.debian.net> wrote:
> common.c:4087:59: warning: '__builtin_snprintf' output may be truncated
> before the last format character [-Wformat-truncation=]
>
> snprintf(current_test_path,
> sizeof(current_test_path), "%s/%s", dirname, dirp->d_name);
>
>
> I get why there is the warning, why the code is defensive, and why it's
> unlikely to be an issue. I don't know what the right approach is;
> perhaps checking dirname and erroring out if it's > than the sizeof-64,
> or something like that?
>
> (not seeing this needs fixing, but I got only 4 warnings building)
>
> _______________________________________________
> Nut-upsdev mailing list
> Nut-upsdev at alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/nut-upsdev/attachments/20250331/f5e82e73/attachment.htm>
More information about the Nut-upsdev
mailing list