csh: replace malloc(x * y) and realloc(x * y) with reallocarraydiff -r1.35 -r1.36 src/bin/csh/dir.c
(nia)
--- src/bin/csh/dir.c 2020/08/09 00:34:21 1.35
+++ src/bin/csh/dir.c 2024/04/24 15:49:03 1.36
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: dir.c,v 1.35 2020/08/09 00:34:21 dholland Exp $ */ | 1 | /* $NetBSD: dir.c,v 1.36 2024/04/24 15:49:03 nia Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1980, 1991, 1993 | 4 | * Copyright (c) 1980, 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: dir.c,v 1.35 2020/08/09 00:34:21 dholland Exp $"); | 37 | __RCSID("$NetBSD: dir.c,v 1.36 2024/04/24 15:49:03 nia Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | #include <sys/stat.h> | 42 | #include <sys/stat.h> | |
43 | 43 | |||
44 | #include <errno.h> | 44 | #include <errno.h> | |
45 | #include <stdarg.h> | 45 | #include <stdarg.h> | |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> | |
47 | #include <string.h> | 47 | #include <string.h> | |
48 | #include <unistd.h> | 48 | #include <unistd.h> | |
49 | 49 | |||
50 | #include "csh.h" | 50 | #include "csh.h" | |
@@ -269,28 +269,28 @@ dtilde(void) | @@ -269,28 +269,28 @@ dtilde(void) | |||
269 | Char * | 269 | Char * | |
270 | dnormalize(Char *cp) | 270 | dnormalize(Char *cp) | |
271 | { | 271 | { | |
272 | #define UC (unsigned char) | 272 | #define UC (unsigned char) | |
273 | #define ISDOT(c) (UC(c)[0] == '.' && ((UC(c)[1] == '\0') || (UC(c)[1] == '/'))) | 273 | #define ISDOT(c) (UC(c)[0] == '.' && ((UC(c)[1] == '\0') || (UC(c)[1] == '/'))) | |
274 | #define ISDOTDOT(c) (UC(c)[0] == '.' && ISDOT(&((c)[1]))) | 274 | #define ISDOTDOT(c) (UC(c)[0] == '.' && ISDOT(&((c)[1]))) | |
275 | if ((unsigned char) cp[0] == '/') | 275 | if ((unsigned char) cp[0] == '/') | |
276 | return (Strsave(cp)); | 276 | return (Strsave(cp)); | |
277 | 277 | |||
278 | if (adrof(STRignore_symlinks)) { | 278 | if (adrof(STRignore_symlinks)) { | |
279 | size_t dotdot = 0; | 279 | size_t dotdot = 0; | |
280 | Char *dp, *cwd; | 280 | Char *dp, *cwd; | |
281 | 281 | |||
282 | cwd = xmalloc((size_t)((Strlen(dcwd->di_name) + 3) * | 282 | cwd = xreallocarray(NULL, (size_t)(Strlen(dcwd->di_name) + 3), | |
283 | sizeof(Char))); | 283 | sizeof(Char)); | |
284 | (void)Strcpy(cwd, dcwd->di_name); | 284 | (void)Strcpy(cwd, dcwd->di_name); | |
285 | 285 | |||
286 | /* | 286 | /* | |
287 | * Ignore . and count ..'s | 287 | * Ignore . and count ..'s | |
288 | */ | 288 | */ | |
289 | while (*cp) { | 289 | while (*cp) { | |
290 | if (ISDOT(cp)) { | 290 | if (ISDOT(cp)) { | |
291 | if (*++cp) | 291 | if (*++cp) | |
292 | cp++; | 292 | cp++; | |
293 | } | 293 | } | |
294 | else if (ISDOTDOT(cp)) { | 294 | else if (ISDOTDOT(cp)) { | |
295 | dotdot++; | 295 | dotdot++; | |
296 | cp += 2; | 296 | cp += 2; | |
@@ -379,27 +379,28 @@ dgoto(Char *cp) | @@ -379,27 +379,28 @@ dgoto(Char *cp) | |||
379 | { | 379 | { | |
380 | Char *dp; | 380 | Char *dp; | |
381 | 381 | |||
382 | if (*cp != '/') { | 382 | if (*cp != '/') { | |
383 | Char *p, *q; | 383 | Char *p, *q; | |
384 | size_t cwdlen; | 384 | size_t cwdlen; | |
385 | 385 | |||
386 | for (p = dcwd->di_name; *p++;) | 386 | for (p = dcwd->di_name; *p++;) | |
387 | continue; | 387 | continue; | |
388 | if ((cwdlen = (size_t)(p - dcwd->di_name - 1)) == 1) /* root */ | 388 | if ((cwdlen = (size_t)(p - dcwd->di_name - 1)) == 1) /* root */ | |
389 | cwdlen = 0; | 389 | cwdlen = 0; | |
390 | for (p = cp; *p++;) | 390 | for (p = cp; *p++;) | |
391 | continue; | 391 | continue; | |
392 | dp = xmalloc((size_t)(cwdlen + (size_t)(p - cp) + 1) * sizeof(Char)); | 392 | dp = xreallocarray(NULL, | |
393 | (size_t)(cwdlen + (size_t)(p - cp) + 1), sizeof(Char)); | |||
393 | for (p = dp, q = dcwd->di_name; (*p++ = *q++) != '\0';) | 394 | for (p = dp, q = dcwd->di_name; (*p++ = *q++) != '\0';) | |
394 | continue; | 395 | continue; | |
395 | if (cwdlen) | 396 | if (cwdlen) | |
396 | p[-1] = '/'; | 397 | p[-1] = '/'; | |
397 | else | 398 | else | |
398 | p--; /* don't add a / after root */ | 399 | p--; /* don't add a / after root */ | |
399 | for (q = cp; (*p++ = *q++) != '\0';) | 400 | for (q = cp; (*p++ = *q++) != '\0';) | |
400 | continue; | 401 | continue; | |
401 | free(cp); | 402 | free(cp); | |
402 | cp = dp; | 403 | cp = dp; | |
403 | dp += cwdlen; | 404 | dp += cwdlen; | |
404 | } | 405 | } | |
405 | else | 406 | else | |
@@ -695,48 +696,48 @@ dcanon(Char *cp, Char *p) | @@ -695,48 +696,48 @@ dcanon(Char *cp, Char *p) | |||
695 | continue; | 696 | continue; | |
696 | if (*slink != '/') { | 697 | if (*slink != '/') { | |
697 | /* | 698 | /* | |
698 | * Relative path, expand it between the "yyy/" and the | 699 | * Relative path, expand it between the "yyy/" and the | |
699 | * "/..". First, back sp up to the character past "yyy/". | 700 | * "/..". First, back sp up to the character past "yyy/". | |
700 | */ | 701 | */ | |
701 | while (*--sp != '/') | 702 | while (*--sp != '/') | |
702 | continue; | 703 | continue; | |
703 | sp++; | 704 | sp++; | |
704 | *sp = 0; | 705 | *sp = 0; | |
705 | /* | 706 | /* | |
706 | * New length is "yyy/" + slink + "/.." and rest | 707 | * New length is "yyy/" + slink + "/.." and rest | |
707 | */ | 708 | */ | |
708 | p1 = newcp = xmalloc( | 709 | p1 = newcp = xreallocarray(NULL, | |
709 | (size_t)((sp - cp) + cc + (p1 - p)) * sizeof(Char)); | 710 | (size_t)((sp - cp) + cc + (p1 - p)), sizeof(Char)); | |
710 | /* | 711 | /* | |
711 | * Copy new path into newcp | 712 | * Copy new path into newcp | |
712 | */ | 713 | */ | |
713 | for (p2 = cp; (*p1++ = *p2++) != '\0';) | 714 | for (p2 = cp; (*p1++ = *p2++) != '\0';) | |
714 | continue; | 715 | continue; | |
715 | for (p1--, p2 = slink; (*p1++ = *p2++) != '\0';) | 716 | for (p1--, p2 = slink; (*p1++ = *p2++) != '\0';) | |
716 | continue; | 717 | continue; | |
717 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | 718 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | |
718 | continue; | 719 | continue; | |
719 | /* | 720 | /* | |
720 | * Restart canonicalization at expanded "/xxx". | 721 | * Restart canonicalization at expanded "/xxx". | |
721 | */ | 722 | */ | |
722 | p = sp - cp - 1 + newcp; | 723 | p = sp - cp - 1 + newcp; | |
723 | } | 724 | } | |
724 | else { | 725 | else { | |
725 | /* | 726 | /* | |
726 | * New length is slink + "/.." and rest | 727 | * New length is slink + "/.." and rest | |
727 | */ | 728 | */ | |
728 | p1 = newcp = xmalloc( | 729 | p1 = newcp = xreallocarray(NULL, | |
729 | (size_t)(cc + (p1 - p)) * sizeof(Char)); | 730 | (size_t)(cc + (p1 - p)), sizeof(Char)); | |
730 | /* | 731 | /* | |
731 | * Copy new path into newcp | 732 | * Copy new path into newcp | |
732 | */ | 733 | */ | |
733 | for (p2 = slink; (*p1++ = *p2++) != '\0';) | 734 | for (p2 = slink; (*p1++ = *p2++) != '\0';) | |
734 | continue; | 735 | continue; | |
735 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | 736 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | |
736 | continue; | 737 | continue; | |
737 | /* | 738 | /* | |
738 | * Restart canonicalization at beginning | 739 | * Restart canonicalization at beginning | |
739 | */ | 740 | */ | |
740 | p = newcp; | 741 | p = newcp; | |
741 | } | 742 | } | |
742 | free(cp); | 743 | free(cp); | |
@@ -784,48 +785,48 @@ dcanon(Char *cp, Char *p) | @@ -784,48 +785,48 @@ dcanon(Char *cp, Char *p) | |||
784 | if (*slink != '/') { | 785 | if (*slink != '/') { | |
785 | /* | 786 | /* | |
786 | * Relative path, expand it between the "yyy/" and the | 787 | * Relative path, expand it between the "yyy/" and the | |
787 | * remainder. First, back sp up to the character past | 788 | * remainder. First, back sp up to the character past | |
788 | * "yyy/". | 789 | * "yyy/". | |
789 | */ | 790 | */ | |
790 | while (*--sp != '/') | 791 | while (*--sp != '/') | |
791 | continue; | 792 | continue; | |
792 | sp++; | 793 | sp++; | |
793 | *sp = 0; | 794 | *sp = 0; | |
794 | /* | 795 | /* | |
795 | * New length is "yyy/" + slink + "/.." and rest | 796 | * New length is "yyy/" + slink + "/.." and rest | |
796 | */ | 797 | */ | |
797 | p1 = newcp = xmalloc( | 798 | p1 = newcp = xreallocarray(NULL, | |
798 | (size_t)((sp - cp) + cc + (p1 - p)) * sizeof(Char)); | 799 | (size_t)((sp - cp) + cc + (p1 - p)), sizeof(Char)); | |
799 | /* | 800 | /* | |
800 | * Copy new path into newcp | 801 | * Copy new path into newcp | |
801 | */ | 802 | */ | |
802 | for (p2 = cp; (*p1++ = *p2++) != '\0';) | 803 | for (p2 = cp; (*p1++ = *p2++) != '\0';) | |
803 | continue; | 804 | continue; | |
804 | for (p1--, p2 = slink; (*p1++ = *p2++) != '\0';) | 805 | for (p1--, p2 = slink; (*p1++ = *p2++) != '\0';) | |
805 | continue; | 806 | continue; | |
806 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | 807 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | |
807 | continue; | 808 | continue; | |
808 | /* | 809 | /* | |
809 | * Restart canonicalization at expanded "/xxx". | 810 | * Restart canonicalization at expanded "/xxx". | |
810 | */ | 811 | */ | |
811 | p = sp - cp - 1 + newcp; | 812 | p = sp - cp - 1 + newcp; | |
812 | } | 813 | } | |
813 | else { | 814 | else { | |
814 | /* | 815 | /* | |
815 | * New length is slink + the rest | 816 | * New length is slink + the rest | |
816 | */ | 817 | */ | |
817 | p1 = newcp = xmalloc( | 818 | p1 = newcp = xreallocarray(NULL, | |
818 | (size_t)(cc + (p1 - p)) * sizeof(Char)); | 819 | (size_t)(cc + (p1 - p)), sizeof(Char)); | |
819 | /* | 820 | /* | |
820 | * Copy new path into newcp | 821 | * Copy new path into newcp | |
821 | */ | 822 | */ | |
822 | for (p2 = slink; (*p1++ = *p2++) != '\0';) | 823 | for (p2 = slink; (*p1++ = *p2++) != '\0';) | |
823 | continue; | 824 | continue; | |
824 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | 825 | for (p1--, p2 = p; (*p1++ = *p2++) != '\0';) | |
825 | continue; | 826 | continue; | |
826 | /* | 827 | /* | |
827 | * Restart canonicalization at beginning | 828 | * Restart canonicalization at beginning | |
828 | */ | 829 | */ | |
829 | p = newcp; | 830 | p = newcp; | |
830 | } | 831 | } | |
831 | free(cp); | 832 | free(cp); |
--- src/bin/csh/file.c 2020/09/29 02:58:51 1.33
+++ src/bin/csh/file.c 2024/04/24 15:49:03 1.34
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: file.c,v 1.33 2020/09/29 02:58:51 msaitoh Exp $ */ | 1 | /* $NetBSD: file.c,v 1.34 2024/04/24 15:49:03 nia Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1980, 1991, 1993 | 4 | * Copyright (c) 1980, 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)file.c 8.2 (Berkeley) 3/19/94"; | 35 | static char sccsid[] = "@(#)file.c 8.2 (Berkeley) 3/19/94"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: file.c,v 1.33 2020/09/29 02:58:51 msaitoh Exp $"); | 37 | __RCSID("$NetBSD: file.c,v 1.34 2024/04/24 15:49:03 nia Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #ifdef FILEC | 41 | #ifdef FILEC | |
42 | 42 | |||
43 | #include <sys/ioctl.h> | 43 | #include <sys/ioctl.h> | |
44 | #include <sys/param.h> | 44 | #include <sys/param.h> | |
45 | #include <sys/stat.h> | 45 | #include <sys/stat.h> | |
46 | #include <sys/tty.h> | 46 | #include <sys/tty.h> | |
47 | 47 | |||
48 | #include <dirent.h> | 48 | #include <dirent.h> | |
49 | #include <pwd.h> | 49 | #include <pwd.h> | |
50 | #include <termios.h> | 50 | #include <termios.h> | |
@@ -509,33 +509,30 @@ tsearch(Char *word, COMMAND command, siz | @@ -509,33 +509,30 @@ tsearch(Char *word, COMMAND command, siz | |||
509 | 509 | |||
510 | again: /* search for matches */ | 510 | again: /* search for matches */ | |
511 | name_length = Strlen(name); | 511 | name_length = Strlen(name); | |
512 | for (numitems = 0; (entry = getentry(dir_fd, looking_for_lognames)) != NULL;) { | 512 | for (numitems = 0; (entry = getentry(dir_fd, looking_for_lognames)) != NULL;) { | |
513 | if (!is_prefix(name, entry)) | 513 | if (!is_prefix(name, entry)) | |
514 | continue; | 514 | continue; | |
515 | /* Don't match . files on null prefix match */ | 515 | /* Don't match . files on null prefix match */ | |
516 | if (name_length == 0 && entry[0] == '.' && | 516 | if (name_length == 0 && entry[0] == '.' && | |
517 | !looking_for_lognames) | 517 | !looking_for_lognames) | |
518 | continue; | 518 | continue; | |
519 | if (command == LIST) { | 519 | if (command == LIST) { | |
520 | if ((size_t)numitems >= maxitems) { | 520 | if ((size_t)numitems >= maxitems) { | |
521 | maxitems += 1024; | 521 | maxitems += 1024; | |
522 | if (items == NULL) | 522 | items = xreallocarray(items, sizeof(*items), maxitems); | |
523 | items = xmalloc(sizeof(*items) * maxitems); | |||
524 | else | |||
525 | items = xrealloc(items, sizeof(*items) * maxitems); | |||
526 | } | 523 | } | |
527 | items[numitems] = xmalloc((size_t) (Strlen(entry) + 1) * | 524 | items[numitems] = xreallocarray(NULL, | |
528 | sizeof(Char)); | 525 | (size_t) (Strlen(entry) + 1), sizeof(Char)); | |
529 | copyn(items[numitems], entry, MAXNAMLEN); | 526 | copyn(items[numitems], entry, MAXNAMLEN); | |
530 | numitems++; | 527 | numitems++; | |
531 | } | 528 | } | |
532 | else { /* RECOGNIZE command */ | 529 | else { /* RECOGNIZE command */ | |
533 | if (ignoring && ignored(entry)) | 530 | if (ignoring && ignored(entry)) | |
534 | nignored++; | 531 | nignored++; | |
535 | else if (recognize(extended_name, | 532 | else if (recognize(extended_name, | |
536 | entry, name_length, ++numitems)) | 533 | entry, name_length, ++numitems)) | |
537 | break; | 534 | break; | |
538 | } | 535 | } | |
539 | } | 536 | } | |
540 | if (ignoring && numitems == 0 && nignored > 0) { | 537 | if (ignoring && numitems == 0 && nignored > 0) { | |
541 | ignoring = FALSE; | 538 | ignoring = FALSE; |
--- src/bin/csh/func.c 2020/08/09 00:22:53 1.44
+++ src/bin/csh/func.c 2024/04/24 15:49:03 1.45
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: func.c,v 1.44 2020/08/09 00:22:53 dholland Exp $ */ | 1 | /* $NetBSD: func.c,v 1.45 2024/04/24 15:49:03 nia Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1980, 1991, 1993 | 4 | * Copyright (c) 1980, 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)func.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)func.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: func.c,v 1.44 2020/08/09 00:22:53 dholland Exp $"); | 37 | __RCSID("$NetBSD: func.c,v 1.45 2024/04/24 15:49:03 nia Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <sys/stat.h> | 41 | #include <sys/stat.h> | |
42 | #include <sys/types.h> | 42 | #include <sys/types.h> | |
43 | 43 | |||
44 | #include <locale.h> | 44 | #include <locale.h> | |
45 | #include <inttypes.h> | 45 | #include <inttypes.h> | |
46 | #include <signal.h> | 46 | #include <signal.h> | |
47 | #include <stdarg.h> | 47 | #include <stdarg.h> | |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> | |
49 | #include <string.h> | 49 | #include <string.h> | |
50 | #include <unistd.h> | 50 | #include <unistd.h> | |
@@ -968,27 +968,27 @@ dounsetenv(Char **v, struct command *t) | @@ -968,27 +968,27 @@ dounsetenv(Char **v, struct command *t) | |||
968 | 968 | |||
969 | if (name) | 969 | if (name) | |
970 | free(name); | 970 | free(name); | |
971 | /* | 971 | /* | |
972 | * Find the longest environment variable | 972 | * Find the longest environment variable | |
973 | */ | 973 | */ | |
974 | for (maxi = 0, ep = STR_environ; *ep; ep++) { | 974 | for (maxi = 0, ep = STR_environ; *ep; ep++) { | |
975 | for (i = 0, p = *ep; *p && *p != '='; p++, i++) | 975 | for (i = 0, p = *ep; *p && *p != '='; p++, i++) | |
976 | continue; | 976 | continue; | |
977 | if (i > maxi) | 977 | if (i > maxi) | |
978 | maxi = i; | 978 | maxi = i; | |
979 | } | 979 | } | |
980 | 980 | |||
981 | name = xmalloc((size_t)(maxi + 1) * sizeof(Char)); | 981 | name = xreallocarray(NULL, (size_t)(maxi + 1), sizeof(Char)); | |
982 | 982 | |||
983 | while (++v && *v) | 983 | while (++v && *v) | |
984 | for (maxi = 1; maxi;) | 984 | for (maxi = 1; maxi;) | |
985 | for (maxi = 0, ep = STR_environ; *ep; ep++) { | 985 | for (maxi = 0, ep = STR_environ; *ep; ep++) { | |
986 | for (n = name, p = *ep; *p && *p != '='; *n++ = *p++) | 986 | for (n = name, p = *ep; *p && *p != '='; *n++ = *p++) | |
987 | continue; | 987 | continue; | |
988 | *n = '\0'; | 988 | *n = '\0'; | |
989 | if (!Gmatch(name, *v)) | 989 | if (!Gmatch(name, *v)) | |
990 | continue; | 990 | continue; | |
991 | maxi = 1; | 991 | maxi = 1; | |
992 | if (eq(name, STRLANG) || eq(name, STRLC_CTYPE)) { | 992 | if (eq(name, STRLANG) || eq(name, STRLC_CTYPE)) { | |
993 | #ifdef NLS | 993 | #ifdef NLS | |
994 | int k; | 994 | int k; |
--- src/bin/csh/glob.c 2019/01/05 16:56:25 1.31
+++ src/bin/csh/glob.c 2024/04/24 15:49:03 1.32
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: glob.c,v 1.31 2019/01/05 16:56:25 christos Exp $ */ | 1 | /* $NetBSD: glob.c,v 1.32 2024/04/24 15:49:03 nia Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1980, 1991, 1993 | 4 | * Copyright (c) 1980, 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)glob.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)glob.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: glob.c,v 1.31 2019/01/05 16:56:25 christos Exp $"); | 37 | __RCSID("$NetBSD: glob.c,v 1.32 2024/04/24 15:49:03 nia Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | 42 | |||
43 | #include <errno.h> | 43 | #include <errno.h> | |
44 | #include <glob.h> | 44 | #include <glob.h> | |
45 | #include <stdarg.h> | 45 | #include <stdarg.h> | |
46 | #include <stddef.h> | 46 | #include <stddef.h> | |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> | |
48 | #include <string.h> | 48 | #include <string.h> | |
49 | #include <unistd.h> | 49 | #include <unistd.h> | |
50 | 50 | |||
@@ -121,27 +121,27 @@ globtilde(Char **nv, Char *s) | @@ -121,27 +121,27 @@ globtilde(Char **nv, Char *s) | |||
121 | --u; | 121 | --u; | |
122 | free(u); | 122 | free(u); | |
123 | return (Strsave(gstart)); | 123 | return (Strsave(gstart)); | |
124 | } | 124 | } | |
125 | 125 | |||
126 | static int | 126 | static int | |
127 | globbrace(Char *s, Char *p, Char ***bl) | 127 | globbrace(Char *s, Char *p, Char ***bl) | |
128 | { | 128 | { | |
129 | Char gbuf[MAXPATHLEN]; | 129 | Char gbuf[MAXPATHLEN]; | |
130 | Char *lm, *pe, *pl, *pm, **nv, **vl; | 130 | Char *lm, *pe, *pl, *pm, **nv, **vl; | |
131 | int i, len, size; | 131 | int i, len, size; | |
132 | 132 | |||
133 | size = GLOBSPACE; | 133 | size = GLOBSPACE; | |
134 | nv = vl = xmalloc(sizeof(Char *) * (size_t)size); | 134 | nv = vl = xreallocarray(NULL, sizeof(Char *), (size_t)size); | |
135 | *vl = NULL; | 135 | *vl = NULL; | |
136 | len = 0; | 136 | len = 0; | |
137 | /* copy part up to the brace */ | 137 | /* copy part up to the brace */ | |
138 | for (lm = gbuf, p = s; *p != LBRC; *lm++ = *p++) | 138 | for (lm = gbuf, p = s; *p != LBRC; *lm++ = *p++) | |
139 | continue; | 139 | continue; | |
140 | 140 | |||
141 | /* check for balanced braces */ | 141 | /* check for balanced braces */ | |
142 | for (i = 0, pe = ++p; *pe; pe++) | 142 | for (i = 0, pe = ++p; *pe; pe++) | |
143 | if (*pe == LBRK) { | 143 | if (*pe == LBRK) { | |
144 | /* Ignore everything between [] */ | 144 | /* Ignore everything between [] */ | |
145 | for (++pe; *pe != RBRK && *pe != EOS; pe++) | 145 | for (++pe; *pe != RBRK && *pe != EOS; pe++) | |
146 | continue; | 146 | continue; | |
147 | if (*pe == EOS) { | 147 | if (*pe == EOS) { | |
@@ -187,27 +187,27 @@ globbrace(Char *s, Char *p, Char ***bl) | @@ -187,27 +187,27 @@ globbrace(Char *s, Char *p, Char ***bl) | |||
187 | break; | 187 | break; | |
188 | else { | 188 | else { | |
189 | Char savec = *pm; | 189 | Char savec = *pm; | |
190 | 190 | |||
191 | *pm = EOS; | 191 | *pm = EOS; | |
192 | (void)Strcpy(lm, pl); | 192 | (void)Strcpy(lm, pl); | |
193 | (void)Strcat(gbuf, pe + 1); | 193 | (void)Strcat(gbuf, pe + 1); | |
194 | *pm = savec; | 194 | *pm = savec; | |
195 | *vl++ = Strsave(gbuf); | 195 | *vl++ = Strsave(gbuf); | |
196 | len++; | 196 | len++; | |
197 | pl = pm + 1; | 197 | pl = pm + 1; | |
198 | if (vl == &nv[size]) { | 198 | if (vl == &nv[size]) { | |
199 | size += GLOBSPACE; | 199 | size += GLOBSPACE; | |
200 | nv = xrealloc(nv, (size_t)size * sizeof(Char *)); | 200 | nv = xreallocarray(nv, (size_t)size, sizeof(Char *)); | |
201 | vl = &nv[size - GLOBSPACE]; | 201 | vl = &nv[size - GLOBSPACE]; | |
202 | } | 202 | } | |
203 | } | 203 | } | |
204 | break; | 204 | break; | |
205 | default: | 205 | default: | |
206 | break; | 206 | break; | |
207 | } | 207 | } | |
208 | *vl = NULL; | 208 | *vl = NULL; | |
209 | *bl = nv; | 209 | *bl = nv; | |
210 | return (len); | 210 | return (len); | |
211 | } | 211 | } | |
212 | 212 | |||
213 | static void | 213 | static void | |
@@ -240,27 +240,27 @@ expbrace(Char ***nvp, Char ***elp, size_ | @@ -240,27 +240,27 @@ expbrace(Char ***nvp, Char ***elp, size_ | |||
240 | if (len == 1) { | 240 | if (len == 1) { | |
241 | *vl-- = *bl; | 241 | *vl-- = *bl; | |
242 | free(bl); | 242 | free(bl); | |
243 | continue; | 243 | continue; | |
244 | } | 244 | } | |
245 | len = blklen(bl); | 245 | len = blklen(bl); | |
246 | if (&ex[len] >= &nv[size]) { | 246 | if (&ex[len] >= &nv[size]) { | |
247 | ptrdiff_t l, e; | 247 | ptrdiff_t l, e; | |
248 | 248 | |||
249 | l = &ex[len] - &nv[size]; | 249 | l = &ex[len] - &nv[size]; | |
250 | size += (size_t)(GLOBSPACE > l ? GLOBSPACE : l); | 250 | size += (size_t)(GLOBSPACE > l ? GLOBSPACE : l); | |
251 | l = vl - nv; | 251 | l = vl - nv; | |
252 | e = ex - nv; | 252 | e = ex - nv; | |
253 | nv = xrealloc(nv, (size_t)size * sizeof(Char *)); | 253 | nv = xreallocarray(nv, size, sizeof(Char *)); | |
254 | vl = nv + l; | 254 | vl = nv + l; | |
255 | ex = nv + e; | 255 | ex = nv + e; | |
256 | } | 256 | } | |
257 | vp = vl--; | 257 | vp = vl--; | |
258 | *vp = *bl; | 258 | *vp = *bl; | |
259 | len--; | 259 | len--; | |
260 | for (bp = ex; bp != vp; bp--) | 260 | for (bp = ex; bp != vp; bp--) | |
261 | bp[len] = *bp; | 261 | bp[len] = *bp; | |
262 | ex += len; | 262 | ex += len; | |
263 | vp++; | 263 | vp++; | |
264 | for (bp = bl + 1; *bp; *vp++ = *bp++) | 264 | for (bp = bl + 1; *bp; *vp++ = *bp++) | |
265 | continue; | 265 | continue; | |
266 | free(bl); | 266 | free(bl); | |
@@ -269,53 +269,53 @@ expbrace(Char ***nvp, Char ***elp, size_ | @@ -269,53 +269,53 @@ expbrace(Char ***nvp, Char ***elp, size_ | |||
269 | } | 269 | } | |
270 | if (elp != NULL) | 270 | if (elp != NULL) | |
271 | *elp = ex; | 271 | *elp = ex; | |
272 | *nvp = nv; | 272 | *nvp = nv; | |
273 | } | 273 | } | |
274 | 274 | |||
275 | static Char ** | 275 | static Char ** | |
276 | globexpand(Char **v) | 276 | globexpand(Char **v) | |
277 | { | 277 | { | |
278 | Char **ex, **nv, *s, **vl; | 278 | Char **ex, **nv, *s, **vl; | |
279 | size_t size; | 279 | size_t size; | |
280 | 280 | |||
281 | size = GLOBSPACE; | 281 | size = GLOBSPACE; | |
282 | nv = vl = xmalloc(sizeof(Char *) * size); | 282 | nv = vl = xreallocarray(NULL, sizeof(Char *), size); | |
283 | *vl = NULL; | 283 | *vl = NULL; | |
284 | 284 | |||
285 | /* | 285 | /* | |
286 | * Step 1: expand backquotes. | 286 | * Step 1: expand backquotes. | |
287 | */ | 287 | */ | |
288 | while ((s = *v++) != NULL) { | 288 | while ((s = *v++) != NULL) { | |
289 | if (Strchr(s, '`')) { | 289 | if (Strchr(s, '`')) { | |
290 | int i; | 290 | int i; | |
291 | 291 | |||
292 | (void) dobackp(s, 0); | 292 | (void) dobackp(s, 0); | |
293 | for (i = 0; i < pargc; i++) { | 293 | for (i = 0; i < pargc; i++) { | |
294 | *vl++ = pargv[i]; | 294 | *vl++ = pargv[i]; | |
295 | if (vl == &nv[size]) { | 295 | if (vl == &nv[size]) { | |
296 | size += GLOBSPACE; | 296 | size += GLOBSPACE; | |
297 | nv = xrealloc(nv, (size_t)size * sizeof(Char *)); | 297 | nv = xreallocarray(nv, size, sizeof(Char *)); | |
298 | vl = &nv[size - GLOBSPACE]; | 298 | vl = &nv[size - GLOBSPACE]; | |
299 | } | 299 | } | |
300 | } | 300 | } | |
301 | free(pargv); | 301 | free(pargv); | |
302 | pargv = NULL; | 302 | pargv = NULL; | |
303 | } | 303 | } | |
304 | else { | 304 | else { | |
305 | *vl++ = Strsave(s); | 305 | *vl++ = Strsave(s); | |
306 | if (vl == &nv[size]) { | 306 | if (vl == &nv[size]) { | |
307 | size += GLOBSPACE; | 307 | size += GLOBSPACE; | |
308 | nv = xrealloc(nv, size * sizeof(Char *)); | 308 | nv = xreallocarray(nv, size, sizeof(Char *)); | |
309 | vl = &nv[size - GLOBSPACE]; | 309 | vl = &nv[size - GLOBSPACE]; | |
310 | } | 310 | } | |
311 | } | 311 | } | |
312 | } | 312 | } | |
313 | *vl = NULL; | 313 | *vl = NULL; | |
314 | 314 | |||
315 | if (noglob) | 315 | if (noglob) | |
316 | return (nv); | 316 | return (nv); | |
317 | 317 | |||
318 | /* | 318 | /* | |
319 | * Step 2: expand braces | 319 | * Step 2: expand braces | |
320 | */ | 320 | */ | |
321 | ex = vl; | 321 | ex = vl; | |
@@ -502,27 +502,27 @@ globall(Char **v) | @@ -502,27 +502,27 @@ globall(Char **v) | |||
502 | blkfree(vo); | 502 | blkfree(vo); | |
503 | } | 503 | } | |
504 | else | 504 | else | |
505 | trim(vl); | 505 | trim(vl); | |
506 | 506 | |||
507 | gargc = vl ? blklen(vl) : 0; | 507 | gargc = vl ? blklen(vl) : 0; | |
508 | return (gargv = vl); | 508 | return (gargv = vl); | |
509 | } | 509 | } | |
510 | 510 | |||
511 | void | 511 | void | |
512 | ginit(void) | 512 | ginit(void) | |
513 | { | 513 | { | |
514 | gargsiz = GLOBSPACE; | 514 | gargsiz = GLOBSPACE; | |
515 | gargv = xmalloc(sizeof(Char *) * (size_t)gargsiz); | 515 | gargv = xreallocarray(NULL, sizeof(Char *), (size_t)gargsiz); | |
516 | gargv[0] = 0; | 516 | gargv[0] = 0; | |
517 | gargc = 0; | 517 | gargc = 0; | |
518 | } | 518 | } | |
519 | 519 | |||
520 | void | 520 | void | |
521 | rscan(Char **t, void (*f)(int)) | 521 | rscan(Char **t, void (*f)(int)) | |
522 | { | 522 | { | |
523 | Char *p; | 523 | Char *p; | |
524 | 524 | |||
525 | while ((p = *t++) != NULL) | 525 | while ((p = *t++) != NULL) | |
526 | while (*p) | 526 | while (*p) | |
527 | (*f) (*p++); | 527 | (*f) (*p++); | |
528 | } | 528 | } | |
@@ -581,27 +581,27 @@ tglob(Char **t) | @@ -581,27 +581,27 @@ tglob(Char **t) | |||
581 | */ | 581 | */ | |
582 | Char ** | 582 | Char ** | |
583 | dobackp(Char *cp, int literal) | 583 | dobackp(Char *cp, int literal) | |
584 | { | 584 | { | |
585 | Char word[MAXPATHLEN], *ep, *lp, *rp; | 585 | Char word[MAXPATHLEN], *ep, *lp, *rp; | |
586 | 586 | |||
587 | if (pargv) { | 587 | if (pargv) { | |
588 | #ifdef notdef | 588 | #ifdef notdef | |
589 | abort(); | 589 | abort(); | |
590 | #endif | 590 | #endif | |
591 | blkfree(pargv); | 591 | blkfree(pargv); | |
592 | } | 592 | } | |
593 | pargsiz = GLOBSPACE; | 593 | pargsiz = GLOBSPACE; | |
594 | pargv = xmalloc(sizeof(Char *) * (size_t)pargsiz); | 594 | pargv = xreallocarray(NULL, sizeof(Char *), (size_t)pargsiz); | |
595 | pargv[0] = NULL; | 595 | pargv[0] = NULL; | |
596 | pargcp = pargs = word; | 596 | pargcp = pargs = word; | |
597 | pargc = 0; | 597 | pargc = 0; | |
598 | pnleft = MAXPATHLEN - 4; | 598 | pnleft = MAXPATHLEN - 4; | |
599 | for (;;) { | 599 | for (;;) { | |
600 | for (lp = cp; *lp != '`'; lp++) { | 600 | for (lp = cp; *lp != '`'; lp++) { | |
601 | if (*lp == 0) { | 601 | if (*lp == 0) { | |
602 | if (pargcp != pargs) | 602 | if (pargcp != pargs) | |
603 | pword(); | 603 | pword(); | |
604 | return (pargv); | 604 | return (pargv); | |
605 | } | 605 | } | |
606 | psave(*lp); | 606 | psave(*lp); | |
607 | } | 607 | } | |
@@ -767,49 +767,49 @@ static void | @@ -767,49 +767,49 @@ static void | |||
767 | psave(int c) | 767 | psave(int c) | |
768 | { | 768 | { | |
769 | if (--pnleft <= 0) | 769 | if (--pnleft <= 0) | |
770 | stderror(ERR_WTOOLONG); | 770 | stderror(ERR_WTOOLONG); | |
771 | *pargcp++ = (Char)c; | 771 | *pargcp++ = (Char)c; | |
772 | } | 772 | } | |
773 | 773 | |||
774 | static void | 774 | static void | |
775 | pword(void) | 775 | pword(void) | |
776 | { | 776 | { | |
777 | psave(0); | 777 | psave(0); | |
778 | if (pargc == pargsiz - 1) { | 778 | if (pargc == pargsiz - 1) { | |
779 | pargsiz += GLOBSPACE; | 779 | pargsiz += GLOBSPACE; | |
780 | pargv = xrealloc(pargv, (size_t)pargsiz * sizeof(Char *)); | 780 | pargv = xreallocarray(pargv, (size_t)pargsiz, sizeof(Char *)); | |
781 | } | 781 | } | |
782 | pargv[pargc++] = Strsave(pargs); | 782 | pargv[pargc++] = Strsave(pargs); | |
783 | pargv[pargc] = NULL; | 783 | pargv[pargc] = NULL; | |
784 | pargcp = pargs; | 784 | pargcp = pargs; | |
785 | pnleft = MAXPATHLEN - 4; | 785 | pnleft = MAXPATHLEN - 4; | |
786 | } | 786 | } | |
787 | 787 | |||
788 | int | 788 | int | |
789 | Gmatch(Char *string, Char *pattern) | 789 | Gmatch(Char *string, Char *pattern) | |
790 | { | 790 | { | |
791 | Char **blk, **p; | 791 | Char **blk, **p; | |
792 | int gpol, gres; | 792 | int gpol, gres; | |
793 | 793 | |||
794 | gpol = 1; | 794 | gpol = 1; | |
795 | gres = 0; | 795 | gres = 0; | |
796 | 796 | |||
797 | if (*pattern == '^') { | 797 | if (*pattern == '^') { | |
798 | gpol = 0; | 798 | gpol = 0; | |
799 | pattern++; | 799 | pattern++; | |
800 | } | 800 | } | |
801 | 801 | |||
802 | blk = xmalloc(GLOBSPACE * sizeof(Char *)); | 802 | blk = xreallocarray(NULL, GLOBSPACE, sizeof(Char *)); | |
803 | blk[0] = Strsave(pattern); | 803 | blk[0] = Strsave(pattern); | |
804 | blk[1] = NULL; | 804 | blk[1] = NULL; | |
805 | 805 | |||
806 | expbrace(&blk, NULL, GLOBSPACE); | 806 | expbrace(&blk, NULL, GLOBSPACE); | |
807 | 807 | |||
808 | for (p = blk; *p; p++) | 808 | for (p = blk; *p; p++) | |
809 | gres |= pmatch(string, *p); | 809 | gres |= pmatch(string, *p); | |
810 | 810 | |||
811 | blkfree(blk); | 811 | blkfree(blk); | |
812 | return(gres == gpol); | 812 | return(gres == gpol); | |
813 | } | 813 | } | |
814 | 814 | |||
815 | static int | 815 | static int | |
@@ -887,30 +887,30 @@ pmatch(const Char *name, const Char *pat | @@ -887,30 +887,30 @@ pmatch(const Char *name, const Char *pat | |||
887 | void | 887 | void | |
888 | Gcat(Char *s1, Char *s2) | 888 | Gcat(Char *s1, Char *s2) | |
889 | { | 889 | { | |
890 | Char *p, *q; | 890 | Char *p, *q; | |
891 | ptrdiff_t n; | 891 | ptrdiff_t n; | |
892 | 892 | |||
893 | for (p = s1; *p++;) | 893 | for (p = s1; *p++;) | |
894 | continue; | 894 | continue; | |
895 | for (q = s2; *q++;) | 895 | for (q = s2; *q++;) | |
896 | continue; | 896 | continue; | |
897 | n = (p - s1) + (q - s2) - 1; | 897 | n = (p - s1) + (q - s2) - 1; | |
898 | if (++gargc >= gargsiz) { | 898 | if (++gargc >= gargsiz) { | |
899 | gargsiz += GLOBSPACE; | 899 | gargsiz += GLOBSPACE; | |
900 | gargv = xrealloc(gargv, (size_t)gargsiz * sizeof(Char *)); | 900 | gargv = xreallocarray(gargv, (size_t)gargsiz, sizeof(Char *)); | |
901 | } | 901 | } | |
902 | gargv[gargc] = 0; | 902 | gargv[gargc] = 0; | |
903 | p = gargv[gargc - 1] = xmalloc((size_t)n * sizeof(Char)); | 903 | p = gargv[gargc - 1] = xreallocarray(NULL, (size_t)n, sizeof(Char)); | |
904 | for (q = s1; (*p++ = *q++) != '\0';) | 904 | for (q = s1; (*p++ = *q++) != '\0';) | |
905 | continue; | 905 | continue; | |
906 | for (p--, q = s2; (*p++ = *q++) != '\0';) | 906 | for (p--, q = s2; (*p++ = *q++) != '\0';) | |
907 | continue; | 907 | continue; | |
908 | } | 908 | } | |
909 | 909 | |||
910 | #ifdef FILEC | 910 | #ifdef FILEC | |
911 | int | 911 | int | |
912 | sortscmp(const void *va, const void *vb) | 912 | sortscmp(const void *va, const void *vb) | |
913 | { | 913 | { | |
914 | #if defined(NLS) && !defined(NOSTRCOLL) | 914 | #if defined(NLS) && !defined(NOSTRCOLL) | |
915 | char buf[2048]; | 915 | char buf[2048]; | |
916 | #endif | 916 | #endif |
--- src/bin/csh/misc.c 2019/01/05 16:54:00 1.22
+++ src/bin/csh/misc.c 2024/04/24 15:49:03 1.23
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: misc.c,v 1.22 2019/01/05 16:54:00 christos Exp $ */ | 1 | /* $NetBSD: misc.c,v 1.23 2024/04/24 15:49:03 nia Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1980, 1991, 1993 | 4 | * Copyright (c) 1980, 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: misc.c,v 1.22 2019/01/05 16:54:00 christos Exp $"); | 37 | __RCSID("$NetBSD: misc.c,v 1.23 2024/04/24 15:49:03 nia Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | 42 | |||
43 | #include <stdarg.h> | 43 | #include <stdarg.h> | |
44 | #include <stdlib.h> | 44 | #include <stdlib.h> | |
45 | #include <string.h> | 45 | #include <string.h> | |
46 | #include <unistd.h> | 46 | #include <unistd.h> | |
47 | #include <fcntl.h> | 47 | #include <fcntl.h> | |
48 | 48 | |||
49 | #include "csh.h" | 49 | #include "csh.h" | |
50 | #include "extern.h" | 50 | #include "extern.h" | |
@@ -62,27 +62,27 @@ any(const char *s, int c) | @@ -62,27 +62,27 @@ any(const char *s, int c) | |||
62 | return (0); | 62 | return (0); | |
63 | } | 63 | } | |
64 | 64 | |||
65 | char * | 65 | char * | |
66 | strsave(const char *s) | 66 | strsave(const char *s) | |
67 | { | 67 | { | |
68 | const char *n; | 68 | const char *n; | |
69 | char *p, *r; | 69 | char *p, *r; | |
70 | 70 | |||
71 | if (s == NULL) | 71 | if (s == NULL) | |
72 | s = ""; | 72 | s = ""; | |
73 | for (n = s; *n++;) | 73 | for (n = s; *n++;) | |
74 | continue; | 74 | continue; | |
75 | r = p = xmalloc((size_t)(n - s) * sizeof(*p)); | 75 | r = p = xreallocarray(NULL, (size_t)(n - s), sizeof(*p)); | |
76 | while ((*p++ = *s++) != '\0') | 76 | while ((*p++ = *s++) != '\0') | |
77 | continue; | 77 | continue; | |
78 | return (r); | 78 | return (r); | |
79 | } | 79 | } | |
80 | 80 | |||
81 | Char ** | 81 | Char ** | |
82 | blkend(Char **up) | 82 | blkend(Char **up) | |
83 | { | 83 | { | |
84 | while (*up) | 84 | while (*up) | |
85 | up++; | 85 | up++; | |
86 | return (up); | 86 | return (up); | |
87 | } | 87 | } | |
88 | 88 | |||
@@ -179,27 +179,27 @@ strstr(char *s, char *t) | @@ -179,27 +179,27 @@ strstr(char *s, char *t) | |||
179 | char * | 179 | char * | |
180 | strspl(char *cp, char *dp) | 180 | strspl(char *cp, char *dp) | |
181 | { | 181 | { | |
182 | char *ep, *p, *q; | 182 | char *ep, *p, *q; | |
183 | 183 | |||
184 | if (!cp) | 184 | if (!cp) | |
185 | cp = ""; | 185 | cp = ""; | |
186 | if (!dp) | 186 | if (!dp) | |
187 | dp = ""; | 187 | dp = ""; | |
188 | for (p = cp; *p++;) | 188 | for (p = cp; *p++;) | |
189 | continue; | 189 | continue; | |
190 | for (q = dp; *q++;) | 190 | for (q = dp; *q++;) | |
191 | continue; | 191 | continue; | |
192 | ep = xmalloc((size_t)(((p - cp) + (q - dp) - 1) * sizeof(*ep))); | 192 | ep = xreallocarray(NULL, (size_t)(((p - cp) + (q - dp) - 1), sizeof(*ep))); | |
193 | for (p = ep, q = cp; *p++ = *q++;) | 193 | for (p = ep, q = cp; *p++ = *q++;) | |
194 | continue; | 194 | continue; | |
195 | for (p--, q = dp; *p++ = *q++;) | 195 | for (p--, q = dp; *p++ = *q++;) | |
196 | continue; | 196 | continue; | |
197 | return (ep); | 197 | return (ep); | |
198 | } | 198 | } | |
199 | 199 | |||
200 | #endif | 200 | #endif | |
201 | 201 | |||
202 | Char ** | 202 | Char ** | |
203 | blkspl(Char **up, Char **vp) | 203 | blkspl(Char **up, Char **vp) | |
204 | { | 204 | { | |
205 | Char **wp; | 205 | Char **wp; |
--- src/bin/csh/str.c 2019/01/05 16:54:00 1.16
+++ src/bin/csh/str.c 2024/04/24 15:49:03 1.17
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: str.c,v 1.16 2019/01/05 16:54:00 christos Exp $ */ | 1 | /* $NetBSD: str.c,v 1.17 2024/04/24 15:49:03 nia Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1991, 1993 | 4 | * Copyright (c) 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | #ifndef lint | 33 | #ifndef lint | |
34 | #if 0 | 34 | #if 0 | |
35 | static char sccsid[] = "@(#)str.c 8.1 (Berkeley) 5/31/93"; | 35 | static char sccsid[] = "@(#)str.c 8.1 (Berkeley) 5/31/93"; | |
36 | #else | 36 | #else | |
37 | __RCSID("$NetBSD: str.c,v 1.16 2019/01/05 16:54:00 christos Exp $"); | 37 | __RCSID("$NetBSD: str.c,v 1.17 2024/04/24 15:49:03 nia Exp $"); | |
38 | #endif | 38 | #endif | |
39 | #endif /* not lint */ | 39 | #endif /* not lint */ | |
40 | 40 | |||
41 | #define MALLOC_INCR 128 | 41 | #define MALLOC_INCR 128 | |
42 | 42 | |||
43 | /* | 43 | /* | |
44 | * tc.str.c: Short string package | 44 | * tc.str.c: Short string package | |
45 | * This has been a lesson of how to write buggy code! | 45 | * This has been a lesson of how to write buggy code! | |
46 | */ | 46 | */ | |
47 | 47 | |||
48 | #include <sys/types.h> | 48 | #include <sys/types.h> | |
49 | 49 | |||
50 | #include <stdarg.h> | 50 | #include <stdarg.h> | |
@@ -56,104 +56,104 @@ __RCSID("$NetBSD: str.c,v 1.16 2019/01/0 | @@ -56,104 +56,104 @@ __RCSID("$NetBSD: str.c,v 1.16 2019/01/0 | |||
56 | #ifdef SHORT_STRINGS | 56 | #ifdef SHORT_STRINGS | |
57 | 57 | |||
58 | Char ** | 58 | Char ** | |
59 | blk2short(char **src) | 59 | blk2short(char **src) | |
60 | { | 60 | { | |
61 | Char **dst, **sdst; | 61 | Char **dst, **sdst; | |
62 | size_t n; | 62 | size_t n; | |
63 | 63 | |||
64 | /* | 64 | /* | |
65 | * Count | 65 | * Count | |
66 | */ | 66 | */ | |
67 | for (n = 0; src[n] != NULL; n++) | 67 | for (n = 0; src[n] != NULL; n++) | |
68 | continue; | 68 | continue; | |
69 | sdst = dst = xmalloc((size_t)((n + 1) * sizeof(*dst))); | 69 | sdst = dst = xreallocarray(NULL, n + 1, sizeof(*dst)); | |
70 | 70 | |||
71 | for (; *src != NULL; src++) | 71 | for (; *src != NULL; src++) | |
72 | *dst++ = SAVE(*src); | 72 | *dst++ = SAVE(*src); | |
73 | *dst = NULL; | 73 | *dst = NULL; | |
74 | return (sdst); | 74 | return (sdst); | |
75 | } | 75 | } | |
76 | 76 | |||
77 | char ** | 77 | char ** | |
78 | short2blk(Char *const *src) | 78 | short2blk(Char *const *src) | |
79 | { | 79 | { | |
80 | char **dst, **sdst; | 80 | char **dst, **sdst; | |
81 | size_t n; | 81 | size_t n; | |
82 | 82 | |||
83 | /* | 83 | /* | |
84 | * Count | 84 | * Count | |
85 | */ | 85 | */ | |
86 | for (n = 0; src[n] != NULL; n++) | 86 | for (n = 0; src[n] != NULL; n++) | |
87 | continue; | 87 | continue; | |
88 | sdst = dst = xmalloc((size_t)((n + 1) * sizeof(*dst))); | 88 | sdst = dst = xreallocarray(NULL, n + 1, sizeof(*dst)); | |
89 | 89 | |||
90 | for (; *src != NULL; src++) | 90 | for (; *src != NULL; src++) | |
91 | *dst++ = strsave(short2str(*src)); | 91 | *dst++ = strsave(short2str(*src)); | |
92 | *dst = NULL; | 92 | *dst = NULL; | |
93 | return (sdst); | 93 | return (sdst); | |
94 | } | 94 | } | |
95 | 95 | |||
96 | Char * | 96 | Char * | |
97 | str2short(const char *src) | 97 | str2short(const char *src) | |
98 | { | 98 | { | |
99 | static Char *sdst; | 99 | static Char *sdst; | |
100 | Char *dst, *edst; | 100 | Char *dst, *edst; | |
101 | static size_t dstsize = 0; | 101 | static size_t dstsize = 0; | |
102 | 102 | |||
103 | if (src == NULL) | 103 | if (src == NULL) | |
104 | return (NULL); | 104 | return (NULL); | |
105 | 105 | |||
106 | if (sdst == (NULL)) { | 106 | if (sdst == (NULL)) { | |
107 | dstsize = MALLOC_INCR; | 107 | dstsize = MALLOC_INCR; | |
108 | sdst = xmalloc((size_t)dstsize * sizeof(*sdst)); | 108 | sdst = xreallocarray(NULL, (size_t)dstsize, sizeof(*sdst)); | |
109 | } | 109 | } | |
110 | 110 | |||
111 | dst = sdst; | 111 | dst = sdst; | |
112 | edst = &dst[dstsize]; | 112 | edst = &dst[dstsize]; | |
113 | while (*src) { | 113 | while (*src) { | |
114 | *dst++ = (Char) ((unsigned char) *src++); | 114 | *dst++ = (Char) ((unsigned char) *src++); | |
115 | if (dst == edst) { | 115 | if (dst == edst) { | |
116 | dstsize += MALLOC_INCR; | 116 | dstsize += MALLOC_INCR; | |
117 | sdst = xrealloc(sdst, (size_t)dstsize * sizeof(*sdst)); | 117 | sdst = xreallocarray(sdst, (size_t)dstsize, sizeof(*sdst)); | |
118 | edst = &sdst[dstsize]; | 118 | edst = &sdst[dstsize]; | |
119 | dst = &edst[-MALLOC_INCR]; | 119 | dst = &edst[-MALLOC_INCR]; | |
120 | } | 120 | } | |
121 | } | 121 | } | |
122 | *dst = 0; | 122 | *dst = 0; | |
123 | return (sdst); | 123 | return (sdst); | |
124 | } | 124 | } | |
125 | 125 | |||
126 | char * | 126 | char * | |
127 | short2str(const Char *src) | 127 | short2str(const Char *src) | |
128 | { | 128 | { | |
129 | static char *sdst = NULL; | 129 | static char *sdst = NULL; | |
130 | static size_t dstsize = 0; | 130 | static size_t dstsize = 0; | |
131 | char *dst, *edst; | 131 | char *dst, *edst; | |
132 | 132 | |||
133 | if (src == NULL) | 133 | if (src == NULL) | |
134 | return (NULL); | 134 | return (NULL); | |
135 | 135 | |||
136 | if (sdst == NULL) { | 136 | if (sdst == NULL) { | |
137 | dstsize = MALLOC_INCR; | 137 | dstsize = MALLOC_INCR; | |
138 | sdst = xmalloc((size_t)dstsize * sizeof(*sdst)); | 138 | sdst = xreallocarray(NULL, dstsize, sizeof(*sdst)); | |
139 | } | 139 | } | |
140 | dst = sdst; | 140 | dst = sdst; | |
141 | edst = &dst[dstsize]; | 141 | edst = &dst[dstsize]; | |
142 | while (*src) { | 142 | while (*src) { | |
143 | *dst++ = (char) *src++; | 143 | *dst++ = (char) *src++; | |
144 | if (dst == edst) { | 144 | if (dst == edst) { | |
145 | dstsize += MALLOC_INCR; | 145 | dstsize += MALLOC_INCR; | |
146 | sdst = xrealloc(sdst, (size_t)dstsize * sizeof(*sdst)); | 146 | sdst = xreallocarray(sdst, dstsize, sizeof(*sdst)); | |
147 | edst = &sdst[dstsize]; | 147 | edst = &sdst[dstsize]; | |
148 | dst = &edst[-MALLOC_INCR]; | 148 | dst = &edst[-MALLOC_INCR]; | |
149 | } | 149 | } | |
150 | } | 150 | } | |
151 | *dst = 0; | 151 | *dst = 0; | |
152 | return (sdst); | 152 | return (sdst); | |
153 | } | 153 | } | |
154 | 154 | |||
155 | Char * | 155 | Char * | |
156 | s_strcpy(Char *dst, const Char *src) | 156 | s_strcpy(Char *dst, const Char *src) | |
157 | { | 157 | { | |
158 | Char *sdst; | 158 | Char *sdst; | |
159 | 159 | |||
@@ -302,47 +302,47 @@ s_strncmp(const Char *str1, const Char * | @@ -302,47 +302,47 @@ s_strncmp(const Char *str1, const Char * | |||
302 | return(0); | 302 | return(0); | |
303 | } | 303 | } | |
304 | 304 | |||
305 | Char * | 305 | Char * | |
306 | s_strsave(const Char *s) | 306 | s_strsave(const Char *s) | |
307 | { | 307 | { | |
308 | const Char *p; | 308 | const Char *p; | |
309 | Char *n; | 309 | Char *n; | |
310 | 310 | |||
311 | if (s == 0) | 311 | if (s == 0) | |
312 | s = STRNULL; | 312 | s = STRNULL; | |
313 | for (p = s; *p++;) | 313 | for (p = s; *p++;) | |
314 | continue; | 314 | continue; | |
315 | p = n = xmalloc((size_t)(p - s) * sizeof(*n)); | 315 | p = n = xreallocarray(NULL, (size_t)(p - s), sizeof(*n)); | |
316 | while ((*n++ = *s++) != '\0') | 316 | while ((*n++ = *s++) != '\0') | |
317 | continue; | 317 | continue; | |
318 | return __UNCONST(p); | 318 | return __UNCONST(p); | |
319 | } | 319 | } | |
320 | 320 | |||
321 | Char * | 321 | Char * | |
322 | s_strspl(const Char *cp, const Char *dp) | 322 | s_strspl(const Char *cp, const Char *dp) | |
323 | { | 323 | { | |
324 | Char *ep, *d; | 324 | Char *ep, *d; | |
325 | const Char *p, *q; | 325 | const Char *p, *q; | |
326 | 326 | |||
327 | if (!cp) | 327 | if (!cp) | |
328 | cp = STRNULL; | 328 | cp = STRNULL; | |
329 | if (!dp) | 329 | if (!dp) | |
330 | dp = STRNULL; | 330 | dp = STRNULL; | |
331 | for (p = cp; *p++;) | 331 | for (p = cp; *p++;) | |
332 | continue; | 332 | continue; | |
333 | for (q = dp; *q++;) | 333 | for (q = dp; *q++;) | |
334 | continue; | 334 | continue; | |
335 | ep = xmalloc((size_t)((p - cp) + (q - dp) - 1) * sizeof(*ep)); | 335 | ep = xreallocarray(NULL, (size_t)((p - cp) + (q - dp) - 1), sizeof(*ep)); | |
336 | for (d = ep, q = cp; (*d++ = *q++) != '\0';) | 336 | for (d = ep, q = cp; (*d++ = *q++) != '\0';) | |
337 | continue; | 337 | continue; | |
338 | for (d--, q = dp; (*d++ = *q++) != '\0';) | 338 | for (d--, q = dp; (*d++ = *q++) != '\0';) | |
339 | continue; | 339 | continue; | |
340 | return (ep); | 340 | return (ep); | |
341 | } | 341 | } | |
342 | 342 | |||
343 | Char * | 343 | Char * | |
344 | s_strend(const Char *cp) | 344 | s_strend(const Char *cp) | |
345 | { | 345 | { | |
346 | if (!cp) | 346 | if (!cp) | |
347 | return __UNCONST(cp); | 347 | return __UNCONST(cp); | |
348 | while (*cp) | 348 | while (*cp) | |
@@ -368,45 +368,45 @@ s_strstr(const Char *s, const Char *t) | @@ -368,45 +368,45 @@ s_strstr(const Char *s, const Char *t) | |||
368 | 368 | |||
369 | char * | 369 | char * | |
370 | short2qstr(const Char *src) | 370 | short2qstr(const Char *src) | |
371 | { | 371 | { | |
372 | static char *sdst = NULL; | 372 | static char *sdst = NULL; | |
373 | static size_t dstsize = 0; | 373 | static size_t dstsize = 0; | |
374 | char *dst, *edst; | 374 | char *dst, *edst; | |
375 | 375 | |||
376 | if (src == NULL) | 376 | if (src == NULL) | |
377 | return (NULL); | 377 | return (NULL); | |
378 | 378 | |||
379 | if (sdst == NULL) { | 379 | if (sdst == NULL) { | |
380 | dstsize = MALLOC_INCR; | 380 | dstsize = MALLOC_INCR; | |
381 | sdst = xmalloc((size_t)dstsize * sizeof(*sdst)); | 381 | sdst = xreallocarray(NULL, dstsize, sizeof(*sdst)); | |
382 | } | 382 | } | |
383 | dst = sdst; | 383 | dst = sdst; | |
384 | edst = &dst[dstsize]; | 384 | edst = &dst[dstsize]; | |
385 | while (*src) { | 385 | while (*src) { | |
386 | 386 | |||
387 | if (*src & QUOTE) { | 387 | if (*src & QUOTE) { | |
388 | *dst++ = '\\'; | 388 | *dst++ = '\\'; | |
389 | if (dst == edst) { | 389 | if (dst == edst) { | |
390 | dstsize += MALLOC_INCR; | 390 | dstsize += MALLOC_INCR; | |
391 | sdst = xrealloc(sdst, (size_t)dstsize * sizeof(*sdst)); | 391 | sdst = xreallocarray(sdst, (size_t)dstsize, sizeof(*sdst)); | |
392 | edst = &sdst[dstsize]; | 392 | edst = &sdst[dstsize]; | |
393 | dst = &edst[-MALLOC_INCR]; | 393 | dst = &edst[-MALLOC_INCR]; | |
394 | } | 394 | } | |
395 | } | 395 | } | |
396 | *dst++ = (char) *src++; | 396 | *dst++ = (char) *src++; | |
397 | if (dst == edst) { | 397 | if (dst == edst) { | |
398 | dstsize += MALLOC_INCR; | 398 | dstsize += MALLOC_INCR; | |
399 | sdst = xrealloc(sdst, (size_t)dstsize * sizeof(*sdst)); | 399 | sdst = xreallocarray(sdst, (size_t)dstsize, sizeof(*sdst)); | |
400 | edst = &sdst[dstsize]; | 400 | edst = &sdst[dstsize]; | |
401 | dst = &edst[-MALLOC_INCR]; | 401 | dst = &edst[-MALLOC_INCR]; | |
402 | } | 402 | } | |
403 | } | 403 | } | |
404 | *dst = 0; | 404 | *dst = 0; | |
405 | return (sdst); | 405 | return (sdst); | |
406 | } | 406 | } | |
407 | 407 | |||
408 | /* | 408 | /* | |
409 | * XXX: Should we worry about QUOTE'd chars? | 409 | * XXX: Should we worry about QUOTE'd chars? | |
410 | */ | 410 | */ | |
411 | char * | 411 | char * | |
412 | vis_str(const Char *cp) | 412 | vis_str(const Char *cp) | |
@@ -414,24 +414,24 @@ vis_str(const Char *cp) | @@ -414,24 +414,24 @@ vis_str(const Char *cp) | |||
414 | static char *sdst = NULL; | 414 | static char *sdst = NULL; | |
415 | static size_t dstsize = 0; | 415 | static size_t dstsize = 0; | |
416 | const Char *dp; | 416 | const Char *dp; | |
417 | size_t n; | 417 | size_t n; | |
418 | 418 | |||
419 | if (cp == NULL) | 419 | if (cp == NULL) | |
420 | return (NULL); | 420 | return (NULL); | |
421 | 421 | |||
422 | for (dp = cp; *dp++;) | 422 | for (dp = cp; *dp++;) | |
423 | continue; | 423 | continue; | |
424 | n = ((size_t)(dp - cp) << 2) + 1; /* 4 times + NULL */ | 424 | n = ((size_t)(dp - cp) << 2) + 1; /* 4 times + NULL */ | |
425 | if (dstsize < n) { | 425 | if (dstsize < n) { | |
426 | sdst = (dstsize ? | 426 | sdst = (dstsize ? | |
427 | xrealloc(sdst, (size_t)n * sizeof(*sdst)) : | 427 | xreallocarray(sdst, (size_t)n, sizeof(*sdst)) : | |
428 | xmalloc((size_t)n * sizeof(*sdst))); | 428 | xreallocarray(NULL, (size_t)n, sizeof(*sdst))); | |
429 | dstsize = n; | 429 | dstsize = n; | |
430 | } | 430 | } | |
431 | /* | 431 | /* | |
432 | * XXX: When we are in AsciiOnly we want all characters >= 0200 to | 432 | * XXX: When we are in AsciiOnly we want all characters >= 0200 to | |
433 | * be encoded, but currently there is no way in vis to do that. | 433 | * be encoded, but currently there is no way in vis to do that. | |
434 | */ | 434 | */ | |
435 | (void)strvis(sdst, short2str(cp), VIS_NOSLASH); | 435 | (void)strvis(sdst, short2str(cp), VIS_NOSLASH); | |
436 | return (sdst); | 436 | return (sdst); | |
437 | } | 437 | } |