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

Side by Side Diff: third_party/WebKit/Source/platform/wtf/text/TextCodecUTF8.cpp

Issue 2919653004: Use LOG() or LOG_IF() instead of IMMEDIATE_CRASH (Closed)
Patch Set: Use LOG() or CHECK()|CHECK_FOO() instead of IMMEDIATE_CRASH Created 3 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 return String::Adopt(buffer16); 456 return String::Adopt(buffer16);
457 } 457 }
458 458
459 template <typename CharType> 459 template <typename CharType>
460 CString TextCodecUTF8::EncodeCommon(const CharType* characters, size_t length) { 460 CString TextCodecUTF8::EncodeCommon(const CharType* characters, size_t length) {
461 // The maximum number of UTF-8 bytes needed per UTF-16 code unit is 3. 461 // The maximum number of UTF-8 bytes needed per UTF-16 code unit is 3.
462 // BMP characters take only one UTF-16 code unit and can take up to 3 bytes 462 // BMP characters take only one UTF-16 code unit and can take up to 3 bytes
463 // (3x). 463 // (3x).
464 // Non-BMP characters take two UTF-16 code units and can take up to 4 bytes 464 // Non-BMP characters take two UTF-16 code units and can take up to 4 bytes
465 // (2x). 465 // (2x).
466 if (length > std::numeric_limits<size_t>::max() / 3) 466 CHECK_LE(length, std::numeric_limits<size_t>::max() / 3);
467 IMMEDIATE_CRASH();
468 Vector<uint8_t> bytes(length * 3); 467 Vector<uint8_t> bytes(length * 3);
469 468
470 size_t i = 0; 469 size_t i = 0;
471 size_t bytes_written = 0; 470 size_t bytes_written = 0;
472 while (i < length) { 471 while (i < length) {
473 UChar32 character; 472 UChar32 character;
474 U16_NEXT(characters, i, length, character); 473 U16_NEXT(characters, i, length, character);
475 // U16_NEXT will simply emit a surrogate code point if an unmatched 474 // U16_NEXT will simply emit a surrogate code point if an unmatched
476 // surrogate is encountered; we must convert it to a 475 // surrogate is encountered; we must convert it to a
477 // U+FFFD (REPLACEMENT CHARACTER) here. 476 // U+FFFD (REPLACEMENT CHARACTER) here.
(...skipping 11 matching lines...) Expand all
489 return EncodeCommon(characters, length); 488 return EncodeCommon(characters, length);
490 } 489 }
491 490
492 CString TextCodecUTF8::Encode(const LChar* characters, 491 CString TextCodecUTF8::Encode(const LChar* characters,
493 size_t length, 492 size_t length,
494 UnencodableHandling) { 493 UnencodableHandling) {
495 return EncodeCommon(characters, length); 494 return EncodeCommon(characters, length);
496 } 495 }
497 496
498 } // namespace WTF 497 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/wtf/text/StringImpl.cpp ('k') | third_party/WebKit/Source/web/WebPagePopupImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698