Commit 5b12bbfc authored by Jim Meyering's avatar Jim Meyering Committed by Viswanath Sivakumar

folly/FBString.h: avoid -Wsign-compare error

Summary:
* folly/FBString.h (operator>>): Since istream.width() is signed,
handle the case of a negative width. This avoids risk that "n"
will be less than 0 when compared against unsigned "extracted".
However, to suppress the following warning, we must also explicitly
convert "n" to size_t before comparing:

folly/FBString.h:2326:22: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: trunkagent, net-systems@, njormrod, folly-diffs@

FB internal diff: D1770460

Tasks: 5941250

Signature: t1:1770460:1420679684:b262eb31e6511b6311bebf0fbc29099471648b36
parent 0b215436
......@@ -2318,12 +2318,13 @@ std::basic_istream<
auto err = __ios_base::goodbit;
if (sentry) {
auto n = is.width();
if (n == 0) {
if (n <= 0) {
n = str.max_size();
}
str.erase();
auto got = is.rdbuf()->sgetc();
for (; extracted != n && got != T::eof() && !isspace(got); ++extracted) {
for (; extracted != size_t(n) && got != T::eof() &&
!isspace(got); ++extracted) {
// Whew. We get to store this guy
str.push_back(got);
got = is.rdbuf()->snextc();
......
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