Really fix the clang warning in Format-inl.h
authorSean Cannella <seanc@fb.com>
Wed, 29 Oct 2014 21:02:55 +0000 (14:02 -0700)
committerdcsommer <dcsommer@fb.com>
Wed, 29 Oct 2014 23:08:28 +0000 (16:08 -0700)
Summary:
The previous diff added the safety check but didn't actually
remove the compiler warning. This is what I get for doing an incremental
compile.

Test Plan: fbmake clean ; fbmake dbg with clang:dev

Reviewed By: meyering@fb.com

Subscribers: trunkagent, mathieubaudet, njormrod, folly-diffs@, bmatheny, ranjeeth, subodh, kmdent, fma, benyluo

FB internal diff: D1646519

Signature: t1:1646519:1414602292:cfb908ae094caaef02e64eb2c42544fd34fa1389

folly/Format-inl.h

index bfbacc3fa499d053be93f5dd2f5565d0ab78b537..5331bbba199038caed2cae4e9104ebcb40d5fe1e 100644 (file)
@@ -313,8 +313,12 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) {
     throw BadFormatArg("folly::format: invalid precision");
   }
 
+  // XXX: clang should be smart enough to not need the two static_cast<size_t>
+  // uses below given the above checks. If clang ever becomes that smart, we
+  // should remove the otherwise unnecessary warts.
+
   if (arg.precision != FormatArg::kDefaultPrecision &&
-      val.size() > arg.precision) {
+      val.size() > static_cast<size_t>(arg.precision)) {
     val.reset(val.data(), arg.precision);
   }
 
@@ -331,7 +335,8 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) {
   };
 
   int padRemaining = 0;
-  if (arg.width != FormatArg::kDefaultWidth && val.size() < arg.width) {
+  if (arg.width != FormatArg::kDefaultWidth &&
+      val.size() < static_cast<size_t>(arg.width)) {
     char fill = arg.fill == FormatArg::kDefaultFill ? ' ' : arg.fill;
     int padChars = static_cast<int> (arg.width - val.size());
     memset(padBuf, fill, std::min(padBufSize, padChars));