mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-18 06:30:14 +08:00
Fix free of buffer which was not allocated
Coverity bug report: CID 1270420 "Free of address-of expression" Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
198ee0a820
commit
6f1142080a
@ -279,17 +279,22 @@ PROTOSTYLE ReadProtoStyle(FILE *File) {
|
||||
* @note History: 6/6/89, DSJ, Created.
|
||||
*/
|
||||
FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
|
||||
bool needs_free = false;
|
||||
int i;
|
||||
int NumFloatsRead;
|
||||
|
||||
if (Buffer == NULL)
|
||||
if (Buffer == NULL) {
|
||||
Buffer = reinterpret_cast<FLOAT32*>(Emalloc(N * sizeof(FLOAT32)));
|
||||
needs_free = true;
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
NumFloatsRead = tfscanf(File, "%f", &(Buffer[i]));
|
||||
if (NumFloatsRead != 1) {
|
||||
if ((NumFloatsRead == EOF) && (i == 0)) {
|
||||
Efree(Buffer);
|
||||
if (needs_free) {
|
||||
Efree(Buffer);
|
||||
}
|
||||
return NULL;
|
||||
} else {
|
||||
DoError(ILLEGALFLOAT, "Illegal float specification");
|
||||
|
Loading…
Reference in New Issue
Block a user