]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hexdump: make code more robust
authorKarel Zak <kzak@redhat.com>
Thu, 2 Feb 2012 14:34:08 +0000 (15:34 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 2 Feb 2012 14:34:08 +0000 (15:34 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/parse.c

index e41b4a0c74a2dede384ea5e913cf022cd4018fd7..481db6d3eea7ca50d35410e621bfe833fae6b6d7 100644 (file)
@@ -80,7 +80,7 @@ void addfile(char *name)
 void add(const char *fmt)
 {
        const char *p;
-       static FS **nextfs;
+       static FS **nextfs = NULL;
        FS *tfs;
        FU *tfu, **nextfu;
        const char *savep;
@@ -89,8 +89,9 @@ void add(const char *fmt)
        tfs = xcalloc(1, sizeof(FS));
        if (!fshead)
                fshead = tfs;
-       else
+       else if (nextfs)
                *nextfs = tfs;
+
        nextfs = &tfs->nextfs;
        nextfu = &tfs->nextfu;
 
@@ -222,7 +223,7 @@ void rewrite(FS *fs)
                        pr = xcalloc(1, sizeof(PR));
                        if (!fu->nextpr)
                                fu->nextpr = pr;
-                       else
+                       else if (nextpr)
                                *nextpr = pr;
 
                        /* Skip preceding text and up to the next % sign. */