cfengine/core — pull request #619 by lpefferkorn (2013-05-04 23:18:45+00:00)
Title: Snprintf() improvments

Hello,

I have found some improvements over uses of snprintf(), for example:

snprintf(name, CF_MAXVARSIZE - 1, "ipv4[interface_name]");

Here - 1 is useless because snprintf() already takes care of '\0', printf(3):

The functions snprintf() and vsnprintf() write at most size bytes (including the terminating null byte ('\0')) to str.

Now we have

snprintf(name, CF_MAXVARSIZE, "ipv4[interface_name]");

But I find annoying to scroll to track the type of 'name', so I suggest using sizeof():

snprintf(name, sizeof(name), "ipv4[interface_name]");

This way, we don't have to track the type of the buffer, and if it change, its size will automatically follow.

I applied these modifications on libpromises/unix.c to have a preview. Does these changes may also be applied more generally ?