Tue, 06 May 2014 14:35:29 +0200
logger: removed unnecessary boundary checks and limited string parts so they always respect buffer lengths
ucx/logging.c | file | annotate | diff | comparison | revisions | |
ucx/logging.h | file | annotate | diff | comparison | revisions |
--- a/ucx/logging.c Tue May 06 14:22:08 2014 +0200 +++ b/ucx/logging.c Tue May 06 14:35:29 2014 +0200 @@ -75,6 +75,7 @@ if ((logger->mask & UCX_LOGGER_LEVEL) > 0) { text = (char*) ucx_map_int_get(logger->levels, level); n = strlen(text); + n = n > 256 ? 256 : n; memcpy(msg+k, text, n); k += n; msg[k++] = ' '; @@ -87,11 +88,7 @@ n = strlen(file); memcpy(msg+k, file, n); k += n; -#ifdef _WIN32 - k += _snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line); -#else - k += snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line); -#endif /* _WIN32 */ + k += sprintf(msg+k, ":%u ", line); } msg[k++] = '-'; msg[k++] = ' ';
--- a/ucx/logging.h Tue May 06 14:22:08 2014 +0200 +++ b/ucx/logging.h Tue May 06 14:35:29 2014 +0200 @@ -162,7 +162,8 @@ * <code>[LEVEL] [TIMESTAMP] [SOURCEFILE]:[LINENO] message</code> * * <b>Attention:</b> the message (including automatically generated information) - * <b>MUST NOT</b> exceed the size of 4 KB. + * is limited to 4096 characters. The level description is limited to + * 256 characters and the timestamp string is limited to 128 characters. * * @param logger the logger to use * @param level the level to log on