Fix CID 1393238 (Dereference null return value)

Add also some error handling if fopen fails.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-06-20 19:47:38 +02:00
parent 27a5908a55
commit 09976e6125

View File

@ -128,8 +128,12 @@ bool Tesseract::ProcessTargetWord(const TBOX& word_box,
if (backup_config_file_ == nullptr) { if (backup_config_file_ == nullptr) {
backup_config_file_ = kBackUpConfigFile; backup_config_file_ = kBackUpConfigFile;
FILE* config_fp = fopen(backup_config_file_, "wb"); FILE* config_fp = fopen(backup_config_file_, "wb");
if (config_fp == nullptr) {
tprintf("Error, failed to open file \"%s\"\n", backup_config_file_);
} else {
ParamUtils::PrintParams(config_fp, params()); ParamUtils::PrintParams(config_fp, params());
fclose(config_fp); fclose(config_fp);
}
ParamUtils::ReadParamsFile(word_config, ParamUtils::ReadParamsFile(word_config,
SET_PARAM_CONSTRAINT_DEBUG_ONLY, SET_PARAM_CONSTRAINT_DEBUG_ONLY,
params()); params());