From 4eb8db26ac9ddd679a32788e8d02ad1e8979e68d Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 19 Apr 2013 21:24:51 +0200 Subject: [PATCH] cleanup: convert set of strncat into a single printf Use single snprintf for better control of used bufsize, and also increased buffer to 128char to ensure all chars will always fit. --- lib/config/config.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/lib/config/config.c b/lib/config/config.c index d420d8332..8acb87d05 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -337,34 +337,22 @@ int config_def_get_path(char *buf, size_t buf_size, int id) static void _get_type_name(char *buf, size_t buf_size, cfg_def_type_t type) { - buf[0] = '\0'; - - if (type & CFG_TYPE_ARRAY) { - if (type & ~CFG_TYPE_ARRAY) - strncat(buf, " array with values of type:", buf_size); - else { - strncat(buf, " array", buf_size); - return; - } - } - - if (type & CFG_TYPE_SECTION) - strncat(buf, " section", buf_size); - if (type & CFG_TYPE_BOOL) - strncat(buf, " boolean", buf_size); - if (type & CFG_TYPE_INT) - strncat(buf, " integer", buf_size); - if (type & CFG_TYPE_FLOAT) - strncat(buf, " float", buf_size); - if (type & CFG_TYPE_STRING) - strncat(buf, " string", buf_size); + (void) dm_snprintf(buf, buf_size, "%s%s%s%s%s%s", + (type & CFG_TYPE_ARRAY) ? + ((type & ~CFG_TYPE_ARRAY) ? + " array with values of type:" : " array") : "", + (type & CFG_TYPE_SECTION) ? " section" : "", + (type & CFG_TYPE_BOOL) ? " boolean" : "", + (type & CFG_TYPE_INT) ? " integer" : "", + (type & CFG_TYPE_FLOAT) ? " float" : "", + (type & CFG_TYPE_STRING) ? " string" : ""); } static void _log_type_error(const char *path, cfg_def_type_t actual, cfg_def_type_t expected, int suppress_messages) { - static char actual_type_name[64]; - static char expected_type_name[64]; + static char actual_type_name[128]; + static char expected_type_name[128]; _get_type_name(actual_type_name, sizeof(actual_type_name), actual); _get_type_name(expected_type_name, sizeof(expected_type_name), expected);