summaryrefslogtreecommitdiff
path: root/usr.bin/make/make_malloc.c
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-08-20 06:35:14 +0000
committerrillig <rillig@NetBSD.org>2020-08-20 06:35:14 +0000
commit85ff1f3f95c9e3628312b799a7d889604bfdb8e9 (patch)
tree0028d4c80dc847068e1e14fc7e095b4d511dc3de /usr.bin/make/make_malloc.c
parentb01a3dadfd0c9e1e7793824ec750da8bdbd95bc4 (diff)
make(1): remove unreached code from bmake_strndup
The "at most" branch was never taken since all call sites in var.c only ever need a substring, and the target buffer is not limited. Therefore rename the function and make it simpler. It's ok that bmake_strldup is defined as estrndup in case of USE_EMALLOC since that function's implementation is compatible to the "copy exactly", it just contains some extra null checks that will never match since the variable values cannot (well, or should not) contain null bytes. Theoretically they can, but the behavior then depends on the exact implementation and is unreliable, therefore nobody does this. After all, Makefiles are used for text processing, not for binary data.
Diffstat (limited to 'usr.bin/make/make_malloc.c')
-rw-r--r--usr.bin/make/make_malloc.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/usr.bin/make/make_malloc.c b/usr.bin/make/make_malloc.c
index 343428b9566..cfc5527be9c 100644
--- a/usr.bin/make/make_malloc.c
+++ b/usr.bin/make/make_malloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: make_malloc.c,v 1.14 2020/08/12 18:47:21 rillig Exp $ */
+/* $NetBSD: make_malloc.c,v 1.15 2020/08/20 06:35:14 rillig Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
#ifdef MAKE_NATIVE
#include <sys/cdefs.h>
-__RCSID("$NetBSD: make_malloc.c,v 1.14 2020/08/12 18:47:21 rillig Exp $");
+__RCSID("$NetBSD: make_malloc.c,v 1.15 2020/08/20 06:35:14 rillig Exp $");
#endif
#include <stdio.h>
@@ -82,23 +82,13 @@ bmake_strdup(const char *str)
return memcpy(p, str, len);
}
-/*
- * bmake_strndup --
- * strndup, but die on error.
- */
+/* Allocate a string starting from str with exactly len characters. */
char *
-bmake_strndup(const char *str, size_t max_len)
+bmake_strldup(const char *str, size_t len)
{
- size_t len;
- char *p;
-
- for (len = 0; len < max_len; len++)
- if (str[len] == '\0')
- break;
- p = bmake_malloc(len + 1);
+ char *p = bmake_malloc(len + 1);
memcpy(p, str, len);
p[len] = '\0';
-
return p;
}