From: Sean Cannella Date: Wed, 29 Oct 2014 02:09:35 +0000 (-0700) Subject: Address clang sign warning in Format-inl.h X-Git-Tag: v0.22.0~235 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4be808739e58723bc6b994a10d7a9270229912e8;p=folly.git Address clang sign warning in Format-inl.h Summary: This has been bothering me for a while when I've been trying to verify builds with clang. This generates a ton of spew and the current code can't actually handle non-default negatives so let's just throw if we see one. Test Plan: fbmake runtests Reviewed By: meyering@fb.com Subscribers: mathieubaudet, njormrod, folly-diffs@, bmatheny, benyluo, shikong, kmdent, fma, ranjeeth, subodh FB internal diff: D1643881 Signature: t1:1643881:1414523777:085035ce8c280fbd6481b2ce0354b53b96fdc50e --- diff --git a/folly/Format-inl.h b/folly/Format-inl.h index f05a5c72..bfbacc3f 100644 --- a/folly/Format-inl.h +++ b/folly/Format-inl.h @@ -306,6 +306,13 @@ namespace format_value { template void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) { + if (arg.width != FormatArg::kDefaultWidth && arg.width < 0) { + throw BadFormatArg("folly::format: invalid width"); + } + if (arg.precision != FormatArg::kDefaultPrecision && arg.precision < 0) { + throw BadFormatArg("folly::format: invalid precision"); + } + if (arg.precision != FormatArg::kDefaultPrecision && val.size() > arg.precision) { val.reset(val.data(), arg.precision);