 Chromium Code Reviews
 Chromium Code Reviews Issue 681123006:
  Fix a 'type-limits' warning in StringSlicer::FindValidBoundaryAfter  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 681123006:
  Fix a 'type-limits' warning in StringSlicer::FindValidBoundaryAfter  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: ui/gfx/text_elider.cc | 
| diff --git a/ui/gfx/text_elider.cc b/ui/gfx/text_elider.cc | 
| index 1bf85d4936761a22cf3351c4fa0e871abbf518bd..6edd2ab4fdb5cebbe6ec8739632162bd917b09ac 100644 | 
| --- a/ui/gfx/text_elider.cc | 
| +++ b/ui/gfx/text_elider.cc | 
| @@ -17,6 +17,7 @@ | 
| #include "base/i18n/char_iterator.h" | 
| #include "base/i18n/rtl.h" | 
| #include "base/memory/scoped_ptr.h" | 
| +#include "base/numerics/safe_conversions.h" | 
| #include "base/strings/string_split.h" | 
| #include "base/strings/string_util.h" | 
| #include "base/strings/sys_string_conversions.h" | 
| @@ -146,9 +147,13 @@ size_t StringSlicer::FindValidBoundaryBefore(size_t index) const { | 
| size_t StringSlicer::FindValidBoundaryAfter(size_t index) const { | 
| DCHECK_LE(index, text_.length()); | 
| - if (index != text_.length()) | 
| - U16_SET_CP_LIMIT(text_.data(), 0, index, text_.length()); | 
| - return index; | 
| + if (index == text_.length()) | 
| + return index; | 
| + | 
| + int32_t text_index = base::checked_cast<int32_t>(index); | 
| + int32_t text_length = base::checked_cast<int32_t>(text_.length()); | 
| + U16_SET_CP_LIMIT(text_.data(), 0, text_index, text_length); | 
| 
msw
2014/10/29 20:46:43
Didn't Peter suggest using c_str() instead of data
 
Ben Chan
2014/10/29 21:08:30
I believe .c_str() isn't necessary if the length i
 
msw
2014/10/29 21:15:46
If c_str() offers additional safety without seriou
 
Ben Chan
2014/10/29 21:23:36
The only thing I can think of may be related to pe
 | 
| + return static_cast<size_t>(text_index); | 
| 
msw
2014/10/29 20:46:44
Shouldn't this check that the 32-bit index won't o
 
Ben Chan
2014/10/29 21:08:30
do we support a platform with 16-bit size_t? if so
 
msw
2014/10/29 21:15:46
Heh, perhaps not, I guess this ought to be fine ot
 | 
| } | 
| base::string16 ElideFilename(const base::FilePath& filename, |