ref: a72a4c8b91dd7e0cd644963fe2a50fb07685e4d6
parent: 876907a5306fc8c41536403185e3cafa23a2c7ed
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Feb 8 19:42:10 EST 2022
audio/flacdec: handle read errors properly to avoid endless looping saturating cpu
--- a/sys/src/cmd/audio/flacdec/flacdec.c
+++ b/sys/src/cmd/audio/flacdec/flacdec.c
@@ -25,10 +25,11 @@
int n = *bytes;
n = fread(buffer, 1, n, stdin);
- if(n < 0)
+ if(n < 1){
+ if(feof(stdin))
+ return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
- if(n == 0)
- return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ }
*bytes = n;
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;