ErrorBase: change to ostringstream. (#66)

This fixes a snprintf issue on 64-bit platforms by avoiding the use
of snprintf.
This commit is contained in:
Peter Johnson
2016-06-01 00:12:55 -07:00
parent c7c011813f
commit f0d9e19b5c

View File

@@ -8,9 +8,8 @@
#include "ErrorBase.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <iomanip>
#include <sstream>
#define WPI_ERRORS_DEFINE_STRINGS
@@ -51,10 +50,10 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
err = "OK: ";
err += contextMessage;
} else {
char buf[256];
snprintf(buf, 256, "%s (0x%08X): %.*s", strerror(errNo), errNo,
contextMessage.size(), contextMessage.data());
err = buf;
std::ostringstream oss;
oss << strerror(errNo) << " (0x" << std::setfill('0') << std::hex
<< std::uppercase << std::setw(8) << errNo << "): " << contextMessage;
err = oss.str();
}
// Set the current error information for this object.