Use the error.h API in LoadEnvelope and check more return values. [Coverity]

This commit is contained in:
Reece H. Dunn
2016-01-22 07:31:34 +00:00
parent ebb052a808
commit 7ea2cf784d
+10 -8
View File
@@ -1381,16 +1381,18 @@ static int LoadWavefile(FILE *f, const char *fname)
return displ | 0x800000; // set bit 23 to indicate a wave file rather than a spectrum return displ | 0x800000; // set bit 23 to indicate a wave file rather than a spectrum
} }
static int LoadEnvelope(FILE *f, const char *fname) static espeak_ng_STATUS LoadEnvelope(FILE *f, const char *fname, int *displ)
{ {
int displ;
char buf[128]; char buf[128];
displ = ftell(f_phdata); if (displ)
*displ = ftell(f_phdata);
fseek(f, 12, SEEK_SET); if (fseek(f, 12, SEEK_SET) == -1)
if (fread(buf, 128, 1, f) == 0) return errno;
error("Failed to read envelope: %s", fname);
if (fread(buf, 128, 1, f) != 128)
return errno;
fwrite(buf, 128, 1, f_phdata); fwrite(buf, 128, 1, f_phdata);
if (n_envelopes < N_ENVELOPES) { if (n_envelopes < N_ENVELOPES) {
@@ -1399,7 +1401,7 @@ static int LoadEnvelope(FILE *f, const char *fname)
n_envelopes++; n_envelopes++;
} }
return displ; return ENS_OK;
} }
// Generate a hash code from the specified string // Generate a hash code from the specified string
@@ -1535,7 +1537,7 @@ static espeak_ng_STATUS LoadDataFile(const char *path, int control, int *addr)
*addr = LoadWavefile(f, path); *addr = LoadWavefile(f, path);
type_code = 'W'; type_code = 'W';
} else if (id == 0x43544950) { } else if (id == 0x43544950) {
*addr = LoadEnvelope(f, path); status = LoadEnvelope(f, path, addr);
type_code = 'E'; type_code = 'E';
} else if (id == 0x45564E45) { } else if (id == 0x45564E45) {
*addr = LoadEnvelope2(f, path); *addr = LoadEnvelope2(f, path);