On Thu, 2020-06-11 at 20:21 +0200, Björn Persson wrote: > Simo Sorce wrote: > > If you really want to avoid the warning instead of ignoring it, you > > should change the code this way: > > > > strncpy(t->name, name, MAX_TUBE_NAME_LEN-1); > > if (t->name[MAX_TUBE_NAME_LEN - 2] != '\0') { > > t->name[MAX_TUBE_NAME_LEN - 1] = '\0'; > > twarnx("truncating tube name"); > > } > > That code will warn wrongly about truncation when the name is exactly > MAX_TUBE_NAME_LEN - 1 bytes long. Yes but that is unavoidable unless you ant to add a check on the source length, which is entirely doable of course. > Nathanael, you could link to libbsd and use strlcpy if that's available > on all target platforms. Or, if you happen to be using Glib, use > g_strlcpy. Otherwise use Peter's snprintf solution, but DO NOT make the > mistake of passing the input as the format string! > > And choose a better language than C for your next project. I wish this was easier done than said :) Simo. -- Simo Sorce RHEL Crypto Team Red Hat, Inc _______________________________________________ devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx