summaryrefslogtreecommitdiffstats
path: root/third_party/cld
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-14 00:46:23 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-14 00:46:23 +0000
commitdb1b925fa6770885cfd9223ef6f05e196a2f41c6 (patch)
treee23ab18b78934bd50f07f5b9b4bd571577acee4e /third_party/cld
parent83513c9d3646674566e64d9662e2b6ae51bc1325 (diff)
downloadchromium_src-db1b925fa6770885cfd9223ef6f05e196a2f41c6.zip
chromium_src-db1b925fa6770885cfd9223ef6f05e196a2f41c6.tar.gz
chromium_src-db1b925fa6770885cfd9223ef6f05e196a2f41c6.tar.bz2
Fix for a memory error in the CLD code.
BUG=None TEST=Run the uni-tests. Review URL: http://codereview.chromium.org/546043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36203 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/cld')
-rw-r--r--third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/cldutil.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/cldutil.cc b/third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/cldutil.cc
index 65b5d13..33d7c38 100644
--- a/third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/cldutil.cc
+++ b/third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/cldutil.cc
@@ -92,6 +92,9 @@ static const int kMaxGramCount = 16;
// OVERSHOOTS up to 3 bytes
// For runtime use of tables
uint32 cld::BiHashV25(const char* word_ptr, int bytecount) {
+ if (bytecount == 0) {
+ return 0;
+ }
const uint32* word_ptr32 = reinterpret_cast<const uint32*>(word_ptr);
uint32 word0, word1;
if (bytecount <= 4) {
@@ -179,6 +182,9 @@ uint32 QuadHashV25Mix(const char* word_ptr, int bytecount, uint32 prepost) {
// UNDERSHOOTS 1 byte, OVERSHOOTS up to 3 bytes
// For runtime use of tables
uint32 cld::QuadHashV25(const char* word_ptr, int bytecount) {
+ if (bytecount == 0) {
+ return 0;
+ }
uint32 prepost = 0;
if (word_ptr[-1] == ' ') {prepost |= kPreSpaceIndicator;}
if (word_ptr[bytecount] == ' ') {prepost |= kPostSpaceIndicator;}
@@ -190,6 +196,9 @@ uint32 cld::QuadHashV25(const char* word_ptr, int bytecount) {
// OVERSHOOTS up to 3 bytes
// For offline construction of tables
uint32 cld::QuadHashV25Underscore(const char* word_ptr, int bytecount) {
+ if (bytecount == 0) {
+ return 0;
+ }
const char* local_word_ptr = word_ptr;
int local_bytecount = bytecount;
uint32 prepost = 0;
@@ -328,6 +337,9 @@ uint64 OctaHash40Mix(const char* word_ptr, int bytecount, uint64 prepost) {
// The high 8 bits are a simple sum of all bytes, shifted by 0/1/2/3 bits each
// For runtime use of tables V3
uint64 cld::OctaHash40(const char* word_ptr, int bytecount) {
+ if (bytecount == 0) {
+ return 0;
+ }
uint64 prepost = 0;
if (word_ptr[-1] == ' ') {prepost |= kPreSpaceIndicator;}
if (word_ptr[bytecount] == ' ') {prepost |= kPostSpaceIndicator;}
@@ -343,6 +355,9 @@ uint64 cld::OctaHash40(const char* word_ptr, int bytecount) {
// The high 8 bits are a simple sum of all bytes, shifted by 0/1/2/3 bits each
// For offline construction of tables
uint64 cld::OctaHash40underscore(const char* word_ptr, int bytecount) {
+ if (bytecount == 0) {
+ return 0;
+ }
const char* local_word_ptr = word_ptr;
int local_bytecount = bytecount;
uint64 prepost = 0;
@@ -671,6 +686,8 @@ int cld::DoOctaScoreV3(const cld::CLDTableSummary* octagram_obj,
// Terminate previous word or continue current word
if (src[0] == ' ') {
int bytecount = word_end - word_ptr;
+ if (bytecount == 0)
+ break;
// Lookup and score this word
uint64 wordhash40 = OctaHash40(word_ptr, bytecount);
uint32 probs = OctaHashV3Lookup4(octagram_obj, wordhash40);