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 |
1.1 --- a/ucx/logging.c Tue May 06 14:22:08 2014 +0200 1.2 +++ b/ucx/logging.c Tue May 06 14:35:29 2014 +0200 1.3 @@ -75,6 +75,7 @@ 1.4 if ((logger->mask & UCX_LOGGER_LEVEL) > 0) { 1.5 text = (char*) ucx_map_int_get(logger->levels, level); 1.6 n = strlen(text); 1.7 + n = n > 256 ? 256 : n; 1.8 memcpy(msg+k, text, n); 1.9 k += n; 1.10 msg[k++] = ' '; 1.11 @@ -87,11 +88,7 @@ 1.12 n = strlen(file); 1.13 memcpy(msg+k, file, n); 1.14 k += n; 1.15 -#ifdef _WIN32 1.16 - k += _snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line); 1.17 -#else 1.18 - k += snprintf(msg+k, UCX_LOGGER_MSGMAX-k, ":%d ", line); 1.19 -#endif /* _WIN32 */ 1.20 + k += sprintf(msg+k, ":%u ", line); 1.21 } 1.22 1.23 msg[k++] = '-'; msg[k++] = ' ';
2.1 --- a/ucx/logging.h Tue May 06 14:22:08 2014 +0200 2.2 +++ b/ucx/logging.h Tue May 06 14:35:29 2014 +0200 2.3 @@ -162,7 +162,8 @@ 2.4 * <code>[LEVEL] [TIMESTAMP] [SOURCEFILE]:[LINENO] message</code> 2.5 * 2.6 * <b>Attention:</b> the message (including automatically generated information) 2.7 - * <b>MUST NOT</b> exceed the size of 4 KB. 2.8 + * is limited to 4096 characters. The level description is limited to 2.9 + * 256 characters and the timestamp string is limited to 128 characters. 2.10 * 2.11 * @param logger the logger to use 2.12 * @param level the level to log on