summaryrefslogtreecommitdiffstats
path: root/base/string_util.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 22:23:20 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 22:23:20 +0000
commit225c8f507421a2eff2ed7a900104431d04ed7e5e (patch)
tree770b7081fc8f2a15abe4635938e03550f010a526 /base/string_util.cc
parentf3f0c05dfbcbfec2ecbb79ba9bab6ffc8f93ea32 (diff)
downloadchromium_src-225c8f507421a2eff2ed7a900104431d04ed7e5e.zip
chromium_src-225c8f507421a2eff2ed7a900104431d04ed7e5e.tar.gz
chromium_src-225c8f507421a2eff2ed7a900104431d04ed7e5e.tar.bz2
linux: build with -Wextra
95% of this is removing "const" from return types, but turning this on found one bug! (A "for" loop that expected its iterator to go negative but which was using an unsigned type.) BUG=34160 Review URL: http://codereview.chromium.org/570012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util.cc')
-rw-r--r--base/string_util.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 5990ef4..a66dae6 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -1182,6 +1182,24 @@ struct IntToStringT {
}
};
+ // This set of templates is very similar to the above templates, but
+ // for testing whether an integer is negative.
+ template <typename INT2, bool NEG2>
+ struct TestNegT { };
+ template <typename INT2>
+ struct TestNegT<INT2, false> {
+ static bool TestNeg(INT2 value) {
+ // value is unsigned, and can never be negative.
+ return false;
+ }
+ };
+ template <typename INT2>
+ struct TestNegT<INT2, true> {
+ static bool TestNeg(INT2 value) {
+ return value < 0;
+ }
+ };
+
static STR IntToString(INT value) {
// log10(2) ~= 0.3 bytes needed per bit or per byte log10(2**8) ~= 2.4.
// So round up to allocate 3 output characters per byte, plus 1 for '-'.
@@ -1191,7 +1209,7 @@ struct IntToStringT {
// then return the substr of what we ended up using.
STR outbuf(kOutputBufSize, 0);
- bool is_neg = value < 0;
+ bool is_neg = TestNegT<INT, NEG>::TestNeg(value);
// Even though is_neg will never be true when INT is parameterized as
// unsigned, even the presence of the unary operation causes a warning.
UINT res = ToUnsignedT<INT, UINT, NEG>::ToUnsigned(value);