Fix warnings about ignoring fread() return value

This commit is contained in:
Jean-Marc Valin 2021-08-02 18:37:19 -04:00
parent 6ea726d401
commit cba0ecd483
2 changed files with 20 additions and 11 deletions

View file

@ -205,12 +205,17 @@ int main(int argc, char **argv) {
while (1) { while (1) {
float E=0; float E=0;
int silent; int silent;
size_t ret;
for (i=0;i<FRAME_SIZE;i++) x[i] = tmp[i]; for (i=0;i<FRAME_SIZE;i++) x[i] = tmp[i];
fread(tmp, sizeof(short), FRAME_SIZE, f1); ret = fread(tmp, sizeof(short), FRAME_SIZE, f1);
if (feof(f1)) { if (feof(f1) || ret != FRAME_SIZE) {
if (!training) break; if (!training) break;
rewind(f1); rewind(f1);
fread(tmp, sizeof(short), FRAME_SIZE, f1); ret = fread(tmp, sizeof(short), FRAME_SIZE, f1);
if (ret != FRAME_SIZE) {
fprintf(stderr, "error reading\n");
exit(1);
}
one_pass_completed = 1; one_pass_completed = 1;
} }
for (i=0;i<FRAME_SIZE;i++) E += tmp[i]*(float)tmp[i]; for (i=0;i<FRAME_SIZE;i++) E += tmp[i]*(float)tmp[i];

View file

@ -75,8 +75,9 @@ int main(int argc, char **argv) {
while (1) { while (1) {
unsigned char buf[LPCNET_COMPRESSED_SIZE]; unsigned char buf[LPCNET_COMPRESSED_SIZE];
short pcm[LPCNET_PACKET_SAMPLES]; short pcm[LPCNET_PACKET_SAMPLES];
fread(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fin); size_t ret;
if (feof(fin)) break; ret = fread(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fin);
if (feof(fin) || ret != LPCNET_PACKET_SAMPLES) break;
lpcnet_encode(net, pcm, buf); lpcnet_encode(net, pcm, buf);
fwrite(buf, 1, LPCNET_COMPRESSED_SIZE, fout); fwrite(buf, 1, LPCNET_COMPRESSED_SIZE, fout);
} }
@ -87,8 +88,9 @@ int main(int argc, char **argv) {
while (1) { while (1) {
unsigned char buf[LPCNET_COMPRESSED_SIZE]; unsigned char buf[LPCNET_COMPRESSED_SIZE];
short pcm[LPCNET_PACKET_SAMPLES]; short pcm[LPCNET_PACKET_SAMPLES];
fread(buf, sizeof(buf[0]), LPCNET_COMPRESSED_SIZE, fin); size_t ret;
if (feof(fin)) break; ret = fread(buf, sizeof(buf[0]), LPCNET_COMPRESSED_SIZE, fin);
if (feof(fin) || ret != LPCNET_COMPRESSED_SIZE) break;
lpcnet_decode(net, buf, pcm); lpcnet_decode(net, buf, pcm);
fwrite(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fout); fwrite(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fout);
} }
@ -99,8 +101,9 @@ int main(int argc, char **argv) {
while (1) { while (1) {
float features[4][NB_TOTAL_FEATURES]; float features[4][NB_TOTAL_FEATURES];
short pcm[LPCNET_PACKET_SAMPLES]; short pcm[LPCNET_PACKET_SAMPLES];
fread(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fin); size_t ret;
if (feof(fin)) break; ret = fread(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fin);
if (feof(fin) || ret != LPCNET_PACKET_SAMPLES) break;
lpcnet_compute_features(net, pcm, features); lpcnet_compute_features(net, pcm, features);
fwrite(features, sizeof(float), 4*NB_TOTAL_FEATURES, fout); fwrite(features, sizeof(float), 4*NB_TOTAL_FEATURES, fout);
} }
@ -112,8 +115,9 @@ int main(int argc, char **argv) {
float in_features[NB_TOTAL_FEATURES]; float in_features[NB_TOTAL_FEATURES];
float features[NB_FEATURES]; float features[NB_FEATURES];
short pcm[LPCNET_FRAME_SIZE]; short pcm[LPCNET_FRAME_SIZE];
fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin); size_t ret;
if (feof(fin)) break; ret = fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin);
if (feof(fin) || ret != NB_TOTAL_FEATURES) break;
RNN_COPY(features, in_features, NB_FEATURES); RNN_COPY(features, in_features, NB_FEATURES);
lpcnet_synthesize(net, features, pcm, LPCNET_FRAME_SIZE); lpcnet_synthesize(net, features, pcm, LPCNET_FRAME_SIZE);
fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout); fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout);