[PATCH:xkbcomp 2/4] Don't dereference the pointer whose allocation failed

Alan Coopersmith alan.coopersmith at oracle.com
Sat Mar 8 19:10:26 PST 2014


Flagged by cppcheck 1.64:
[app/xkbcomp/keycodes.c:264] -> [app/xkbcomp/keycodes.c:262]:
 (warning) Possible null pointer dereference: new - otherwise it
           is redundant to check it against null.
[app/xkbcomp/keytypes.c:600] -> [app/xkbcomp/keytypes.c:597]:
 (warning) Possible null pointer dereference: old - otherwise it
           is redundant to check it against null.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 keycodes.c |    2 +-
 keytypes.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/keycodes.c b/keycodes.c
index 13579ec..22d9eae 100644
--- a/keycodes.c
+++ b/keycodes.c
@@ -261,7 +261,7 @@ AddIndicatorName(KeyNamesInfo * info, IndicatorNameInfo * new)
     new = NextIndicatorName(info);
     if (!new)
     {
-        WSGO1("Couldn't allocate name for indicator %d\n", new->ndx);
+        WSGO1("Couldn't allocate name for indicator %d\n", old->ndx);
         ACTION("Ignored\n");
         return False;
     }
diff --git a/keytypes.c b/keytypes.c
index 375ca3e..103d860 100644
--- a/keytypes.c
+++ b/keytypes.c
@@ -597,7 +597,7 @@ AddPreserve(XkbDescPtr xkb,
     if (!old)
     {
         WSGO1("Couldn't allocate preserve in %s\n", TypeTxt(type));
-        ACTION1("Preserve[%s] lost\n", PreserveIndexTxt(type, xkb, old));
+        ACTION1("Preserve[%s] lost\n", PreserveIndexTxt(type, xkb, new));
         return False;
     }
     *old = *new;
-- 
1.7.9.2



More information about the xorg-devel mailing list