sal/osl/all/log.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
New commits: commit 04eb4bf20642930ab9614101af83186afa87d029 Author: Thorsten Behrens <thorsten.behr...@cib.de> Date: Wed Jan 17 21:13:16 2018 +0100 sal: use snprintf for sal log Change-Id: I0fe7029991052a59ee56cef1897cf6688bfa24b9 Reviewed-on: https://gerrit.libreoffice.org/48083 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index 211fcb6fb9bd..66722662af80 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -101,6 +101,8 @@ char const * getEnvironmentVariable(const char* env) { } #ifdef WNT +# define INI_STRINGBUF_SIZE 1024 + bool getValueFromLoggingIniFile(const char* key, char* value) { char buffer[MAX_PATH]; GetModuleFileName(NULL, buffer, MAX_PATH); @@ -126,7 +128,7 @@ bool getValueFromLoggingIniFile(const char* key, char* value) { if (aKey != sWantedKey) continue; aValue = sLine.substr(n+1, sLine.length()); - sprintf(value, "%s", aValue.c_str()); + snprintf(value, INI_STRINGBUF_SIZE, "%s", aValue.c_str()); return true; } } @@ -142,7 +144,7 @@ char const * getLogLevel() { return env; #ifdef WNT - static char logLevel[1024]; + static char logLevel[INI_STRINGBUF_SIZE]; if (getValueFromLoggingIniFile("LogLevel", logLevel)) return logLevel; #endif @@ -157,7 +159,7 @@ std::ofstream * getLogFile() { return nullptr; #ifdef WNT - static char logFilePath[1024]; + static char logFilePath[INI_STRINGBUF_SIZE]; if (getValueFromLoggingIniFile("LogFilePath", logFilePath)) logFile = logFilePath; else @@ -196,7 +198,7 @@ void maybeOutputTimestamp(std::ostringstream &s) { tm.tm_year = dateTime.Year - 1900; strftime(ts, sizeof(ts), "%Y-%m-%d:%H:%M:%S", &tm); char milliSecs[11]; - sprintf(milliSecs, "%03u", static_cast<unsigned>(dateTime.NanoSeconds/1000000)); + snprintf(milliSecs, sizeof(milliSecs), "%03u", static_cast<unsigned>(dateTime.NanoSeconds/1000000)); s << ts << '.' << milliSecs << ':'; } if (outputRelativeTimer) { @@ -217,7 +219,7 @@ void maybeOutputTimestamp(std::ostringstream &s) { else milliSeconds = (now.Nanosec-first.Nanosec)/1000000; char relativeTimestamp[100]; - sprintf(relativeTimestamp, "%d.%03d", seconds, milliSeconds); + snprintf(relativeTimestamp, sizeof(relativeTimestamp), "%d.%03d", seconds, milliSeconds); s << relativeTimestamp << ':'; } return; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits