Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): add bmake_strsedup for duplicating a s...



details:   https://anonhg.NetBSD.org/src/rev/5a66075d289c
branches:  trunk
changeset: 937957:5a66075d289c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 29 11:24:54 2020 +0000

description:
make(1): add bmake_strsedup for duplicating a substring

diffstat:

 usr.bin/make/make_malloc.c |  11 +++++++++--
 usr.bin/make/make_malloc.h |   3 ++-
 usr.bin/make/parse.c       |   8 ++++----
 usr.bin/make/suff.c        |   8 ++++----
 usr.bin/make/var.c         |  12 ++++--------
 5 files changed, 23 insertions(+), 19 deletions(-)

diffs (158 lines):

diff -r 4461bbfcfe68 -r 5a66075d289c usr.bin/make/make_malloc.c
--- a/usr.bin/make/make_malloc.c        Sat Aug 29 11:13:43 2020 +0000
+++ b/usr.bin/make/make_malloc.c        Sat Aug 29 11:24:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make_malloc.c,v 1.15 2020/08/20 06:35:14 rillig Exp $  */
+/*     $NetBSD: make_malloc.c,v 1.16 2020/08/29 11:24:54 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.15 2020/08/20 06:35:14 rillig Exp $");
+__RCSID("$NetBSD: make_malloc.c,v 1.16 2020/08/29 11:24:54 rillig Exp $");
 #endif
 
 #include <stdio.h>
@@ -92,6 +92,13 @@
        return p;
 }
 
+/* Allocate a string from start up to but excluding end. */
+char *
+bmake_strsedup(const char *start, const char *end)
+{
+       return bmake_strldup(start, (size_t)(end - start));
+}
+
 /*
  * bmake_realloc --
  *     realloc, but die on error.
diff -r 4461bbfcfe68 -r 5a66075d289c usr.bin/make/make_malloc.h
--- a/usr.bin/make/make_malloc.h        Sat Aug 29 11:13:43 2020 +0000
+++ b/usr.bin/make/make_malloc.h        Sat Aug 29 11:24:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make_malloc.h,v 1.8 2020/08/25 17:37:09 rillig Exp $   */
+/*     $NetBSD: make_malloc.h,v 1.9 2020/08/29 11:24:54 rillig Exp $   */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,6 +31,7 @@
 void *bmake_realloc(void *, size_t);
 char *bmake_strdup(const char *);
 char *bmake_strldup(const char *, size_t);
+char *bmake_strsedup(const char *, const char *);
 #else
 #include <util.h>
 #define bmake_malloc(x)         emalloc(x)
diff -r 4461bbfcfe68 -r 5a66075d289c usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Aug 29 11:13:43 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Aug 29 11:24:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c    8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.271 2020/08/29 11:24:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2402,7 +2402,7 @@
        Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL);
        dirname = NULL;
     } else {
-       dirname = bmake_strldup(filename, (size_t)(slash - filename));
+       dirname = bmake_strsedup(filename, slash);
        Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL);
        Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL);
     }
diff -r 4461bbfcfe68 -r 5a66075d289c usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Aug 29 11:13:43 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Aug 29 11:24:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c     8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.133 2020/08/29 11:24:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2037,7 +2037,7 @@
 #endif
 
                eopref = eoname - targ->suff->nameLen;
-               targ->pref = bmake_strldup(sopref, (size_t)(eopref - sopref));
+               targ->pref = bmake_strsedup(sopref, eopref);
 
                /*
                 * Add nodes from which the target can be made
diff -r 4461bbfcfe68 -r 5a66075d289c usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Aug 29 11:13:43 2020 +0000
+++ b/usr.bin/make/var.c        Sat Aug 29 11:24:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.473 2020/08/29 07:52:55 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2312,11 +2312,7 @@
        *dst = '\0';
        endpat = dst;
     } else {
-       /*
-        * Either Var_Subst or ModifyWords will need a
-        * nul-terminated string soon, so construct one now.
-        */
-       pattern = bmake_strldup(mod + 1, (size_t)(endpat - (mod + 1)));
+       pattern = bmake_strsedup(mod + 1, endpat);
     }
 
     if (needSubst) {



Home | Main Index | Thread Index | Old Index