Commit 0dee3980 authored by Sarang Masti's avatar Sarang Masti Committed by Noam Lerner

Relax CHECK condition in stringAppendfImpl

Summary:
vsnprintf can return fewer bytes and bytes_used if
we print a string containing '\0' using a width
specifier.

Test Plan: -- ran all tests

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: folly-diffs@, yfeldblum

FB internal diff: D1915035

Signature: t1:1915035:1426799341:4aaea928c4bdde1998bf66cf9e2732a53572c6e3
parent 71b91824
......@@ -73,12 +73,13 @@ void stringAppendfImpl(std::string& output, const char* format, va_list args) {
std::unique_ptr<char[]> heap_buffer(new char[bytes_used + 1]);
int final_bytes_used =
stringAppendfImplHelper(heap_buffer.get(), bytes_used + 1, format, args);
// The second call should require the same length, which is 1 less
// than the buffer size (we don't keep the trailing \0 byte in our
// output string).
CHECK(bytes_used == final_bytes_used);
// The second call can take fewer bytes if, for example, we were printing a
// string buffer with null-terminating char using a width specifier -
// vsnprintf("%.*s", buf.size(), buf)
CHECK(bytes_used >= final_bytes_used);
output.append(heap_buffer.get(), bytes_used);
// We don't keep the trailing '\0' in our output string
output.append(heap_buffer.get(), final_bytes_used);
}
} // anon namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment