From 2f5c6c3e446d6b98398dc5aeaf0e13ec888e1726 Mon Sep 17 00:00:00 2001 From: Sean Cannella Date: Wed, 29 Oct 2014 14:02:55 -0700 Subject: [PATCH] Really fix the clang warning in Format-inl.h 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/folly/Format-inl.h b/folly/Format-inl.h index bfbacc3f..5331bbba 100644 --- a/folly/Format-inl.h +++ b/folly/Format-inl.h @@ -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 + // 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(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(arg.width)) { char fill = arg.fill == FormatArg::kDefaultFill ? ' ' : arg.fill; int padChars = static_cast (arg.width - val.size()); memset(padBuf, fill, std::min(padBufSize, padChars)); -- 2.34.1