iio: Check for fscanf() return values
Fixes the build on Ubuntu systems. Closes: #248
This commit is contained in:
@@ -125,7 +125,7 @@ iioutils_get_type (unsigned *is_signed,
|
||||
bits_used,
|
||||
&padint, shift);
|
||||
|
||||
if (ret < 0) {
|
||||
if (ret < 0 || ret != 5) {
|
||||
g_warning ("Failed to pass scan type description for %s", filename);
|
||||
fclose (sysfsfp);
|
||||
g_free (filename);
|
||||
@@ -168,10 +168,11 @@ iioutils_get_param_float (float *output,
|
||||
|
||||
sysfsfp = fopen (filename, "r");
|
||||
if (sysfsfp) {
|
||||
fscanf (sysfsfp, "%f", output);
|
||||
ret = fscanf (sysfsfp, "%f", output);
|
||||
fclose (sysfsfp);
|
||||
g_free (filename);
|
||||
return 0;
|
||||
if (ret == 1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = -errno;
|
||||
@@ -260,13 +261,13 @@ build_channel_array (const char *device_dir,
|
||||
g_free (filename);
|
||||
continue;
|
||||
}
|
||||
fscanf (sysfsfp, "%d", &ret);
|
||||
fclose (sysfsfp);
|
||||
if (!ret) {
|
||||
if (fscanf (sysfsfp, "%d", &ret) != 1) {
|
||||
fclose (sysfsfp);
|
||||
g_debug ("Could not read from scan_elements file '%s'", filename);
|
||||
g_free (filename);
|
||||
continue;
|
||||
}
|
||||
fclose (sysfsfp);
|
||||
g_free (filename);
|
||||
|
||||
current = g_new0 (iio_channel_info, 1);
|
||||
@@ -284,13 +285,13 @@ build_channel_array (const char *device_dir,
|
||||
g_free (index_name);
|
||||
|
||||
sysfsfp = fopen (filename, "r");
|
||||
if (sysfsfp == NULL) {
|
||||
ret = -errno;
|
||||
if (sysfsfp == NULL)
|
||||
goto error;
|
||||
}
|
||||
fscanf (sysfsfp, "%u", ¤t->index);
|
||||
ret = fscanf (sysfsfp, "%u", ¤t->index);
|
||||
fclose (sysfsfp);
|
||||
g_free (filename);
|
||||
if (ret != 1)
|
||||
goto error;
|
||||
|
||||
/* Find the scale */
|
||||
ret = iioutils_get_param_float (¤t->scale,
|
||||
@@ -383,8 +384,8 @@ _write_sysfs_int (const char *filename,
|
||||
ret = -errno;
|
||||
goto error_free;
|
||||
}
|
||||
fscanf(sysfsfp, "%d", &test);
|
||||
if (test != val) {
|
||||
if (fscanf(sysfsfp, "%d", &test) != 1 ||
|
||||
test != val) {
|
||||
g_warning ("Possible failure in int write %d to %s",
|
||||
val, temp);
|
||||
ret = -1;
|
||||
@@ -431,8 +432,8 @@ _write_sysfs_string (const char *filename,
|
||||
ret = -errno;
|
||||
goto error_free;
|
||||
}
|
||||
fscanf(sysfsfp, "%s", temp);
|
||||
if (strcmp(temp, val) != 0) {
|
||||
if (fscanf(sysfsfp, "%s", temp) != 1 ||
|
||||
strcmp(temp, val) != 0) {
|
||||
g_warning ("Possible failure in string write of %s Should be %s written to %s\\%s\n",
|
||||
temp, val, basedir, filename);
|
||||
ret = -1;
|
||||
|
Reference in New Issue
Block a user