On Sat, Jan 15, 2022 at 01:50:19PM -0700, Martin Sebor wrote:
Having said that, checking and handling possible truncation before
calling snprintf() is doing double the work. I would suggest to get
rid of the check and instead handle the truncation after it happens.
This is both simpler and faster, and avoids the warning:
if (snprintf (*sockpath, UNIX_PATH_MAX,
"%s/%s", g->sockdir, filename) < UNIX_PATH_MAX)
return 0;
error (g, _("socket path too long: %s/%s"), g->sockdir, filename);
return -1;
}
Oh that's a good idea, thanks!
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW