Blame SOURCES/0006-fix-src-dmierror.c-55-9-warning-Wanalyzer-possible-n.patch

ab0dbe
From fa5f62272997ea5b402ce28c2b197afe1a3c9422 Mon Sep 17 00:00:00 2001
ab0dbe
From: Coiby Xu <coiby.xu@gmail.com>
ab0dbe
Date: Tue, 15 Jun 2021 10:57:45 +0800
ab0dbe
Subject: [PATCH 6/8] fix "src/dmierror.c:55:9:
ab0dbe
 warning[-Wanalyzer-possible-null-argument]: use of possibly-NULL buf where
ab0dbe
 non-null expected"
ab0dbe
ab0dbe
Fix the following error found by covscan,
ab0dbe
    python-dmidecode-3.12.2/src/dmierror.c:55:9: warning[-Wanalyzer-possible-null-argument]: use of possibly-NULL buf where non-null expected
ab0dbe
    /usr/include/python3.9/Python.h:30: included_from: Included from here.
ab0dbe
    python-dmidecode-3.12.2/src/dmierror.c:32: included_from: Included from here.
ab0dbe
    /usr/include/string.h:61:14: note: argument 1 of memset must be non-null
ab0dbe
    #   53|           va_start(ap, fmt);
ab0dbe
    #   54|           buf = (char *) malloc(4098);
ab0dbe
    #   55|->         memset(buf, 0, 4098);
ab0dbe
    #   56|
ab0dbe
    #   57|           if( buf == NULL ) {
ab0dbe
ab0dbe
Signed-off-by: Coiby Xu <coiby.xu@gmail.com>
ab0dbe
---
ab0dbe
 src/dmierror.c | 2 +-
ab0dbe
 1 file changed, 1 insertion(+), 1 deletion(-)
ab0dbe
ab0dbe
diff --git a/src/dmierror.c b/src/dmierror.c
ab0dbe
index d64b4b9..7054cd8 100644
ab0dbe
--- a/src/dmierror.c
ab0dbe
+++ b/src/dmierror.c
ab0dbe
@@ -52,7 +52,6 @@ void _pyReturnError(void *exception, const char *fname, int line, const char *fm
ab0dbe
 
ab0dbe
         va_start(ap, fmt);
ab0dbe
         buf = (char *) malloc(4098);
ab0dbe
-        memset(buf, 0, 4098);
ab0dbe
 
ab0dbe
         if( buf == NULL ) {
ab0dbe
                 // Backup routine if we can't get the needed memory
ab0dbe
@@ -64,6 +63,7 @@ void _pyReturnError(void *exception, const char *fname, int line, const char *fm
ab0dbe
                 return;
ab0dbe
         }
ab0dbe
 
ab0dbe
+        memset(buf, 0, 4098);
ab0dbe
         // Set the error state and message
ab0dbe
         snprintf(buf, 4096, "[%s:%i] %s", fname, line, fmt);
ab0dbe
         PyErr_Format(exception, buf, ap);
ab0dbe
-- 
ab0dbe
2.31.1
ab0dbe