Merge "Fix native crash in BigramDictionary::addWordBigram()"
This commit is contained in:
commit
44f195509a
1 changed files with 10 additions and 4 deletions
|
@ -41,6 +41,9 @@ BigramDictionary::~BigramDictionary() {
|
||||||
|
|
||||||
void BigramDictionary::addWordBigram(int *word, int length, int probability, int *bigramProbability,
|
void BigramDictionary::addWordBigram(int *word, int length, int probability, int *bigramProbability,
|
||||||
int *bigramCodePoints, int *outputTypes) const {
|
int *bigramCodePoints, int *outputTypes) const {
|
||||||
|
if (length >= MAX_WORD_LENGTH) {
|
||||||
|
length = MAX_WORD_LENGTH - 1;
|
||||||
|
}
|
||||||
word[length] = 0;
|
word[length] = 0;
|
||||||
if (DEBUG_DICT_FULL) {
|
if (DEBUG_DICT_FULL) {
|
||||||
#ifdef FLAG_DBG
|
#ifdef FLAG_DBG
|
||||||
|
@ -66,14 +69,17 @@ void BigramDictionary::addWordBigram(int *word, int length, int probability, int
|
||||||
if (insertAt >= MAX_RESULTS) {
|
if (insertAt >= MAX_RESULTS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memmove(bigramProbability + (insertAt + 1),
|
// Shift result buffers to insert the new entry.
|
||||||
bigramProbability + insertAt,
|
memmove(bigramProbability + (insertAt + 1), bigramProbability + insertAt,
|
||||||
(MAX_RESULTS - insertAt - 1) * sizeof(bigramProbability[0]));
|
(MAX_RESULTS - insertAt - 1) * sizeof(bigramProbability[0]));
|
||||||
bigramProbability[insertAt] = probability;
|
memmove(outputTypes + (insertAt + 1), outputTypes + insertAt,
|
||||||
outputTypes[insertAt] = Dictionary::KIND_PREDICTION;
|
(MAX_RESULTS - insertAt - 1) * sizeof(outputTypes[0]));
|
||||||
memmove(bigramCodePoints + (insertAt + 1) * MAX_WORD_LENGTH,
|
memmove(bigramCodePoints + (insertAt + 1) * MAX_WORD_LENGTH,
|
||||||
bigramCodePoints + insertAt * MAX_WORD_LENGTH,
|
bigramCodePoints + insertAt * MAX_WORD_LENGTH,
|
||||||
(MAX_RESULTS - insertAt - 1) * sizeof(bigramCodePoints[0]) * MAX_WORD_LENGTH);
|
(MAX_RESULTS - insertAt - 1) * sizeof(bigramCodePoints[0]) * MAX_WORD_LENGTH);
|
||||||
|
// Put the result.
|
||||||
|
bigramProbability[insertAt] = probability;
|
||||||
|
outputTypes[insertAt] = Dictionary::KIND_PREDICTION;
|
||||||
int *dest = bigramCodePoints + insertAt * MAX_WORD_LENGTH;
|
int *dest = bigramCodePoints + insertAt * MAX_WORD_LENGTH;
|
||||||
while (length--) {
|
while (length--) {
|
||||||
*dest++ = *word++;
|
*dest++ = *word++;
|
||||||
|
|
Loading…
Reference in a new issue