From fdf8e1f595b45337b7d12ab6ac9faf6040fe913c Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 5 Mar 2017 20:52:28 +0000 Subject: include: fix compiler warning ./include/optutils.h:12:18: warning: null pointer dereference [-Wnull-dereference] for (o = opts; o->name; o++) ~^~~~~~ In file included from libfdisk/src/dos.c:12:0: ./include/pt-mbr.h:25:47: warning: potential null pointer dereference [-Wnull-dereference] return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); ~^~~ Well these should be impossible, so add assert() to catch possible bugs. Signed-off-by: Sami Kerola --- include/optutils.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/optutils.h') diff --git a/include/optutils.h b/include/optutils.h index 99ad7e4b4..325cb8812 100644 --- a/include/optutils.h +++ b/include/optutils.h @@ -1,6 +1,8 @@ #ifndef UTIL_LINUX_OPTUTILS_H #define UTIL_LINUX_OPTUTILS_H +#include + #include "c.h" #include "nls.h" @@ -8,6 +10,7 @@ static inline const char *option_to_longopt(int c, const struct option *opts) { const struct option *o; + assert(!(opts == NULL)); for (o = opts; o->name; o++) if (o->val == c) return o->name; -- cgit v1.2.3-55-g7522