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

Side by Side Diff: chrome/third_party/hunspell/src/hunspell/hashmgr.cxx

Issue 6430: [Chromium-reviews] Fix issue 3039/3040 (Add to dictionary crasher) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 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 | Annotate | Revision Log
« no previous file with comments | « chrome/third_party/hunspell/src/hunspell/hashmgr.hxx ('k') | 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 #include "license.hunspell" 1 #include "license.hunspell"
2 #include "license.myspell" 2 #include "license.myspell"
3 3
4 #ifndef MOZILLA_CLIENT 4 #ifndef MOZILLA_CLIENT
5 #include <cstdlib> 5 #include <cstdlib>
6 #include <cstring> 6 #include <cstring>
7 #include <cstdio> 7 #include <cstdio>
8 #include <cctype> 8 #include <cctype>
9 #else 9 #else
10 #include <stdlib.h> 10 #include <stdlib.h>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 for (int j = 0; j < (numaliasm); j++) free(aliasm[j]); 112 for (int j = 0; j < (numaliasm); j++) free(aliasm[j]);
113 free(aliasm); 113 free(aliasm);
114 aliasm = NULL; 114 aliasm = NULL;
115 } 115 }
116 116
117 if (ignorechars) free(ignorechars); 117 if (ignorechars) free(ignorechars);
118 if (ignorechars_utf16) free(ignorechars_utf16); 118 if (ignorechars_utf16) free(ignorechars_utf16);
119 119
120 #ifdef HUNSPELL_CHROME_CLIENT 120 #ifdef HUNSPELL_CHROME_CLIENT
121 EmptyHentryCache(); 121 EmptyHentryCache();
122 STLDeleteValues(&custom_word_to_hentry_map_);
123 for (std::vector<std::string*>::iterator it = pointer_to_strings_.begin(); 122 for (std::vector<std::string*>::iterator it = pointer_to_strings_.begin();
124 it != pointer_to_strings_.end(); ++it) { 123 it != pointer_to_strings_.end(); ++it) {
125 delete *it; 124 delete *it;
126 } 125 }
127 #endif 126 #endif
128 } 127 }
129 128
130 #ifdef HUNSPELL_CHROME_CLIENT 129 #ifdef HUNSPELL_CHROME_CLIENT
131 void HashMgr::EmptyHentryCache() { 130 void HashMgr::EmptyHentryCache() {
132 // We need to delete each cache entry, and each additional one in the linked 131 // We need to delete each cache entry, and each additional one in the linked
(...skipping 12 matching lines...) Expand all
145 #endif 144 #endif
146 145
147 // lookup a root word in the hashtable 146 // lookup a root word in the hashtable
148 147
149 struct hentry * HashMgr::lookup(const char *word) const 148 struct hentry * HashMgr::lookup(const char *word) const
150 { 149 {
151 #ifdef HUNSPELL_CHROME_CLIENT 150 #ifdef HUNSPELL_CHROME_CLIENT
152 int affix_ids[hunspell::BDict::MAX_AFFIXES_PER_WORD]; 151 int affix_ids[hunspell::BDict::MAX_AFFIXES_PER_WORD];
153 int affix_count = bdict_reader->FindWord(word, affix_ids); 152 int affix_count = bdict_reader->FindWord(word, affix_ids);
154 if (affix_count == 0) { // look for custom added word 153 if (affix_count == 0) { // look for custom added word
155 std::map<StringPiece, struct hentry *>::const_iterator iter = 154 std::map<StringPiece, int>::const_iterator iter =
156 custom_word_to_hentry_map_.find(word); 155 custom_word_to_affix_id_map_.find(word);
157 if (iter != custom_word_to_hentry_map_.end()) 156 if (iter != custom_word_to_affix_id_map_.end()) {
158 return iter->second; 157 affix_count = 1;
159 else 158 affix_ids[0] = iter->second;
160 return NULL; 159 }
161 } 160 }
162 161
163 static const int kMaxWordLen = 128; 162 static const int kMaxWordLen = 128;
164 static char word_buf[kMaxWordLen]; 163 static char word_buf[kMaxWordLen];
165 strncpy(word_buf, word, kMaxWordLen); 164 strncpy(word_buf, word, kMaxWordLen);
166 165
167 return AffixIDsToHentry(word_buf, affix_ids, affix_count); 166 return AffixIDsToHentry(word_buf, affix_ids, affix_count);
168 #else 167 #else
169 struct hentry * dp; 168 struct hentry * dp;
170 if (tableptr) { 169 if (tableptr) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 235 }
237 #endif 236 #endif
238 while (dp->next != NULL) { 237 while (dp->next != NULL) {
239 if ((!dp->next_homonym) && (strcmp(hp->word, dp->word) == 0)) dp->next_ homonym = hp; 238 if ((!dp->next_homonym) && (strcmp(hp->word, dp->word) == 0)) dp->next_ homonym = hp;
240 dp=dp->next; 239 dp=dp->next;
241 } 240 }
242 if ((!dp->next_homonym) && (strcmp(hp->word, dp->word) == 0)) dp->next_ho monym = hp; 241 if ((!dp->next_homonym) && (strcmp(hp->word, dp->word) == 0)) dp->next_ho monym = hp;
243 dp->next = hp; 242 dp->next = hp;
244 } 243 }
245 #endif // HUNSPELL_CHROME_CLIENT 244 #endif // HUNSPELL_CHROME_CLIENT
246 std::map<StringPiece, struct hentry *>::iterator iter = 245 std::map<StringPiece, int>::iterator iter =
247 custom_word_to_hentry_map_.find(word); 246 custom_word_to_affix_id_map_.find(word);
248 if(iter == custom_word_to_hentry_map_.end()) { // word needs to be added 247 if(iter == custom_word_to_affix_id_map_.end()) { // word needs to be added
249 // Make a custom hentry.
250 struct hentry* he = new hentry;
251 he->word = (char *)word;
252 he->wlen = wl;
253 he->next = NULL;
254 he->next_homonym = NULL;
255
256 std::string* new_string_word = new std::string(word); 248 std::string* new_string_word = new std::string(word);
257 pointer_to_strings_.push_back(new_string_word); 249 pointer_to_strings_.push_back(new_string_word);
258 StringPiece sp(*(new_string_word)); 250 StringPiece sp(*(new_string_word));
259 custom_word_to_hentry_map_[sp] = he; 251 custom_word_to_affix_id_map_[sp] = 0; // no affixes for custom words
260 return 1; 252 return 1;
261 } 253 }
262 254
263 return 0; 255 return 0;
264 } 256 }
265 257
266 // add a custom dic. word to the hash table (public) 258 // add a custom dic. word to the hash table (public)
267 int HashMgr::put_word(const char * word, int wl, char * aff) 259 int HashMgr::put_word(const char * word, int wl, char * aff)
268 { 260 {
269 unsigned short * flags; 261 unsigned short * flags;
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 int HashMgr::is_aliasm() { 920 int HashMgr::is_aliasm() {
929 return (aliasm != NULL); 921 return (aliasm != NULL);
930 } 922 }
931 923
932 char * HashMgr::get_aliasm(int index) { 924 char * HashMgr::get_aliasm(int index) {
933 if ((index > 0) && (index <= numaliasm)) return aliasm[index - 1]; 925 if ((index > 0) && (index <= numaliasm)) return aliasm[index - 1];
934 HUNSPELL_WARNING(stderr, "error: bad morph. alias index: %d\n", index); 926 HUNSPELL_WARNING(stderr, "error: bad morph. alias index: %d\n", index);
935 return NULL; 927 return NULL;
936 } 928 }
937 #endif 929 #endif
OLDNEW
« no previous file with comments | « chrome/third_party/hunspell/src/hunspell/hashmgr.hxx ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698