Address clang sign warning in Format-inl.h
authorSean Cannella <seanc@fb.com>
Wed, 29 Oct 2014 02:09:35 +0000 (19:09 -0700)
committerdcsommer <dcsommer@fb.com>
Wed, 29 Oct 2014 23:07:12 +0000 (16:07 -0700)
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

index f05a5c723331edf0649d878900d54ebb1c212af5..bfbacc3fa499d053be93f5dd2f5565d0ab78b537 100644 (file)
@@ -306,6 +306,13 @@ namespace format_value {
 
 template <class FormatCallback>
 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);