On Tue, Jul 17, 2018 at 01:09:57PM +0200, Andrea Bolognani wrote: > With the recent update in Fedora Rawhide, MinGW has > started freaking out about our use of strncpy(): > > In function 'virStrncpy', > inlined from 'virStrcpy' at ../../src/util/virstring.c:811:12: > ../../src/util/virstring.c:789:11: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] > ret = strncpy(dest, src, n); > ^~~~~~~~~~~~~~~~~~~~~ > ../../src/util/virstring.c: In function 'virStrcpy': > ../../src/util/virstring.c:811:12: note: length computed here > return virStrncpy(dest, src, strlen(src), destbytes); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The GCC docs for this warning suggest that we should use memcpy() instead of strncpy() when we know that we might truncate. This looks simple enough given that we know the target buffer size and the input size. The caveat is whether any callers are providing a value of 'n' to virStrncpy() that exceeds the size of the 'src', and are thus relying on early termination when reaching '\0' ? > Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> > --- > Kind of a big hammer, so if you have a better approach in mind > please don't hesitate to step forward. The smaller hammer is to just use pragma to turn off the warning around that single piece of code. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list