]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include: fix compiler warning
authorSami Kerola <kerolasa@iki.fi>
Sun, 5 Mar 2017 20:52:28 +0000 (20:52 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Mar 2017 13:48:14 +0000 (14:48 +0100)
./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 <kerolasa@iki.fi>
include/optutils.h
include/pt-mbr.h

index 99ad7e4b425404bf43c6f936d91b6f4882ac1f1d..325cb881272c2a2dfbccd780500caabbc9aa8596 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef UTIL_LINUX_OPTUTILS_H
 #define UTIL_LINUX_OPTUTILS_H
 
+#include <assert.h>
+
 #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;
index 90be95b1fafbf702941e3ea5ee261054b1adda0a..177cc747485ef102a4868187f8f18354b34d64c1 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef UTIL_LINUX_PT_MBR_H
 #define UTIL_LINUX_PT_MBR_H
 
+#include <assert.h>
+
 struct dos_partition {
        unsigned char boot_ind;         /* 0x80 - active */
        unsigned char bh, bs, bc;       /* begin CHS */
@@ -27,6 +29,7 @@ static inline unsigned int __dos_assemble_4le(const unsigned char *p)
 
 static inline void __dos_store_4le(unsigned char *p, unsigned int val)
 {
+       assert(!(p == NULL));
        p[0] = (val & 0xff);
        p[1] = ((val >> 8) & 0xff);
        p[2] = ((val >> 16) & 0xff);