Bug 1061483: Remove dependency on NSPR's PR_smprintf, r=cviecco
authorBrian Smith <brian@briansmith.org>
Sun, 31 Aug 2014 22:03:22 -0700
changeset 203713 4b99d99e7d914561800b8c1c7b758c0f0e07b0cc
parent 203712 114820c95c37663a488be3bb45381efb7dacc56e
child 203714 d052bb1a13b8ab453725984232de9bc87d0f91bd
push id27435
push userryanvm@gmail.com
push dateFri, 05 Sep 2014 15:34:32 +0000
treeherdermozilla-central@d934dc4a99ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscviecco
bugs1061483
milestone35.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
Bug 1061483: Remove dependency on NSPR's PR_smprintf, r=cviecco
security/pkix/test/lib/pkixtestutil.cpp
--- a/security/pkix/test/lib/pkixtestutil.cpp
+++ b/security/pkix/test/lib/pkixtestutil.cpp
@@ -23,26 +23,26 @@
  */
 
 #include "pkixtestutil.h"
 
 #include <cerrno>
 #include <cstdio>
 #include <limits>
 #include <new>
+#include <sstream>
 
 #include "cert.h"
 #include "cryptohi.h"
 #include "hasht.h"
 #include "pk11pub.h"
 #include "pkix/pkixnss.h"
 #include "pkixder.h"
 #include "pkixutil.h"
 #include "prinit.h"
-#include "prprf.h"
 #include "secerr.h"
 
 using namespace std;
 
 namespace mozilla { namespace pkix { namespace test {
 
 // python DottedOIDToCode.py --alg sha256WithRSAEncryption 1.2.840.113549.1.1.11
 static const uint8_t alg_sha256WithRSAEncryption[] = {
@@ -61,45 +61,33 @@ deleteCharArray(char* chars)
 inline void
 fclose_void(FILE* file) {
   (void) fclose(file);
 }
 
 typedef mozilla::pkix::ScopedPtr<FILE, fclose_void> ScopedFILE;
 
 FILE*
-OpenFile(const char* dir, const char* filename, const char* mode)
+OpenFile(const string& dir, const string& filename, const string& mode)
 {
-  assert(dir);
-  assert(*dir);
-  assert(filename);
-  assert(*filename);
-
-  ScopedPtr<char, deleteCharArray>
-    path(new (nothrow) char[strlen(dir) + 1 + strlen(filename) + 1]);
-  if (!path) {
-    return nullptr;
-  }
-  strcpy(path.get(), dir);
-  strcat(path.get(), "/");
-  strcat(path.get(), filename);
+  string path = dir + '/' + filename;
 
   ScopedFILE file;
 #ifdef _MSC_VER
   {
     FILE* rawFile;
-    errno_t error = fopen_s(&rawFile, path.get(), mode);
+    errno_t error = fopen_s(&rawFile, path.c_str(), mode.c_str());
     if (error) {
       // TODO: map error to NSPR error code
       rawFile = nullptr;
     }
     file = rawFile;
   }
 #else
-  file = fopen(path.get(), mode);
+  file = fopen(path.c_str(), mode.c_str());
 #endif
   return file.release();
 }
 
 } // unnamed namespace
 
 Result
 TamperOnce(/*in/out*/ ByteString& item, const ByteString& from,
@@ -483,24 +471,29 @@ MaybeLogOutput(const ByteString& result,
   assert(suffix);
 
   // This allows us to more easily debug the generated output, by creating a
   // file in the directory given by MOZILLA_PKIX_TEST_LOG_DIR for each
   // NOT THREAD-SAFE!!!
   const char* logPath = getenv("MOZILLA_PKIX_TEST_LOG_DIR");
   if (logPath) {
     static int counter = 0;
-    ScopedPtr<char, PR_smprintf_free>
-      filename(PR_smprintf("%u-%s.der", counter, suffix));
+
+    std::ostringstream counterStream;
+    counterStream << counter;
+    if (!counterStream) {
+      assert(false);
+      return;
+    }
+    string filename = counterStream.str() + '-' + suffix + ".der";
+
     ++counter;
-    if (filename) {
-      ScopedFILE file(OpenFile(logPath, filename.get(), "wb"));
-      if (file) {
-        (void) fwrite(result.data(), result.length(), 1, file.get());
-      }
+    ScopedFILE file(OpenFile(logPath, filename, "wb"));
+    if (file) {
+      (void) fwrite(result.data(), result.length(), 1, file.get());
     }
   }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // Key Pairs
 
 Result