Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: base/strings/safe_sprintf.cc

Issue 642263006: Remove trivially-true DEBUG_CHECKs in safe_sprintf.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/safe_sprintf.h" 5 #include "base/strings/safe_sprintf.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #if !defined(NDEBUG) 9 #if !defined(NDEBUG)
10 // In debug builds, we use RAW_CHECK() to print useful error messages, if 10 // In debug builds, we use RAW_CHECK() to print useful error messages, if
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 169 }
170 170
171 // Inserts |padding|-|len| bytes worth of padding into the |buffer_|. 171 // Inserts |padding|-|len| bytes worth of padding into the |buffer_|.
172 // |count_| will also be incremented by the number of bytes that were meant 172 // |count_| will also be incremented by the number of bytes that were meant
173 // to be emitted. The |pad| character is typically either a ' ' space 173 // to be emitted. The |pad| character is typically either a ' ' space
174 // or a '0' zero, but other non-NUL values are legal. 174 // or a '0' zero, but other non-NUL values are legal.
175 // Returns "false", iff the the |buffer_| filled up (i.e. |count_| 175 // Returns "false", iff the the |buffer_| filled up (i.e. |count_|
176 // overflowed |size_|) at any time during padding. 176 // overflowed |size_|) at any time during padding.
177 inline bool Pad(char pad, size_t padding, size_t len) { 177 inline bool Pad(char pad, size_t padding, size_t len) {
178 DEBUG_CHECK(pad); 178 DEBUG_CHECK(pad);
179 DEBUG_CHECK(padding >= 0 && padding <= kSSizeMax); 179 DEBUG_CHECK(padding <= kSSizeMax);
180 DEBUG_CHECK(len >= 0);
181 for (; padding > len; --padding) { 180 for (; padding > len; --padding) {
182 if (!Out(pad)) { 181 if (!Out(pad)) {
183 if (--padding) { 182 if (--padding) {
184 IncrementCount(padding-len); 183 IncrementCount(padding-len);
185 } 184 }
186 return false; 185 return false;
187 } 186 }
188 } 187 }
189 return true; 188 return true;
190 } 189 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 275
277 276
278 bool Buffer::IToASCII(bool sign, bool upcase, int64_t i, int base, 277 bool Buffer::IToASCII(bool sign, bool upcase, int64_t i, int base,
279 char pad, size_t padding, const char* prefix) { 278 char pad, size_t padding, const char* prefix) {
280 // Sanity check for parameters. None of these should ever fail, but see 279 // Sanity check for parameters. None of these should ever fail, but see
281 // above for the rationale why we can't call CHECK(). 280 // above for the rationale why we can't call CHECK().
282 DEBUG_CHECK(base >= 2); 281 DEBUG_CHECK(base >= 2);
283 DEBUG_CHECK(base <= 16); 282 DEBUG_CHECK(base <= 16);
284 DEBUG_CHECK(!sign || base == 10); 283 DEBUG_CHECK(!sign || base == 10);
285 DEBUG_CHECK(pad == '0' || pad == ' '); 284 DEBUG_CHECK(pad == '0' || pad == ' ');
286 DEBUG_CHECK(padding >= 0);
287 DEBUG_CHECK(padding <= kSSizeMax); 285 DEBUG_CHECK(padding <= kSSizeMax);
288 DEBUG_CHECK(!(sign && prefix && *prefix)); 286 DEBUG_CHECK(!(sign && prefix && *prefix));
289 287
290 // Handle negative numbers, if the caller indicated that |i| should be 288 // Handle negative numbers, if the caller indicated that |i| should be
291 // treated as a signed number; otherwise treat |i| as unsigned (even if the 289 // treated as a signed number; otherwise treat |i| as unsigned (even if the
292 // MSB is set!) 290 // MSB is set!)
293 // Details are tricky, because of limited data-types, but equivalent pseudo- 291 // Details are tricky, because of limited data-types, but equivalent pseudo-
294 // code would look like: 292 // code would look like:
295 // if (sign && i < 0) 293 // if (sign && i < 0)
296 // prefix = "-"; 294 // prefix = "-";
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 DEBUG_CHECK(src[0] != '%' || src[1] == '%'); 676 DEBUG_CHECK(src[0] != '%' || src[1] == '%');
679 if (src[0] == '%' && src[1] == '%') { 677 if (src[0] == '%' && src[1] == '%') {
680 ++src; 678 ++src;
681 } 679 }
682 } 680 }
683 return buffer.GetCount(); 681 return buffer.GetCount();
684 } 682 }
685 683
686 } // namespace strings 684 } // namespace strings
687 } // namespace base 685 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698