From 4be808739e58723bc6b994a10d7a9270229912e8 Mon Sep 17 00:00:00 2001 From: Sean Cannella Date: Tue, 28 Oct 2014 19:09:35 -0700 Subject: [PATCH] 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 --- folly/Format-inl.h | 7 +++++++ 1 file changed, 7 insertions(+) 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); -- 2.34.1