From f0d9e19b5ce5f64409f2551ff588fa5b943a17cf Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 1 Jun 2016 00:12:55 -0700 Subject: [PATCH] ErrorBase: change to ostringstream. (#66) This fixes a snprintf issue on 64-bit platforms by avoiding the use of snprintf. --- wpilibc/shared/src/ErrorBase.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/wpilibc/shared/src/ErrorBase.cpp b/wpilibc/shared/src/ErrorBase.cpp index c805ff92dc..969a377f8b 100644 --- a/wpilibc/shared/src/ErrorBase.cpp +++ b/wpilibc/shared/src/ErrorBase.cpp @@ -8,9 +8,8 @@ #include "ErrorBase.h" #include -#include -#include +#include #include #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.