From a2b23ffe458f7353eacb92cbe3dd29aa21dc195b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?utf8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=28=D0=B4=D0=BE=D0=BC=D0=B0=29?= Date: Thu, 30 Aug 2012 00:47:09 +0600 Subject: [PATCH] Fix warning "not checking return value of fscanf" in lib/utils.c: get_psched_settings 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 74f5639..b5e32c3 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -28,6 +28,7 @@ #include #include #include +#include /* 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; -- 2.40.0