Merge pull request #508 from stweil/cube

cube: Fix issues reported by Coverity scan
This commit is contained in:
Egor Pugin 2016-11-30 00:58:47 +03:00 committed by GitHub
commit 0d4d36f058
2 changed files with 13 additions and 2 deletions

View File

@ -179,14 +179,14 @@ int CharBigrams::Cost(const char_32 *char_32_ptr, CharSet *char_set) const {
if (lower_32 && lower_32[0] != 0) {
int cost_lower = MeanCostWithSpaces(lower_32);
cost = MIN(cost, cost_lower);
delete [] lower_32;
}
delete [] lower_32;
char_32 *upper_32 = CubeUtils::ToUpper(char_32_ptr, char_set);
if (upper_32 && upper_32[0] != 0) {
int cost_upper = MeanCostWithSpaces(upper_32);
cost = MIN(cost, cost_upper);
delete [] upper_32;
}
delete [] upper_32;
}
return cost;
}

View File

@ -112,6 +112,7 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) {
// read label
if (fp->Read(label32, val32 * sizeof(*label32)) !=
(val32 * sizeof(*label32))) {
delete [] label32;
return NULL;
}
// null terminate
@ -121,33 +122,42 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) {
}
// read coordinates
if (fp->Read(&page, sizeof(page)) != sizeof(page)) {
delete [] label32;
return NULL;
}
if (fp->Read(&left, sizeof(left)) != sizeof(left)) {
delete [] label32;
return NULL;
}
if (fp->Read(&top, sizeof(top)) != sizeof(top)) {
delete [] label32;
return NULL;
}
if (fp->Read(&first_char, sizeof(first_char)) != sizeof(first_char)) {
delete [] label32;
return NULL;
}
if (fp->Read(&last_char, sizeof(last_char)) != sizeof(last_char)) {
delete [] label32;
return NULL;
}
if (fp->Read(&norm_top, sizeof(norm_top)) != sizeof(norm_top)) {
delete [] label32;
return NULL;
}
if (fp->Read(&norm_bottom, sizeof(norm_bottom)) != sizeof(norm_bottom)) {
delete [] label32;
return NULL;
}
if (fp->Read(&norm_aspect_ratio, sizeof(norm_aspect_ratio)) !=
sizeof(norm_aspect_ratio)) {
delete [] label32;
return NULL;
}
// create the object
CharSamp *char_samp = new CharSamp();
if (char_samp == NULL) {
delete [] label32;
return NULL;
}
// init
@ -163,6 +173,7 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) {
// load the Bmp8 part
if (char_samp->LoadFromCharDumpFile(fp) == false) {
delete char_samp;
delete [] label32;
return NULL;
}
return char_samp;