Merge pull request #1514 from stweil/cid

Fix two reports from Coverity Scan (Copy into fixed size buffer)
This commit is contained in:
zdenop 2018-04-23 13:08:58 +02:00 committed by GitHub
commit c0f9699e9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 9 deletions

View File

@ -83,6 +83,8 @@ const char* UNICHARSET::kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT] = {
"|Broken|0|1" "|Broken|0|1"
}; };
const char* UNICHARSET::null_script = "NULL";
UNICHARSET::UNICHAR_PROPERTIES::UNICHAR_PROPERTIES() { UNICHARSET::UNICHAR_PROPERTIES::UNICHAR_PROPERTIES() {
Init(); Init();
} }
@ -175,8 +177,7 @@ UNICHARSET::UNICHARSET() :
size_used(0), size_used(0),
size_reserved(0), size_reserved(0),
script_table(nullptr), script_table(nullptr),
script_table_size_used(0), script_table_size_used(0) {
null_script("NULL") {
clear(); clear();
for (int i = 0; i < SPECIAL_UNICHAR_CODES_COUNT; ++i) { for (int i = 0; i < SPECIAL_UNICHAR_CODES_COUNT; ++i) {
unichar_insert(kSpecialUnicharCodes[i]); unichar_insert(kSpecialUnicharCodes[i]);
@ -803,7 +804,7 @@ bool UNICHARSET::load_via_fgets(
unsigned int properties; unsigned int properties;
char script[64]; char script[64];
strcpy(script, null_script); strncpy(script, null_script, sizeof(script));
int min_bottom = 0; int min_bottom = 0;
int max_bottom = UINT8_MAX; int max_bottom = UINT8_MAX;
int min_top = 0; int min_top = 0;

View File

@ -1006,6 +1006,7 @@ class UNICHARSET {
// The substitutions clean up text that should exists for rendering of // The substitutions clean up text that should exists for rendering of
// synthetic data, but not in the recognition set. // synthetic data, but not in the recognition set.
static const char* kCleanupMaps[][2]; static const char* kCleanupMaps[][2];
static const char* null_script;
UNICHAR_SLOT* unichars; UNICHAR_SLOT* unichars;
UNICHARMAP ids; UNICHARMAP ids;
@ -1014,7 +1015,6 @@ class UNICHARSET {
char** script_table; char** script_table;
int script_table_size_used; int script_table_size_used;
int script_table_size_reserved; int script_table_size_reserved;
const char* null_script;
// True if the unichars have their tops/bottoms set. // True if the unichars have their tops/bottoms set.
bool top_bottom_set_; bool top_bottom_set_;
// True if the unicharset has significant upper/lower case chars. // True if the unicharset has significant upper/lower case chars.

View File

@ -614,8 +614,6 @@ void Dict::add_document_word(const WERD_CHOICE &best_choice) {
// the line is recognized. // the line is recognized.
if (hyphen_word_) return; if (hyphen_word_) return;
char filename[CHARS_PER_LINE];
FILE *doc_word_file;
int stringlen = best_choice.length(); int stringlen = best_choice.length();
if (valid_word(best_choice) || stringlen < 2) if (valid_word(best_choice) || stringlen < 2)
@ -653,9 +651,9 @@ void Dict::add_document_word(const WERD_CHOICE &best_choice) {
} }
if (save_doc_words) { if (save_doc_words) {
strcpy(filename, getCCUtil()->imagefile.string()); STRING filename(getCCUtil()->imagefile);
strcat(filename, ".doc"); filename += ".doc";
doc_word_file = open_file (filename, "a"); FILE *doc_word_file = open_file (filename.string(), "a");
fprintf(doc_word_file, "%s\n", fprintf(doc_word_file, "%s\n",
best_choice.debug_string().string()); best_choice.debug_string().string());
fclose(doc_word_file); fclose(doc_word_file);