Commit 4e13e6d0 authored by Tommi Rantala's avatar Tommi Rantala

Unsigned sscanf() in kernel_version()

cppcheck was complaining:

[attached_probe.cpp:206]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'unsigned int *'.
[attached_probe.cpp:206]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.
[attached_probe.cpp:206]: (warning) %d in format string (no. 3) requires 'int *' but the argument type is 'unsigned int *'.

While at it, check uname() and sscanf() return values to avoid garbage.
parent fccdd364
......@@ -201,9 +201,11 @@ static unsigned kernel_version(int attempt)
return LINUX_VERSION_CODE;
case 1:
struct utsname utsname;
uname(&utsname);
if (uname(&utsname) < 0)
return 0;
unsigned x, y, z;
sscanf(utsname.release, "%d.%d.%d", &x, &y, &z);
if (sscanf(utsname.release, "%u.%u.%u", &x, &y, &z) != 3)
return 0;
return KERNEL_VERSION(x, y, z);
case 2:
// try to get the definition of LINUX_VERSION_CODE at runtime.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment