Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/bin/sh Pull up following revision(s) (requested by kre in...
details: https://anonhg.NetBSD.org/src/rev/9ea60332fdfb
branches: netbsd-8
changeset: 435212:9ea60332fdfb
user: martin <martin%NetBSD.org@localhost>
date: Sat Aug 25 14:45:37 2018 +0000
description:
Pull up following revision(s) (requested by kre in ticket #988):
bin/sh/parser.c: revision 1.147
bin/sh/var.c: revision 1.70
bin/sh/mystring.c: revision 1.18
bin/sh/options.c: revision 1.53
bin/sh/histedit.c: revision 1.53
Remove atoi()
Mostly use number() (no longer implemented using atoi()) when an
unsigned integer is required, but use strtoXXX() when a conversion
is wanted, without the possibility or error (like setting OPTIND
and RANDOM). Always init OPTIND to 1 when sh starts (overriding
anything in environ.)
diffstat:
bin/sh/histedit.c | 10 +++++-----
bin/sh/mystring.c | 17 ++++++++++++-----
bin/sh/options.c | 12 +++++++++---
bin/sh/parser.c | 6 +++---
bin/sh/var.c | 12 ++++++++----
5 files changed, 37 insertions(+), 20 deletions(-)
diffs (205 lines):
diff -r 28a167dc8976 -r 9ea60332fdfb bin/sh/histedit.c
--- a/bin/sh/histedit.c Sat Aug 25 14:41:21 2018 +0000
+++ b/bin/sh/histedit.c Sat Aug 25 14:45:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: histedit.c,v 1.48.8.1 2017/07/23 14:58:14 snj Exp $ */
+/* $NetBSD: histedit.c,v 1.48.8.2 2018/08/25 14:45:37 martin Exp $ */
/*-
* Copyright (c) 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: histedit.c,v 1.48.8.1 2017/07/23 14:58:14 snj Exp $");
+__RCSID("$NetBSD: histedit.c,v 1.48.8.2 2018/08/25 14:45:37 martin Exp $");
#endif
#endif /* not lint */
@@ -210,8 +210,8 @@
HistEvent he;
if (hist != NULL) {
- if (hs == NULL || *hs == '\0' ||
- (histsize = atoi(hs)) < 0)
+ if (hs == NULL || *hs == '\0' || *hs == '-' ||
+ (histsize = number(hs)) < 0)
histsize = 100;
history(hist, &he, H_SETSIZE, histsize);
history(hist, &he, H_SETUNIQUE, 1);
@@ -529,7 +529,7 @@
s++;
}
if (is_number(s)) {
- i = atoi(s);
+ i = number(s);
if (relative) {
while (retval != -1 && i--) {
retval = history(hist, &he, H_NEXT);
diff -r 28a167dc8976 -r 9ea60332fdfb bin/sh/mystring.c
--- a/bin/sh/mystring.c Sat Aug 25 14:41:21 2018 +0000
+++ b/bin/sh/mystring.c Sat Aug 25 14:45:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mystring.c,v 1.17 2013/04/28 17:01:28 dholland Exp $ */
+/* $NetBSD: mystring.c,v 1.17.22.1 2018/08/25 14:45:37 martin Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)mystring.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: mystring.c,v 1.17 2013/04/28 17:01:28 dholland Exp $");
+__RCSID("$NetBSD: mystring.c,v 1.17.22.1 2018/08/25 14:45:37 martin Exp $");
#endif
#endif /* not lint */
@@ -51,6 +51,8 @@
* is_number(s) Return true if s is a string of digits.
*/
+#include <inttypes.h>
+#include <limits.h>
#include <stdlib.h>
#include "shell.h"
#include "syntax.h"
@@ -110,10 +112,15 @@
int
number(const char *s)
{
+ char *ep = NULL;
+ intmax_t n;
- if (! is_number(s))
- error("Illegal number: %s", s);
- return atoi(s);
+ if (!is_digit(*s) || ((n = strtoimax(s, &ep, 10)),
+ (ep == NULL || ep == s || *ep != '\0')))
+ error("Illegal number: '%s'", s);
+ if (n < INT_MIN || n > INT_MAX)
+ error("Number out of range: %s", s);
+ return (int)n;
}
diff -r 28a167dc8976 -r 9ea60332fdfb bin/sh/options.c
--- a/bin/sh/options.c Sat Aug 25 14:41:21 2018 +0000
+++ b/bin/sh/options.c Sat Aug 25 14:45:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: options.c,v 1.49 2017/05/29 14:03:23 kre Exp $ */
+/* $NetBSD: options.c,v 1.49.2.1 2018/08/25 14:45:37 martin Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: options.c,v 1.49 2017/05/29 14:03:23 kre Exp $");
+__RCSID("$NetBSD: options.c,v 1.49.2.1 2018/08/25 14:45:37 martin Exp $");
#endif
#endif /* not lint */
@@ -60,6 +60,7 @@
#include "memalloc.h"
#include "error.h"
#include "mystring.h"
+#include "syntax.h"
#ifndef SMALL
#include "myhistedit.h"
#endif
@@ -444,7 +445,12 @@
void
getoptsreset(const char *value)
{
- if (number(value) == 1) {
+ /*
+ * This is just to detect the case where OPTIND=1
+ * is executed. Any other string assigned to OPTIND
+ * is OK, but is not a reset. No errors, so cannot use number()
+ */
+ if (is_digit(*value) && strtol(value, NULL, 10) == 1) {
shellparam.optnext = NULL;
shellparam.reset = 1;
}
diff -r 28a167dc8976 -r 9ea60332fdfb bin/sh/parser.c
--- a/bin/sh/parser.c Sat Aug 25 14:41:21 2018 +0000
+++ b/bin/sh/parser.c Sat Aug 25 14:45:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parser.c,v 1.132.2.4 2018/05/06 09:32:57 martin Exp $ */
+/* $NetBSD: parser.c,v 1.132.2.5 2018/08/25 14:45:37 martin Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
#else
-__RCSID("$NetBSD: parser.c,v 1.132.2.4 2018/05/06 09:32:57 martin Exp $");
+__RCSID("$NetBSD: parser.c,v 1.132.2.5 2018/08/25 14:45:37 martin Exp $");
#endif
#endif /* not lint */
@@ -1528,7 +1528,7 @@
union node *np;
int fd;
- fd = (*out == '\0') ? -1 : atoi(out);
+ fd = (*out == '\0') ? -1 : number(out);
np = stalloc(sizeof(struct nfile));
if (c == '>') {
diff -r 28a167dc8976 -r 9ea60332fdfb bin/sh/var.c
--- a/bin/sh/var.c Sat Aug 25 14:41:21 2018 +0000
+++ b/bin/sh/var.c Sat Aug 25 14:45:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.55.2.2 2017/08/31 11:43:44 martin Exp $ */
+/* $NetBSD: var.c,v 1.55.2.3 2018/08/25 14:45:37 martin Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: var.c,v 1.55.2.2 2017/08/31 11:43:44 martin Exp $");
+__RCSID("$NetBSD: var.c,v 1.55.2.3 2018/08/25 14:45:37 martin Exp $");
#endif
#endif /* not lint */
@@ -50,6 +50,7 @@
#include <time.h>
#include <pwd.h>
#include <fcntl.h>
+#include <inttypes.h>
/*
* Shell variables.
@@ -230,14 +231,17 @@
*
* PPID is readonly
* Always default IFS
+ * POSIX: "Whenever the shell is invoked, OPTIND shall
+ * be initialized to 1."
* PSc indicates the root/non-root status of this shell.
+ * START_TIME belongs only to this shell.
* NETBSD_SHELL is a constant (readonly), and is never exported
- * START_TIME belongs only to this shell.
* LINENO is simply magic...
*/
snprintf(buf, sizeof(buf), "%d", (int)getppid());
setvar("PPID", buf, VREADONLY);
setvar("IFS", ifs_default, VTEXTFIXED);
+ setvar("OPTIND", "1", VTEXTFIXED);
setvar("PSc", (geteuid() == 0 ? "#" : "$"), VTEXTFIXED);
#ifndef SMALL
@@ -1398,7 +1402,7 @@
}
} else
/* good enough for today */
- random_val = atoi(vp->text + vp->name_len + 1);
+ random_val = strtoimax(vp->text+vp->name_len+1,NULL,0);
srandom((long)random_val);
}
Home |
Main Index |
Thread Index |
Old Index