diff mbox series

[23/47] libsemanage: simplify malloc plus strcpy via strndup

Message ID 20241111141706.38039-23-cgoettsche@seltendoof.de (mailing list archive)
State New
Delegated to: Petr Lautrbach
Headers show
Series [01/47] libsemanage: white space cleanup | expand

Commit Message

Christian Göttsche Nov. 11, 2024, 2:16 p.m. UTC
From: Christian Göttsche <cgzones@googlemail.com>

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsemanage/src/parse_utils.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libsemanage/src/parse_utils.c b/libsemanage/src/parse_utils.c
index d9b12763..d3bc148b 100644
--- a/libsemanage/src/parse_utils.c
+++ b/libsemanage/src/parse_utils.c
@@ -290,14 +290,12 @@  int parse_fetch_string(semanage_handle_t * handle,
 		goto err;
 	}
 
-	tmp_str = (char *)malloc(len + 1);
+	tmp_str = strndup(start, len);
 	if (!tmp_str) {
 		ERR(handle, "out of memory");
 		goto err;
 	}
 
-	strncpy(tmp_str, start, len);
-	*(tmp_str + len) = '\0';
 	*str = tmp_str;
 	return STATUS_SUCCESS;