HomeClusterLabs Projects

Refactor: libcrmcommon: Don't use FILENAME_MAX for array size

Description

Refactor: libcrmcommon: Don't use FILENAME_MAX for array size

The glibc manual warns against this and notes that glibc doesn't enforce
PATH_MAX:
https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html

snprintf() and other functions that operate on a fixed-size buffer are
thus not feasible. (We could iterate over all parameter names, call
strlen() on each, and use the max-length name to compute a buffer size;
then allocate the buffer once and use snprintf(). However, that seems
like premature optimization that hurts readability for little gain.)

Using a GString simplifies the function significantly and likely uses
less overhead than crm_strdup_printf() since we can easily reuse the
buffer. We don't even have to use string formatting.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>

Details

Provenance
nrwahl2Authored on Sat, Mar 1, 4:48 PM
Parents
rP62ebd3e82db3: Refactor: libstonithd: Don't use FILENAME_MAX for array size
Branches
Unknown
Tags
Unknown