Fix reading uninitialized memory.

Bug: 12967899

Change-Id: Ia17e4ca9dd8c1e0b24b0fb7e73d07b97c5d81c0c
This commit is contained in:
Keisuke Kuroyanagi 2014-02-13 21:18:02 +09:00
parent 85f6edbaba
commit a000a32c80
9 changed files with 29 additions and 29 deletions

View file

@ -46,7 +46,7 @@ Dictionary::Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::S
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
const SuggestOptions *const suggestOptions, int *outWords, int *outputScores,
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
TimeKeeper::setCurrentTime();
int result = 0;
@ -55,9 +55,9 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
result = mGestureSuggest.get()->getSuggestions(proximityInfo, traverseSession, xcoordinates,
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords,
frequencies, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
outputScores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
if (DEBUG_DICT) {
DUMP_RESULT(outWords, frequencies);
DUMP_RESULT(outWords, outputScores);
}
return result;
} else {
@ -65,20 +65,20 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
result = mTypingSuggest.get()->getSuggestions(proximityInfo, traverseSession, xcoordinates,
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint,
outWords, frequencies, spaceIndices, outputTypes,
outWords, outputScores, spaceIndices, outputTypes,
outputAutoCommitFirstWordConfidence);
if (DEBUG_DICT) {
DUMP_RESULT(outWords, frequencies);
DUMP_RESULT(outWords, outputScores);
}
return result;
}
}
int Dictionary::getBigrams(const int *word, int length, int *outWords, int *frequencies,
int Dictionary::getBigrams(const int *word, int length, int *outWords, int *outputScores,
int *outputTypes) const {
TimeKeeper::setCurrentTime();
if (length <= 0) return 0;
return mBigramDictionary.get()->getPredictions(word, length, outWords, frequencies,
return mBigramDictionary.get()->getPredictions(word, length, outWords, outputScores,
outputTypes);
}

View file

@ -64,10 +64,10 @@ class Dictionary {
int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint,
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
const SuggestOptions *const suggestOptions, int *outWords, int *outputScores,
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const;
int getBigrams(const int *word, int length, int *outWords, int *frequencies,
int getBigrams(const int *word, int length, int *outWords, int *outputScores,
int *outputTypes) const;
int getProbability(const int *word, int length) const;

View file

@ -31,7 +31,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
// TODO: Split this method.
/* static */ int SuggestionsOutputUtils::outputSuggestions(
const Scoring *const scoringPolicy, DicTraverseSession *traverseSession,
int *frequencies, int *outputCodePoints, int *outputIndicesToPartialCommit,
int *outputScores, int *outputCodePoints, int *outputIndicesToPartialCommit,
int *outputTypes, int *outputAutoCommitFirstWordConfidence) {
#if DEBUG_EVALUATE_MOST_PROBABLE_STRING
const int terminalSize = 0;
@ -52,7 +52,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
// Insert most probable word at index == 0 as long as there is one terminal at least
const bool hasMostProbableString =
scoringPolicy->getMostProbableString(traverseSession, terminalSize, languageWeight,
&outputCodePoints[0], &outputTypes[0], &frequencies[0]);
&outputCodePoints[0], &outputTypes[0], &outputScores[0]);
if (hasMostProbableString) {
outputIndicesToPartialCommit[outputWordIndex] = NOT_AN_INDEX;
++outputWordIndex;
@ -97,7 +97,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
const bool isExactMatch =
ErrorTypeUtils::isExactMatch(terminalDicNode->getContainedErrorTypes());
const bool isFirstCharUppercase = terminalDicNode->isFirstCharUppercase();
// Heuristic: We exclude freq=0 first-char-uppercase words from exact match.
// Heuristic: We exclude probability=0 first-char-uppercase words from exact match.
// (e.g. "AMD" and "and")
const bool isSafeExactMatch = isExactMatch
&& !(isPossiblyOffensiveWord && isFirstCharUppercase);
@ -123,7 +123,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
// Don't output invalid words. However, we still need to submit their shortcuts if any.
if (isValidWord) {
outputTypes[outputWordIndex] = Dictionary::KIND_CORRECTION | outputTypeFlags;
frequencies[outputWordIndex] = finalScore;
outputScores[outputWordIndex] = finalScore;
if (outputSecondWordFirstLetterInputIndex) {
outputIndicesToPartialCommit[outputWordIndex] =
terminalDicNode->getSecondWordFirstInputIndex(
@ -151,7 +151,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
terminalDicNode->getContainedErrorTypes(),
true /* forceCommit */, boostExactMatches) : finalScore;
const int updatedOutputWordIndex = outputShortcuts(&shortcutIt,
outputWordIndex, shortcutBaseScore, outputCodePoints, frequencies, outputTypes,
outputWordIndex, shortcutBaseScore, outputCodePoints, outputScores, outputTypes,
sameAsTyped);
const int secondWordFirstInputIndex = terminalDicNode->getSecondWordFirstInputIndex(
traverseSession->getProximityInfoState(0));
@ -168,8 +168,8 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
}
if (hasMostProbableString) {
scoringPolicy->safetyNetForMostProbableString(terminalSize, maxScore,
&outputCodePoints[0], &frequencies[0]);
scoringPolicy->safetyNetForMostProbableString(outputWordIndex, maxScore,
&outputCodePoints[0], outputScores);
}
return outputWordIndex;
}
@ -229,7 +229,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
/* static */ int SuggestionsOutputUtils::outputShortcuts(
BinaryDictionaryShortcutIterator *const shortcutIt,
int outputWordIndex, const int finalScore, int *const outputCodePoints,
int *const frequencies, int *const outputTypes, const bool sameAsTyped) {
int *const outputScores, int *const outputTypes, const bool sameAsTyped) {
int shortcutTarget[MAX_WORD_LENGTH];
while (shortcutIt->hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
bool isWhilelist;
@ -249,8 +249,8 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
kind = Dictionary::KIND_SHORTCUT;
}
outputTypes[outputWordIndex] = kind;
frequencies[outputWordIndex] = shortcutScore;
frequencies[outputWordIndex] = max(S_INT_MIN + 1, shortcutScore) - 1;
outputScores[outputWordIndex] = shortcutScore;
outputScores[outputWordIndex] = max(S_INT_MIN + 1, shortcutScore) - 1;
const int startIndex2 = outputWordIndex * MAX_WORD_LENGTH;
DicNodeUtils::appendTwoWords(0, 0, shortcutTarget, shortcutTargetStringLength,
&outputCodePoints[startIndex2]);

View file

@ -32,7 +32,7 @@ class SuggestionsOutputUtils {
* Outputs the final list of suggestions (i.e., terminal nodes).
*/
static int outputSuggestions(const Scoring *const scoringPolicy,
DicTraverseSession *traverseSession, int *frequencies, int *outputCodePoints,
DicTraverseSession *traverseSession, int *outputScores, int *outputCodePoints,
int *outputIndicesToPartialCommit, int *outputTypes,
int *outputAutoCommitFirstWordConfidence);
@ -46,7 +46,7 @@ class SuggestionsOutputUtils {
static int outputShortcuts(BinaryDictionaryShortcutIterator *const shortcutIt,
int outputWordIndex, const int finalScore, int *const outputCodePoints,
int *const frequencies, int *const outputTypes, const bool sameAsTyped);
int *const outputScores, int *const outputTypes, const bool sameAsTyped);
};
} // namespace latinime
#endif // LATINIME_SUGGESTIONS_OUTPUT_UTILS

View file

@ -33,8 +33,8 @@ class Scoring {
virtual bool getMostProbableString(const DicTraverseSession *const traverseSession,
const int terminalSize, const float languageWeight, int *const outputCodePoints,
int *const type, int *const freq) const = 0;
virtual void safetyNetForMostProbableString(const int terminalSize,
const int maxScore, int *const outputCodePoints, int *const frequencies) const = 0;
virtual void safetyNetForMostProbableString(const int scoreCount,
const int maxScore, int *const outputCodePoints, int *const scores) const = 0;
virtual float getAdjustedLanguageWeight(DicTraverseSession *const traverseSession,
DicNode *const terminals, const int size) const = 0;
virtual float getDoubleLetterDemotionDistanceCost(

View file

@ -44,7 +44,7 @@ const int Suggest::MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE = 2;
*/
int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
int *inputXs, int *inputYs, int *times, int *pointerIds, int *inputCodePoints,
int inputSize, int commitPoint, int *outWords, int *frequencies, int *outputIndices,
int inputSize, int commitPoint, int *outWords, int *outputScores, int *outputIndices,
int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
PROF_OPEN;
PROF_START(0);
@ -66,7 +66,7 @@ int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
}
PROF_END(1);
PROF_START(2);
const int size = SuggestionsOutputUtils::outputSuggestions(SCORING, tSession, frequencies,
const int size = SuggestionsOutputUtils::outputSuggestions(SCORING, tSession, outputScores,
outWords, outputIndices, outputTypes, outputAutoCommitFirstWordConfidence);
PROF_END(2);
PROF_CLOSE;

View file

@ -48,7 +48,7 @@ class Suggest : public SuggestInterface {
AK_FORCE_INLINE virtual ~Suggest() {}
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint,
int *outWords, int *frequencies, int *outputIndices, int *outputTypes,
int *outWords, int *outputScores, int *outputIndices, int *outputTypes,
int *outputAutoCommitFirstWordConfidence) const;
private:

View file

@ -27,7 +27,7 @@ class SuggestInterface {
public:
virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs,
int *inputYs, int *times, int *pointerIds, int *inputCodePoints, int inputSize,
int commitPoint, int *outWords, int *frequencies, int *outputIndices,
int commitPoint, int *outWords, int *outputScores, int *outputIndices,
int *outputTypes, int *outputAutoCommitFirstWordConfidence) const = 0;
SuggestInterface() {}
virtual ~SuggestInterface() {}

View file

@ -39,8 +39,8 @@ class TypingScoring : public Scoring {
return false;
}
AK_FORCE_INLINE void safetyNetForMostProbableString(const int terminalSize,
const int maxScore, int *const outputCodePoints, int *const frequencies) const {
AK_FORCE_INLINE void safetyNetForMostProbableString(const int scoreCount,
const int maxScore, int *const outputCodePoints, int *const scores) const {
}
AK_FORCE_INLINE float getAdjustedLanguageWeight(DicTraverseSession *const traverseSession,