eqctl: do not process invalid input file name

Fixes seg faults when input file does not exist.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
This commit is contained in:
Ranjani Sridharan 2018-10-01 11:12:08 -07:00
parent 4c9498a8ac
commit e4171c89f8
1 changed files with 7 additions and 0 deletions

View File

@ -31,6 +31,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#define SOF_CTRL_CMD_BINARY 3 /* TODO: From uapi ipc */ #define SOF_CTRL_CMD_BINARY 3 /* TODO: From uapi ipc */
@ -64,7 +65,13 @@ static int read_setup(unsigned int *data, char setup[], size_t smax)
int n_max = smax / sizeof(unsigned int); int n_max = smax / sizeof(unsigned int);
int separator; int separator;
/* open input file */
fh = fopen(setup, "r"); fh = fopen(setup, "r");
if (!fh) {
fprintf(stderr, "error: %s\n", strerror(errno));
return -errno;
}
while (fscanf(fh, "%u", &data[n]) != EOF && n < n_max) { while (fscanf(fh, "%u", &data[n]) != EOF && n < n_max) {
if (n > 0) if (n > 0)
fprintf(stdout, ","); fprintf(stdout, ",");