From 98ffbef6ea7a0944fd4aca27e3343b8ac5bc12f0 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 11 Apr 2011 22:36:20 +0300 Subject: [PATCH 1/1] Fix settings error reporting mechanism --- projects/stargazer/settings_impl.cpp | 4 ++-- stglibs/dotconfpp.lib/dotconfpp.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index e0eb4639..d5fb2dad 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -235,9 +235,9 @@ return 0; //----------------------------------------------------------------------------- void SETTINGS_IMPL::ErrorCallback(void * data, const char * buf) { - printfd(__FILE__, buf); + printfd(__FILE__, "SETTINGS_IMPL::ErrorCallback() - %s\n", buf); SETTINGS_IMPL * settings = static_cast(data); - settings->logger(buf); + settings->logger("%s", buf); } //----------------------------------------------------------------------------- int SETTINGS_IMPL::ReadSettings() diff --git a/stglibs/dotconfpp.lib/dotconfpp.cpp b/stglibs/dotconfpp.lib/dotconfpp.cpp index ceca3ab2..8ac25440 100644 --- a/stglibs/dotconfpp.lib/dotconfpp.cpp +++ b/stglibs/dotconfpp.lib/dotconfpp.cpp @@ -339,7 +339,7 @@ int DOTCONFDocument::setContent(const char * _fileName) char realpathBuf[PATH_MAX]; if(realpath(_fileName, realpathBuf) == NULL){ - error(0, NULL, "realpath(%s) failed: %s", _fileName, strerror(errno)); + error(0, _fileName, "realpath('%s') failed: %s", _fileName, strerror(errno)); return -1; } @@ -509,13 +509,17 @@ void DOTCONFDocument::error(int lineNum, const char * fileName, const char * fmt va_list args; va_start(args, fmt); - size_t len = (lineNum!=0?strlen(fileName):0) + strlen(fmt) + 50; + char msg[256]; + + vsnprintf(msg, 256, fmt, args); + + size_t len = (lineNum!=0?strlen(fileName):0) + strlen(msg) + 50; char * buf = (char*)mempool->alloc(len); if(lineNum) - (void) snprintf(buf, len, "DOTCONF++: file '%s', line %d: %s\n", fileName, lineNum, fmt); + (void) snprintf(buf, len, "DOTCONF++: file '%s', line %d: %s\n", fileName, lineNum, msg); else - (void) snprintf(buf, len, "DOTCONF++: %s\n", fmt); + (void) snprintf(buf, len, "DOTCONF++: file '%s': %s\n", fileName, msg); if (errorCallback) { errorCallback(errorCallbackData, buf); -- 2.44.2