Swap a few APIs to reduce sign and implicit truncations required to work with it
[folly.git] / folly / io / Cursor.cpp
index f2dc1c3eaf74ded078cfecde26b886ceff9e4cf9..9d51092e5ee361dcde61bd8fcfc1ef940467471f 100644 (file)
@@ -43,28 +43,30 @@ void Appender::vprintf(const char* fmt, va_list ap) {
   if (ret < 0) {
     throw std::runtime_error("error formatting printf() data");
   }
+  auto len = size_t(ret);
   // vsnprintf() returns the number of characters that would be printed,
   // not including the terminating nul.
-  if (size_t(ret) < length()) {
+  if (len < length()) {
     // All of the data was successfully written.
-    append(ret);
+    append(len);
     return;
   }
 
   // There wasn't enough room for the data.
   // Allocate more room, and then retry.
-  ensure(ret + 1);
+  ensure(len + 1);
   ret = vsnprintf(reinterpret_cast<char*>(writableData()), length(),
                   fmt, apCopy);
   if (ret < 0) {
     throw std::runtime_error("error formatting printf() data");
   }
-  if (size_t(ret) >= length()) {
+  len = size_t(ret);
+  if (len >= length()) {
     // This shouldn't ever happen.
     throw std::runtime_error("unexpectedly out of buffer space on second "
                              "vsnprintf() attmept");
   }
-  append(ret);
+  append(len);
 }
 
 }}  // folly::io