X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fio%2FCursor.cpp;h=cd7807c1568941e1872406e9a428ce49ab3fe1a7;hb=ecd0fb38477b04e36685a0808a904fd9080f50b1;hp=fe478403b4ab0e3fa8df61d35878d96702b2fc95;hpb=1fa49a2e4b15c727fdb0715545c44f3aa1108193;p=folly.git diff --git a/folly/io/Cursor.cpp b/folly/io/Cursor.cpp index fe478403..cd7807c1 100644 --- a/folly/io/Cursor.cpp +++ b/folly/io/Cursor.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include #include + #include -namespace folly { namespace io { +namespace folly { +namespace io { void Appender::printf(const char* fmt, ...) { va_list ap; @@ -43,28 +46,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(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 +} // namespace io +} // namespace folly