]> granicus.if.org Git - libnl/commitdiff
Fix warning "not checking return value of fscanf" in lib/utils.c: get_psched_settings
authorКоренберг Марк (дома) <socketpair@gmail.com>
Wed, 29 Aug 2012 18:47:09 +0000 (00:47 +0600)
committerКоренберг Марк (дома) <socketpair@gmail.com>
Wed, 29 Aug 2012 21:19:04 +0000 (03:19 +0600)
Also, change internal variables type from uint32_t to unsigned int.
Correct scanf format string should contain "SCNx32" instead of just "x",
but I decide not to fix that and just changed variable type.

lib/utils.c

index 74f5639df143be8fc8fa230c5d6e6b1c905bae63..b5e32c3c2dcc61346f7819c533c1fd448eb8769d 100644 (file)
@@ -28,6 +28,7 @@
 #include <netlink/netlink.h>
 #include <netlink/utils.h>
 #include <linux/socket.h>
+#include <stdlib.h> /* exit() */
 
 /**
  * Global variable indicating the desired level of debugging output.
@@ -421,10 +422,15 @@ static void __init get_psched_settings(void)
                        strncpy(name, "/proc/net/psched", sizeof(name) - 1);
                
                if ((fd = fopen(name, "r"))) {
-                       uint32_t ns_per_usec, ns_per_tick, nom, denom;
-
-                       fscanf(fd, "%08x %08x %08x %08x",
-                              &ns_per_usec, &ns_per_tick, &nom, &denom);
+                       unsigned int ns_per_usec, ns_per_tick, nom, denom;
+
+                       if (fscanf(fd, "%08x %08x %08x %08x",
+                              &ns_per_usec, &ns_per_tick, &nom, &denom) != 4) {
+                            fprintf(stderr, "Fatal error: can not read psched settings from \"%s\". " \
+                                    "Try to set TICKS_PER_USEC, PROC_NET_PSCHED or PROC_ROOT " \
+                                    "environment variables\n", name);
+                            exit(1);
+                        }
 
                        ticks_per_usec = (double) ns_per_usec / 
                                         (double) ns_per_tick;