author | Honza Bambas <honzab.moz@firemni.cz> |
Wed, 01 Mar 2017 05:02:00 -0500 | |
changeset 345327 | 1bea491fae965da7d65cf345f67ca5fb870d4356 |
parent 345326 | acf42887c8a7cf23ff677d49742cd6610545a38b |
child 345328 | a6db4cae99904cecfc03101a7007a147aca6b1fc |
push id | 87558 |
push user | ryanvm@gmail.com |
push date | Wed, 01 Mar 2017 17:06:44 +0000 |
treeherder | mozilla-inbound@e2395b3b1e16 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | froydnj |
bugs | 1341017 |
milestone | 54.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/xpcom/base/Logging.cpp +++ b/xpcom/base/Logging.cpp @@ -356,24 +356,30 @@ public: void Print(const char* aName, LogLevel aLevel, const char* aFmt, va_list aArgs) { const size_t kBuffSize = 1024; char buff[kBuffSize]; char* buffToWrite = buff; - // For backwards compat we need to use the NSPR format string versions - // of sprintf and friends and then hand off to printf. va_list argsCopy; va_copy(argsCopy, aArgs); - size_t charsWritten = VsprintfLiteral(buff, aFmt, argsCopy); + int charsWritten = VsprintfLiteral(buff, aFmt, argsCopy); va_end(argsCopy); - if (charsWritten == kBuffSize - 1) { + if (charsWritten < 0) { + // Print out at least something. We must copy to the local buff, + // can't just assign aFmt to buffToWrite, since when + // buffToWrite != buff, we try to release it. + MOZ_ASSERT(false, "Probably incorrect format string in LOG?"); + strncpy(buff, aFmt, kBuffSize - 1); + buff[kBuffSize - 1] = '\0'; + charsWritten = strlen(buff); + } else if (static_cast<size_t>(charsWritten) >= kBuffSize - 1) { // We may have maxed out, allocate a buffer instead. buffToWrite = mozilla::Vsmprintf(aFmt, aArgs); charsWritten = strlen(buffToWrite); } // Determine if a newline needs to be appended to the message. const char* newline = ""; if (charsWritten == 0 || buffToWrite[charsWritten - 1] != '\n') {