libratbag-util: check the return value of scanf

This commit is contained in:
Yaroslav Chvanov
2023-02-25 00:02:38 +03:00
parent 3730e4d48a
commit e9e9d8e3fe

View File

@@ -277,6 +277,7 @@ dpi_list_from_string(const char *str)
struct dpi_list *list;
unsigned int i, count, index;
int nread, dpi = 0;
int rc = 0;
char c;
void *tmp;
@@ -305,8 +306,8 @@ dpi_list_from_string(const char *str)
}
nread = 0;
sscanf(str, "%d%n", &dpi, &nread);
if (!nread || dpi < 0)
rc = sscanf(str, "%d%n", &dpi, &nread);
if (rc != 1 || !nread || dpi < 0)
goto err;
list->entries[index] = dpi;