From fe011c1e1f1db2bb75d63deb15a3df7b57f0a8bf Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Wed, 14 Dec 2022 19:31:50 -0500 Subject: [PATCH] vasqLoggerCreate now sets *logger to NULL upon error; vasqLoggerCreate no longer calls vasqSetLoggerLevel; vasqSetLoggerLevel no longer emits a log message; changed version to 6.0.6 --- README.rst | 4 ++-- changelog | 4 ++++ include/vasq/config.h | 7 ------- include/vasq/definitions.h | 2 +- source/logger.c | 12 +++++------- source/safe_snprintf.c | 5 ++--- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/README.rst b/README.rst index a6bbdb8..3b5d891 100644 --- a/README.rst +++ b/README.rst @@ -3,8 +3,8 @@ Vanilla Squad ============= :Author: Daniel Walker -:Version: 6.0.5 -:Date: 2022-09-01 +:Version: 6.0.6 +:Date: 2022-12-14 Overview ======== diff --git a/changelog b/changelog index 895a2b3..e5b43ec 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +6.0.6: + - vasqLoggerCreate now sets *logger to NULL upon error. + - vasqSetLoggerLevel no longer emits a logging message. + 6.0.5: - make.mk now creates any necessary directories. - Added an include guard to make.mk. diff --git a/include/vasq/config.h b/include/vasq/config.h index 8f4766e..8f4e21e 100644 --- a/include/vasq/config.h +++ b/include/vasq/config.h @@ -40,13 +40,6 @@ #define VASQ_LL_PROCESS VASQ_LL_DEBUG #endif -/** - * @brief The log level which displays the setting of a logger's log level. - */ -#ifndef VASQ_LL_LEVEL_CHANGE -#define VASQ_LL_LEVEL_CHANGE VASQ_LL_DEBUG -#endif - /** * @brief Causes the PLACEHOLDER() macro to generate an error when used even if DEBUG or * VASQ_ALLOW_PLACEHOLDER are defined. diff --git a/include/vasq/definitions.h b/include/vasq/definitions.h index 9d57579..a68c3ae 100644 --- a/include/vasq/definitions.h +++ b/include/vasq/definitions.h @@ -9,7 +9,7 @@ /** * @brief Current version of the library. */ -#define VASQ_VERSION "6.0.5" +#define VASQ_VERSION "6.0.6" #ifndef NO_OP #define NO_OP ((void)0) diff --git a/source/logger.c b/source/logger.c index 15e8bbe..c1cbf82 100644 --- a/source/logger.c +++ b/source/logger.c @@ -247,6 +247,7 @@ vasqLoggerCreate(int fd, vasqLogLevel_t level, const char *format, const vasqLog default: free(*logger); + *logger = NULL; errno = local_errno; return VASQ_RET_DUP_FAIL; } @@ -268,7 +269,7 @@ vasqLoggerCreate(int fd, vasqLogLevel_t level, const char *format, const vasqLog (*logger)->processor = options->processor; (*logger)->user = options->user; (*logger)->hex_dump_info = !!(options->flags & VASQ_LOGGER_FLAG_HEX_DUMP_INFO); - vasqSetLoggerLevel(*logger, level); + (*logger)->level = level; if (options->flags & VASQ_LOGGER_FLAG_CLOEXEC) { int flags; @@ -277,6 +278,7 @@ vasqLoggerCreate(int fd, vasqLogLevel_t level, const char *format, const vasqLog if (flags == -1 || fcntl(new_fd, F_SETFD, flags | FD_CLOEXEC) == -1) { local_errno = errno; vasqLoggerFree(*logger); + *logger = NULL; errno = local_errno; return VASQ_RET_FCNTL_FAIL; } @@ -326,13 +328,9 @@ vasqLoggerLevel(const vasqLogger *logger) void vasqSetLoggerLevel(vasqLogger *logger, vasqLogLevel_t level) { - if (!logger) { - return; + if (logger) { + logger->level = level; } - - logger->level = level; - vasqLogStatement(logger, VASQ_LL_LEVEL_CHANGE, VASQ_CONTEXT_PARAMS, "Log level set to %s", - logLevelName(level)); } void diff --git a/source/safe_snprintf.c b/source/safe_snprintf.c index 655101e..1c66334 100644 --- a/source/safe_snprintf.c +++ b/source/safe_snprintf.c @@ -60,11 +60,11 @@ vasqSafeVsnprintf(char *buffer, size_t size, const char *format, va_list args) { char *start = buffer; - if (!buffer || size == 0 || !format) { + if (!buffer || size-- == 0 || !format) { // The -- is to leave space for the null terminator. return -1; } - for (size--; *format && size > 0; format++) { // The -- is to leave space for the null terminator. + for (; *format && size > 0; format++) { char c = *format; if (c == '%') { @@ -271,7 +271,6 @@ vasqSafeVsnprintf(char *buffer, size_t size, const char *format, va_list args) } done: - *buffer = '\0'; return buffer - start; }