util-linux/libuuid-ensure-variable-is-initialized-cppcheck.patch

49 lines
1.7 KiB
Diff

From 3c92864ecd755286b8a743d8ac3388e67ae8598c Mon Sep 17 00:00:00 2001
From: Sami Kerola <kerolasa@iki.fi>
Date: Sat, 29 Feb 2020 08:51:53 +0000
Subject: [PATCH 179/389] libuuid: ensure variable is initialized [cppcheck]
This fix has a little bit of a feel of making a static analyzer to be happy
instead of real progress. If I read the preprocessor directives correctly
it should be impossible hit uninitialized variable. Then again if a bug
creeps into these ifdef's in that case it is nice to have robust code that
doesn't immediately go wrong.
libuuid/src/gen_uuid.c:200:20: error: Uninitialized variable: a [uninitvar]
memcpy(node_id, a, 6);
^
libuuid/src/gen_uuid.c:197:8: error: Uninitialized variable: a [uninitvar]
if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
^
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
libuuid/src/gen_uuid.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c
index 27c135d..69f9591 100644
--- a/libuuid/src/gen_uuid.c
+++ b/libuuid/src/gen_uuid.c
@@ -136,7 +136,7 @@ static int get_node_id(unsigned char *node_id)
struct ifconf ifc;
char buf[1024];
int n, i;
- unsigned char *a;
+ unsigned char *a = NULL;
#ifdef HAVE_NET_IF_DL_H
struct sockaddr_dl *sdlp;
#endif
@@ -194,7 +194,7 @@ static int get_node_id(unsigned char *node_id)
#endif /* HAVE_NET_IF_DL_H */
#endif /* SIOCGENADDR */
#endif /* SIOCGIFHWADDR */
- if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
+ if (a == NULL || (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5]))
continue;
if (node_id) {
memcpy(node_id, a, 6);
--
1.8.3.1