[PATCH:libXfont 1/2] Check if pointer returned by BufFileCreate is NULL before writing to it

Alan Coopersmith alan.coopersmith at oracle.com
Sun Apr 20 18:23:39 PDT 2014


Fixes clang analyzer warning:

bufio.c:165:13: warning: Access to field 'bufp' results in a dereference
 of a null pointer (loaded from variable 'f')
    f->bufp = f->buffer;
    ~       ^

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/fontfile/bufio.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/fontfile/bufio.c b/src/fontfile/bufio.c
index 34b7f36..d8d4f29 100644
--- a/src/fontfile/bufio.c
+++ b/src/fontfile/bufio.c
@@ -162,8 +162,10 @@ BufFileOpenWrite (int fd)
     setmode(fd,O_BINARY);
 #endif
     f = BufFileCreate ((char *)(long) fd, 0, BufFileRawFlush, 0, BufFileFlush);
-    f->bufp = f->buffer;
-    f->left = BUFFILESIZE;
+    if (f != NULL) {
+	f->bufp = f->buffer;
+	f->left = BUFFILESIZE;
+    }
     return f;
 }
 
-- 
1.7.9.2



More information about the xorg-devel mailing list