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

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

Issue 98403005: Disable kSSizeMaxConst COMPILE_ASSERT() for Android / Mac / IOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable for Mac / Android / IOS instead of clang Created 7 years 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // |buffer| is caller-allocated storage that SafeSPrintf() writes to. It 101 // |buffer| is caller-allocated storage that SafeSPrintf() writes to. It
102 // has |size| bytes of writable storage. It is the caller's responsibility 102 // has |size| bytes of writable storage. It is the caller's responsibility
103 // to ensure that the buffer is at least one byte in size, so that it fits 103 // to ensure that the buffer is at least one byte in size, so that it fits
104 // the trailing NUL that will be added by the destructor. The buffer also 104 // the trailing NUL that will be added by the destructor. The buffer also
105 // must be smaller or equal to kSSizeMax in size. 105 // must be smaller or equal to kSSizeMax in size.
106 Buffer(char* buffer, size_t size) 106 Buffer(char* buffer, size_t size)
107 : buffer_(buffer), 107 : buffer_(buffer),
108 size_(size - 1), // Account for trailing NUL byte 108 size_(size - 1), // Account for trailing NUL byte
109 count_(0) { 109 count_(0) {
110 // This test should work on all C++11 compilers, but apparently something is 110 // This test should work on all C++11 compilers, but apparently something is
111 // not working on all versions of clang just yet (e.g. on Mac, IOS, and 111 // not working on all versions of clang / gcc just yet (e.g. on Mac, IOS, and
112 // Android). We are conservative and exclude all of clang for the time being. 112 // Android). We exclude those platforms for now.
113 // TODO(markus): Check if this restriction can be lifted. 113 // TODO(markus): Check if this restriction can be lifted.
114 #if __cplusplus >= 201103 && !defined(__clang__) 114 #if __cplusplus >= 201103 && !defined(OS_ANDROID) && !defined(OS_MACOSX) && !def ined(OS_IOS)
115 COMPILE_ASSERT(kSSizeMaxConst == std::numeric_limits<ssize_t>::max(), 115 COMPILE_ASSERT(kSSizeMaxConst == std::numeric_limits<ssize_t>::max(),
Inactive 2013/12/06 22:18:10 Note that on Linux desktop, gcc does complain abou
Nico 2013/12/06 22:21:45 It should be safe to cast std::numeric_limits<ssiz
116 kSSizeMax_is_the_max_value_of_an_ssize_t); 116 kSSizeMax_is_the_max_value_of_an_ssize_t);
117 #endif 117 #endif
118 DEBUG_CHECK(size > 0); 118 DEBUG_CHECK(size > 0);
119 DEBUG_CHECK(size <= kSSizeMax); 119 DEBUG_CHECK(size <= kSSizeMax);
120 } 120 }
121 121
122 ~Buffer() { 122 ~Buffer() {
123 // The code calling the constructor guaranteed that there was enough space 123 // The code calling the constructor guaranteed that there was enough space
124 // to store a trailing NUL -- and in debug builds, we are actually 124 // to store a trailing NUL -- and in debug builds, we are actually
125 // verifying this with DEBUG_CHECK()s in the constructor. So, we can 125 // verifying this with DEBUG_CHECK()s in the constructor. So, we can
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 DEBUG_CHECK(src[0] != '%' || src[1] == '%'); 672 DEBUG_CHECK(src[0] != '%' || src[1] == '%');
673 if (src[0] == '%' && src[1] == '%') { 673 if (src[0] == '%' && src[1] == '%') {
674 ++src; 674 ++src;
675 } 675 }
676 } 676 }
677 return buffer.GetCount(); 677 return buffer.GetCount();
678 } 678 }
679 679
680 } // namespace strings 680 } // namespace strings
681 } // namespace base 681 } // 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