From 19a515e314f809a14e02223bac08e28a7ed7d354 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 1 May 2016 17:46:25 +1000 Subject: [PATCH] library: Fix LINUX_VERSION macro The previous commit did not take into account operator evaluation order so always gave 0. Fixed the macro and added some checks for the macro. References: commit 9abf7d879d07c140a265b9f8efb642fdb5bd06b3 --- proc/test_version.c | 29 +++++++++++++++++++++++++++++ proc/version.h | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/proc/test_version.c b/proc/test_version.c index ba01925c..caa06775 100644 --- a/proc/test_version.c +++ b/proc/test_version.c @@ -30,7 +30,36 @@ int check_linux_version(void *data) return (procps_linux_version() > 0); } +int check_conversion(void *data) +{ + testname = "LINUX_VERSION macro"; + struct testvals { + int retval; + int major, minor, patch; + }; + + struct testvals *tv; + struct testvals tvs[] = { + { 132096, 2, 4, 0 }, + { 132635, 2, 6, 27 }, + { 199936, 3, 13, 0 }, + { 263426, 4, 5, 2 }, + { 0, 0, 0, 0} + }; + + for (tv=tvs; tv->major != 0; tv++) + { + if (LINUX_VERSION(tv->major, tv->minor, tv->patch) != tv->retval) { + fprintf(stderr, "Failed %d != %d\n", LINUX_VERSION(tv->major, tv->minor, + tv->patch), tv->retval); + return 0; + } + } + return 1; +} + TestFunction test_funcs[] = { + check_conversion, check_linux_version, NULL }; diff --git a/proc/version.h b/proc/version.h index 611b4a7f..3cde808c 100644 --- a/proc/version.h +++ b/proc/version.h @@ -29,7 +29,7 @@ __BEGIN_DECLS int procps_linux_version(void); /* Convenience macros for composing/decomposing version codes */ -#define LINUX_VERSION(x,y,z) (0x10000*((x)&0x7fff) + 0x100*((y)&0xff) + (z)&0xff) +#define LINUX_VERSION(x,y,z) (0x10000*((x)&0x7fff) + 0x100*((y)&0xff) + ((z)&0xff)) #define LINUX_VERSION_MAJOR(x) (((x)>>16) & 0xFF) #define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF) #define LINUX_VERSION_PATCH(x) ( (x) & 0xFF) -- 2.40.0