Initialize child_idx to fix warning

This commit is contained in:
lingsheng 2021-01-26 09:58:18 +08:00
parent 4dc3a15d7e
commit 19d0adfb0b
2 changed files with 48 additions and 1 deletions

View File

@ -0,0 +1,43 @@
From 721a48e5397bd4ab454482041e55671eae7b189f Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Mon, 11 May 2020 18:01:11 -0700
Subject: [PATCH] examples: Initialize child_idx
Assign UINT_MAX and assert it
Fixes warning
rtree_map.c:358:12: error: 'child_idx' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
src/examples/libpmemobj/tree_map/rtree_map.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/examples/libpmemobj/tree_map/rtree_map.c b/src/examples/libpmemobj/tree_map/rtree_map.c
index 995e22bb94..6b3ead65c2 100644
--- a/src/examples/libpmemobj/tree_map/rtree_map.c
+++ b/src/examples/libpmemobj/tree_map/rtree_map.c
@@ -8,6 +8,7 @@
#include <ex_common.h>
#include <assert.h>
#include <errno.h>
+#include <limits.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -320,12 +321,13 @@ has_only_one_child(TOID(struct tree_map_node) node, unsigned *child_idx)
static void
remove_extra_node(TOID(struct tree_map_node) *node)
{
- unsigned child_idx;
+ unsigned child_idx = UINT_MAX;
TOID(struct tree_map_node) tmp, tmp_child;
/* Our node has child with only one child. */
tmp = *node;
has_only_one_child(tmp, &child_idx);
+ assert(child_idx != UINT_MAX);
tmp_child = D_RO(tmp)->slots[child_idx];
/*

View File

@ -7,7 +7,7 @@
Name: nvml
Summary: Persistent Memory Development Kit (formerly NVML)
Version: 1.4.2
Release: 4
Release: 5
License: BSD
URL: http://pmem.io/pmdk
@ -90,6 +90,7 @@ Provides: librpmem-debug = %{version}-%{release}
Patch0000: fix-build-error.patch
Patch0001: delete-extra-tests.patch
Patch0002: Initialize-child_idx.patch
%description
The Persistent Memory Development Kit (PMDK), formerly known as NVML, is
@ -247,6 +248,9 @@ echo "PMEM_FS_DIR_FORCE_PMEM=1" >> src/test/testconfig.sh
%endif
%changelog
* Mon Jan 25 2021 lingsheng<lingsheng@huawei.com> - 1.4.2-5
- Initialize child_idx to fix warning
* Wed Aug 19 2020 lingsheng<lingsheng@huawei.com> - 1.4.2-4
- Disable check