Skip to content

Commit

Permalink
Merge pull request #1514 from stweil/cid
Browse files Browse the repository at this point in the history
 Fix two reports from Coverity Scan (Copy into fixed size buffer)
  • Loading branch information
zdenop authored Apr 23, 2018
2 parents acbd333 + 68450d8 commit c0f9699
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
7 changes: 4 additions & 3 deletions ccutil/unicharset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const char* UNICHARSET::kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT] = {
"|Broken|0|1"
};

const char* UNICHARSET::null_script = "NULL";

UNICHARSET::UNICHAR_PROPERTIES::UNICHAR_PROPERTIES() {
Init();
}
Expand Down Expand Up @@ -175,8 +177,7 @@ UNICHARSET::UNICHARSET() :
size_used(0),
size_reserved(0),
script_table(nullptr),
script_table_size_used(0),
null_script("NULL") {
script_table_size_used(0) {
clear();
for (int i = 0; i < SPECIAL_UNICHAR_CODES_COUNT; ++i) {
unichar_insert(kSpecialUnicharCodes[i]);
Expand Down Expand Up @@ -803,7 +804,7 @@ bool UNICHARSET::load_via_fgets(
unsigned int properties;
char script[64];

strcpy(script, null_script);
strncpy(script, null_script, sizeof(script));
int min_bottom = 0;
int max_bottom = UINT8_MAX;
int min_top = 0;
Expand Down
2 changes: 1 addition & 1 deletion ccutil/unicharset.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ class UNICHARSET {
// The substitutions clean up text that should exists for rendering of
// synthetic data, but not in the recognition set.
static const char* kCleanupMaps[][2];
static const char* null_script;

UNICHAR_SLOT* unichars;
UNICHARMAP ids;
Expand All @@ -1014,7 +1015,6 @@ class UNICHARSET {
char** script_table;
int script_table_size_used;
int script_table_size_reserved;
const char* null_script;
// True if the unichars have their tops/bottoms set.
bool top_bottom_set_;
// True if the unicharset has significant upper/lower case chars.
Expand Down
8 changes: 3 additions & 5 deletions dict/dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,6 @@ void Dict::add_document_word(const WERD_CHOICE &best_choice) {
// the line is recognized.
if (hyphen_word_) return;

char filename[CHARS_PER_LINE];
FILE *doc_word_file;
int stringlen = best_choice.length();

if (valid_word(best_choice) || stringlen < 2)
Expand Down Expand Up @@ -653,9 +651,9 @@ void Dict::add_document_word(const WERD_CHOICE &best_choice) {
}

if (save_doc_words) {
strcpy(filename, getCCUtil()->imagefile.string());
strcat(filename, ".doc");
doc_word_file = open_file (filename, "a");
STRING filename(getCCUtil()->imagefile);
filename += ".doc";
FILE *doc_word_file = open_file (filename.string(), "a");
fprintf(doc_word_file, "%s\n",
best_choice.debug_string().string());
fclose(doc_word_file);
Expand Down

0 comments on commit c0f9699

Please sign in to comment.