hush: delete hush-bugs/glob_and_vars.tests for real
[oweals/busybox.git] / shell / ash.c
index 3651929c229caed0455f2c19e44b571f25bb1304..b490b69f1c3a52647a8f60dd971cc8da5f4c5fee 100644 (file)
@@ -1258,7 +1258,7 @@ stunalloc(void *p)
 {
 #if DEBUG
        if (!p || (g_stacknxt < (char *)p) || ((char *)p < g_stackp->space)) {
-               write(2, "stunalloc\n", 10);
+               write(STDERR_FILENO, "stunalloc\n", 10);
                abort();
        }
 #endif
@@ -1360,7 +1360,7 @@ growstackblock(void)
                INT_ON;
        } else {
                char *oldspace = g_stacknxt;
-               int oldlen = g_stacknleft;
+               size_t oldlen = g_stacknleft;
                char *p = stalloc(newlen);
 
                /* free the space we just allocated */
@@ -1403,7 +1403,7 @@ growstackstr(void)
                return stackblock();
        }
        growstackblock();
-       return stackblock() + len;
+       return (char *)stackblock() + len;
 }
 
 /*
@@ -1424,14 +1424,14 @@ makestrspace(size_t newlen, char *p)
                        break;
                growstackblock();
        }
-       return stackblock() + len;
+       return (char *)stackblock() + len;
 }
 
 static char *
 stack_nputstr(const char *s, size_t n, char *p)
 {
        p = makestrspace(n, p);
-       p = memcpy(p, s, n) + n;
+       p = (char *)memcpy(p, s, n) + n;
        return p;
 }
 
@@ -1536,7 +1536,7 @@ single_quote(const char *s)
                q = p = makestrspace(len + 3, p);
 
                *q++ = '\'';
-               q = memcpy(q, s, len) + len;
+               q = (char *)memcpy(q, s, len) + len;
                *q++ = '\'';
                s += len;
 
@@ -1549,7 +1549,7 @@ single_quote(const char *s)
                q = p = makestrspace(len + 3, p);
 
                *q++ = '"';
-               q = memcpy(q, s, len) + len;
+               q = (char *)memcpy(q, s, len) + len;
                *q++ = '"';
                s += len;
 
@@ -1790,7 +1790,7 @@ extern struct globals_var *const ash_ptr_to_globals_var;
 #define vartab        (G_var.vartab       )
 #define varinit       (G_var.varinit      )
 #define INIT_G_var() do { \
-       int i; \
+       unsigned i; \
        (*(struct globals_var**)&ash_ptr_to_globals_var) = xzalloc(sizeof(G_var)); \
        barrier(); \
        for (i = 0; i < ARRAY_SIZE(varinit_data); i++) { \
@@ -2079,10 +2079,10 @@ setvar(const char *name, const char *val, int flags)
        }
        INT_OFF;
        nameeq = ckmalloc(namelen + vallen + 2);
-       p = memcpy(nameeq, name, namelen) + namelen;
+       p = (char *)memcpy(nameeq, name, namelen) + namelen;
        if (val) {
                *p++ = '=';
-               p = memcpy(p, val, vallen) + vallen;
+               p = (char *)memcpy(p, val, vallen) + vallen;
        }
        *p = '\0';
        setvareq(nameeq, flags | VNOSAVE);
@@ -2364,7 +2364,7 @@ updatepwd(const char *dir)
                new = stack_putstr(curdir, new);
        }
        new = makestrspace(strlen(dir) + 2, new);
-       lim = stackblock() + 1;
+       lim = (char *)stackblock() + 1;
        if (*dir != '/') {
                if (new[-1] != '/')
                        USTPUTC('/', new);
@@ -4789,7 +4789,7 @@ openhere(union node *redir)
                        full_write(pip[1], redir->nhere.doc->narg.text, len);
                else
                        expandhere(redir->nhere.doc, pip[1]);
-               _exit(0);
+               _exit(EXIT_SUCCESS);
        }
  out:
        close(pip[1]);
@@ -5157,7 +5157,7 @@ _rmescapes(char *str, int flag)
                }
                q = r;
                if (len > 0) {
-                       q = memcpy(q, str, len) + len;
+                       q = (char *)memcpy(q, str, len) + len;
                }
        }
        inquotes = (flag & RMESCAPE_QUOTED) ^ RMESCAPE_QUOTED;
@@ -5426,7 +5426,7 @@ expbackq(union node *cmd, int quoted, int quotes)
        char *p;
        char *dest;
        int startloc;
-       int syntax = quoted? DQSYNTAX : BASESYNTAX;
+       int syntax = quoted ? DQSYNTAX : BASESYNTAX;
        struct stackmark smark;
 
        INT_OFF;
@@ -5691,13 +5691,39 @@ static char *
 scanleft(char *startp, char *rmesc, char *rmescend ATTRIBUTE_UNUSED, char *str, int quotes,
        int zero)
 {
-       char *loc, *loc2, *full;
+// This commented out code was added by James Simmons <jsimmons@infradead.org>
+// as part of a larger change when he added support for ${var/a/b}.
+// However, it broke # and % operators:
+//
+//var=ababcdcd
+//                 ok       bad
+//echo ${var#ab}   abcdcd   abcdcd
+//echo ${var##ab}  abcdcd   abcdcd
+//echo ${var#a*b}  abcdcd   ababcdcd  (!)
+//echo ${var##a*b} cdcd     cdcd
+//echo ${var#?}    babcdcd  ababcdcd  (!)
+//echo ${var##?}   babcdcd  babcdcd
+//echo ${var#*}    ababcdcd babcdcd   (!)
+//echo ${var##*}
+//echo ${var%cd}   ababcd   ababcd
+//echo ${var%%cd}  ababcd   abab      (!)
+//echo ${var%c*d}  ababcd   ababcd
+//echo ${var%%c*d} abab     ababcdcd  (!)
+//echo ${var%?}    ababcdc  ababcdc
+//echo ${var%%?}   ababcdc  ababcdcd  (!)
+//echo ${var%*}    ababcdcd ababcdcd
+//echo ${var%%*}
+//
+// Commenting it back out helped. Remove it completely if it really
+// is not needed.
+
+       char *loc, *loc2; //, *full;
        char c;
 
        loc = startp;
        loc2 = rmesc;
        do {
-               int match = strlen(str);
+               int match; // = strlen(str);
                const char *s = loc2;
 
                c = *loc2;
@@ -5705,23 +5731,24 @@ scanleft(char *startp, char *rmesc, char *rmescend ATTRIBUTE_UNUSED, char *str,
                        *loc2 = '\0';
                        s = rmesc;
                }
-
-               // chop off end if its '*'
-               full = strrchr(str, '*');
-               if (full && full != str)
-                       match--;
-
-               // If str starts with '*' replace with s.
-               if ((*str == '*') && strlen(s) >= match) {
-                       full = xstrdup(s);
-                       strncpy(full+strlen(s)-match+1, str+1, match-1);
-               } else
-                       full = xstrndup(str, match);
-               match = strncmp(s, full, strlen(full));
-               free(full);
-
+               match = pmatch(str, s); // this line was deleted
+
+//             // chop off end if its '*'
+//             full = strrchr(str, '*');
+//             if (full && full != str)
+//                     match--;
+//
+//             // If str starts with '*' replace with s.
+//             if ((*str == '*') && strlen(s) >= match) {
+//                     full = xstrdup(s);
+//                     strncpy(full+strlen(s)-match+1, str+1, match-1);
+//             } else
+//                     full = xstrndup(str, match);
+//             match = strncmp(s, full, strlen(full));
+//             free(full);
+//
                *loc2 = c;
-               if (!match)
+               if (match) // if (!match)
                        return loc;
                if (quotes && *loc == CTLESC)
                        loc++;
@@ -5791,73 +5818,26 @@ parse_sub_pattern(char *arg, int inquotes)
        char *idx, *repl = NULL;
        unsigned char c;
 
-       for (idx = arg; *arg; arg++) {
-               if (*arg == '/') {
-                       /* Only the first '/' seen is our seperator */
+       idx = arg;
+       while (1) {
+               c = *arg;
+               if (!c)
+                       break;
+               if (c == '/') {
+                       /* Only the first '/' seen is our separator */
                        if (!repl) {
-                               *idx++ = '\0';
-                               repl = idx;
-                       } else
-                               *idx++ = *arg;
-                       } else if (*arg != '\\') {
-                               *idx++ = *arg;
-                       } else {
-                               if (inquotes)
-                                       arg++;
-                               else {
-                                       if (*(arg + 1) != '\\')
-                                               goto single_backslash;
-                                       arg += 2;
-                               }
-
-                       switch (*arg) {
-                       case 'n':       c = '\n'; break;
-                       case 'r':       c = '\r'; break;
-                       case 't':       c = '\t'; break;
-                       case 'v':       c = '\v'; break;
-                       case 'f':       c = '\f'; break;
-                       case 'b':       c = '\b'; break;
-                       case 'a':       c = '\a'; break;
-                       case '\\':
-                               if (*(arg + 1) != '\\' && !inquotes)
-                                       goto single_backslash;
-                               arg++;
-                               /* FALLTHROUGH */
-                       case '\0':
-                               /* Trailing backslash, just stuff one in the buffer
-                                * and backup arg so the loop will exit.
-                                */
-                               c = '\\';
-                               if (!*arg)
-                                       arg--;
-                               break;
-                       default:
-                               c = *arg;
-                               if (isdigit(c)) {
-                                       /* It's an octal number, parse it. */
-                                       int i;
-                                       c = 0;
-
-                                       for (i = 0; *arg && i < 3; arg++, i++) {
-                                               if (*arg >= '8' || *arg < '0')
-                                                       ash_msg_and_raise_error("Invalid octal char in pattern");
-// TODO: number() instead? It does error checking...
-                                               c = (c << 3) + atoi(arg);
-                                       }
-                                       /* back off one (so outer loop can do it) */
-                                       arg--;
-                               }
+                               repl = idx + 1;
+                               c = '\0';
                        }
-                       *idx++ = c;
                }
+               *idx++ = c;
+               if (!inquotes && c == '\\' && arg[1] == '\\')
+                       arg++; /* skip both \\, not just first one */
+               arg++;
        }
-       *idx = *arg;
+       *idx = c; /* NUL */
 
        return repl;
-
- single_backslash:
-       ash_msg_and_raise_error("single backslash unexpected");
-       /* NOTREACHED */
 }
 #endif /* ENABLE_ASH_BASH_COMPAT */
 
@@ -5883,7 +5863,7 @@ subevalvar(char *p, char *str, int strloc, int subtype,
        STPUTC('\0', expdest);
        herefd = saveherefd;
        argbackq = saveargbackq;
-       startp = stackblock() + startloc;
+       startp = (char *)stackblock() + startloc;
 
        switch (subtype) {
        case VSASSIGN:
@@ -5961,19 +5941,19 @@ subevalvar(char *p, char *str, int strloc, int subtype,
 
        amount = expdest - ((char *)stackblock() + resetloc);
        STADJUST(-amount, expdest);
-       startp = stackblock() + startloc;
+       startp = (char *)stackblock() + startloc;
 
        rmesc = startp;
-       rmescend = stackblock() + strloc;
+       rmescend = (char *)stackblock() + strloc;
        if (quotes) {
                rmesc = _rmescapes(startp, RMESCAPE_ALLOC | RMESCAPE_GROW);
                if (rmesc != startp) {
                        rmescend = expdest;
-                       startp = stackblock() + startloc;
+                       startp = (char *)stackblock() + startloc;
                }
        }
        rmescend--;
-       str = stackblock() + strloc;
+       str = (char *)stackblock() + strloc;
        preglob(str, varflags & VSQUOTE, 0);
        workloc = expdest - (char *)stackblock();
 
@@ -6196,7 +6176,7 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list)
                                if (!eq) /* stop at first non-assignment */
                                        break;
                                eq++;
-                               if (name_len == (eq - str)
+                               if (name_len == (unsigned)(eq - str)
                                 && strncmp(str, name, name_len) == 0) {
                                        p = eq;
                                        /* goto value; - WRONG! */
@@ -6828,9 +6808,13 @@ struct builtincmd {
 #define IS_BUILTIN_ASSIGN(b)  ((b)->name[0] & 4)
 
 struct cmdentry {
-       int cmdtype;
+       smallint cmdtype;       /* CMDxxx */
        union param {
                int index;
+               /* index >= 0 for commands without path (slashes) */
+               /* (TODO: what exactly does the value mean? PATH position?) */
+               /* index == -1 for commands with slashes */
+               /* index == (-2 - applet_no) for NOFORK applets */
                const struct builtincmd *cmd;
                struct funcnode *func;
        } u;
@@ -6867,7 +6851,7 @@ static void find_command(char *, struct cmdentry *, int, const char *);
 struct tblentry {
        struct tblentry *next;  /* next entry in hash chain */
        union param param;      /* definition of builtin function */
-       short cmdtype;          /* index identifying command */
+       smallint cmdtype;       /* CMDxxx */
        char rehash;            /* if set, cd done since entry created */
        char cmdname[ARB];      /* name of command */
 };
@@ -6881,21 +6865,18 @@ static int builtinloc = -1;     /* index in path of %builtin, or -1 */
 
 
 static void
-tryexec(char *cmd, char **argv, char **envp)
+tryexec(USE_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **envp)
 {
        int repeated = 0;
 
 #if ENABLE_FEATURE_SH_STANDALONE
-       if (strchr(cmd, '/') == NULL) {
-               int a = find_applet_by_name(cmd);
-               if (a >= 0) {
-                       if (APPLET_IS_NOEXEC(a))
-                               run_applet_no_and_exit(a, argv);
-                       /* re-exec ourselves with the new arguments */
-                       execve(bb_busybox_exec_path, argv, envp);
-                       /* If they called chroot or otherwise made the binary no longer
-                        * executable, fall through */
-               }
+       if (applet_no >= 0) {
+               if (APPLET_IS_NOEXEC(applet_no))
+                       run_applet_no_and_exit(applet_no, argv);
+               /* re-exec ourselves with the new arguments */
+               execve(bb_busybox_exec_path, argv, envp);
+               /* If they called chroot or otherwise made the binary no longer
+                * executable, fall through */
        }
 #endif
 
@@ -6931,7 +6912,6 @@ tryexec(char *cmd, char **argv, char **envp)
  * Exec a program.  Never returns.  If you change this routine, you may
  * have to change the find_command routine as well.
  */
-#define environment() listvars(VEXPORT, VUNSET, 0)
 static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN;
 static void
 shellexec(char **argv, const char *path, int idx)
@@ -6940,21 +6920,24 @@ shellexec(char **argv, const char *path, int idx)
        int e;
        char **envp;
        int exerrno;
+#if ENABLE_FEATURE_SH_STANDALONE
+       int applet_no = -1;
+#endif
 
        clearredir(1);
-       envp = environment();
-       if (strchr(argv[0], '/')
+       envp = listvars(VEXPORT, VUNSET, 0);
+       if (strchr(argv[0], '/') != NULL
 #if ENABLE_FEATURE_SH_STANDALONE
-        || find_applet_by_name(argv[0]) >= 0
+        || (applet_no = find_applet_by_name(argv[0])) >= 0
 #endif
        ) {
-               tryexec(argv[0], argv, envp);
+               tryexec(USE_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, envp);
                e = errno;
        } else {
                e = ENOENT;
                while ((cmdname = padvance(&path, argv[0])) != NULL) {
                        if (--idx < 0 && pathopt == NULL) {
-                               tryexec(cmdname, argv, envp);
+                               tryexec(USE_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp);
                                if (errno != ENOENT && errno != ENOTDIR)
                                        e = errno;
                        }
@@ -7356,7 +7339,7 @@ describe_command(char *command, int describe_command_verbose)
        case CMDNORMAL: {
                int j = entry.u.index;
                char *p;
-               if (j == -1) {
+               if (j < 0) {
                        p = command;
                } else {
                        do {
@@ -8417,12 +8400,6 @@ returncmd(int argc ATTRIBUTE_UNUSED, char **argv)
 static int breakcmd(int, char **);
 static int dotcmd(int, char **);
 static int evalcmd(int, char **);
-#if ENABLE_ASH_BUILTIN_ECHO
-static int echocmd(int, char **);
-#endif
-#if ENABLE_ASH_BUILTIN_TEST
-static int testcmd(int, char **);
-#endif
 static int exitcmd(int, char **);
 static int exportcmd(int, char **);
 #if ENABLE_ASH_GETOPTS
@@ -8464,14 +8441,18 @@ static int ulimitcmd(int, char **);
  * Apart from the above, [[ expr ]] should work as [ expr ]
  */
 
+#define echocmd   echo_main
+#define printfcmd printf_main
+#define testcmd   test_main
+
 /* Keep these in proper order since it is searched via bsearch() */
 static const struct builtincmd builtintab[] = {
        { BUILTIN_SPEC_REG      ".", dotcmd },
        { BUILTIN_SPEC_REG      ":", truecmd },
 #if ENABLE_ASH_BUILTIN_TEST
-       { BUILTIN_REGULAR       "[", testcmd },
+       { BUILTIN_REGULAR       "[", testcmd },
 #if ENABLE_ASH_BASH_COMPAT
-       { BUILTIN_REGULAR       "[[", testcmd },
+       { BUILTIN_REGULAR       "[[", testcmd },
 #endif
 #endif
 #if ENABLE_ASH_ALIAS
@@ -8513,6 +8494,9 @@ static const struct builtincmd builtintab[] = {
        { BUILTIN_NOSPEC        "let", letcmd },
 #endif
        { BUILTIN_ASSIGN        "local", localcmd },
+#if ENABLE_ASH_BUILTIN_PRINTF
+       { BUILTIN_REGULAR       "printf", printfcmd },
+#endif
        { BUILTIN_NOSPEC        "pwd", pwdcmd },
        { BUILTIN_REGULAR       "read", readcmd },
        { BUILTIN_SPEC_REG_ASSG "readonly", exportcmd },
@@ -8521,7 +8505,7 @@ static const struct builtincmd builtintab[] = {
        { BUILTIN_SPEC_REG      "shift", shiftcmd },
        { BUILTIN_SPEC_REG      "source", dotcmd },
 #if ENABLE_ASH_BUILTIN_TEST
-       { BUILTIN_REGULAR       "test", testcmd },
+       { BUILTIN_REGULAR       "test", testcmd },
 #endif
        { BUILTIN_SPEC_REG      "times", timescmd },
        { BUILTIN_SPEC_REG      "trap", trapcmd },
@@ -8751,6 +8735,19 @@ evalcommand(union node *cmd, int flags)
        /* Execute the command. */
        switch (cmdentry.cmdtype) {
        default:
+#if ENABLE_FEATURE_SH_NOFORK
+       {
+               /* find_command() encodes applet_no as (-2 - applet_no) */
+               int applet_no = (- cmdentry.u.index - 2);
+               if (applet_no >= 0 && APPLET_IS_NOFORK(applet_no)) {
+                       listsetvar(varlist.list, VEXPORT|VSTACK);
+                       /* run <applet>_main() */
+                       exitstatus = run_nofork_applet(applet_no, argv);
+                       break;
+               }
+       }
+#endif
+
                /* Fork off a child process if necessary. */
                if (!(flags & EV_EXIT) || trap[0]) {
                        INT_OFF;
@@ -9446,7 +9443,7 @@ setparam(char **argv)
  * Oh well. Let's mimic that.
  */
 static int
-minus_o(char *name, int val)
+plus_minus_o(char *name, int val)
 {
        int i;
 
@@ -9457,13 +9454,16 @@ minus_o(char *name, int val)
                                return 0;
                        }
                }
-               ash_msg("illegal option -o %s", name);
+               ash_msg("illegal option %co %s", val ? '-' : '+', name);
                return 1;
        }
-       out1str("Current option settings\n");
-       for (i = 0; i < NOPTS; i++)
-               out1fmt("%-16s%s\n", optnames(i),
-                               optlist[i] ? "on" : "off");
+       for (i = 0; i < NOPTS; i++) {
+               if (val) {
+                       out1fmt("%-16s%s\n", optnames(i), optlist[i] ? "on" : "off");
+               } else {
+                       out1fmt("set %co %s\n", optlist[i] ? '-' : '+', optnames(i));
+               }
+       }
        return 0;
 }
 static void
@@ -9477,7 +9477,7 @@ setoption(int flag, int val)
                        return;
                }
        }
-       ash_msg_and_raise_error("illegal option -%c", flag);
+       ash_msg_and_raise_error("illegal option %c%c", val ? '-' : '+', flag);
        /* NOTREACHED */
 }
 static int
@@ -9515,7 +9515,7 @@ options(int cmdline)
                        if (c == 'c' && cmdline) {
                                minusc = p;     /* command is after shell args */
                        } else if (c == 'o') {
-                               if (minus_o(*argptr, val)) {
+                               if (plus_minus_o(*argptr, val)) {
                                        /* it already printed err message */
                                        return 1; /* error */
                                }
@@ -9657,7 +9657,7 @@ getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *opt
                return 1;
        optnext = optfirst + *param_optind - 1;
 
-       if (*param_optind <= 1 || *optoff < 0 || strlen(optnext[-1]) < *optoff)
+       if (*param_optind <= 1 || *optoff < 0 || (int)strlen(optnext[-1]) < *optoff)
                p = NULL;
        else
                p = optnext[-1] + *optoff;
@@ -10718,7 +10718,7 @@ parsesub: {
 #if ENABLE_ASH_MATH_SUPPORT
                        PARSEARITH();
 #else
-                       raise_error_syntax("We unsupport $((arith))");
+                       raise_error_syntax("you disabled math support for $((arith)) syntax");
 #endif
                } else {
                        pungetc();
@@ -11079,7 +11079,7 @@ xxreadtoken(void)
                                                return readtoken1(c, BASESYNTAX, (char *) NULL, 0);
                                        }
 
-                                       if (p - xxreadtoken_chars >= xxreadtoken_singles) {
+                                       if ((size_t)(p - xxreadtoken_chars) >= xxreadtoken_singles) {
                                                if (pgetc() == *p) {    /* double occurrence? */
                                                        p += xxreadtoken_doubles + 1;
                                                } else {
@@ -11506,22 +11506,6 @@ exitcmd(int argc ATTRIBUTE_UNUSED, char **argv)
        /* NOTREACHED */
 }
 
-#if ENABLE_ASH_BUILTIN_ECHO
-static int
-echocmd(int argc, char **argv)
-{
-       return echo_main(argc, argv);
-}
-#endif
-
-#if ENABLE_ASH_BUILTIN_TEST
-static int
-testcmd(int argc, char **argv)
-{
-       return test_main(argc, argv);
-}
-#endif
-
 /*
  * Read a file containing shell functions.
  */
@@ -11620,10 +11604,13 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
        }
 
 #if ENABLE_FEATURE_SH_STANDALONE
-       if (find_applet_by_name(name) >= 0) {
-               entry->cmdtype = CMDNORMAL;
-               entry->u.index = -1;
-               return;
+       {
+               int applet_no = find_applet_by_name(name);
+               if (applet_no >= 0) {
+                       entry->cmdtype = CMDNORMAL;
+                       entry->u.index = -2 - applet_no;
+                       return;
+               }
        }
 #endif
 
@@ -11649,11 +11636,10 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
                                if (bcmd)
                                        goto builtin_success;
                                continue;
-                       } else if (!(act & DO_NOFUNC)
-                        && prefix(pathopt, "func")) {
-                               /* handled below */
-                       } else {
-                               /* ignore unimplemented options */
+                       }
+                       if ((act & DO_NOFUNC)
+                        || !prefix(pathopt, "func")
+                       ) {     /* ignore unimplemented options */
                                continue;
                        }
                }
@@ -11789,7 +11775,8 @@ trapcmd(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
 static int
 helpcmd(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
 {
-       int col, i;
+       unsigned col;
+       unsigned i;
 
        out1fmt("\nBuilt-in commands:\n-------------------\n");
        for (col = 0, i = 0; i < ARRAY_SIZE(builtintab); i++) {
@@ -12451,6 +12438,7 @@ ulimitcmd(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
 
                        while ((c = *p++) >= '0' && c <= '9') {
                                val = (val * 10) + (long)(c - '0');
+                               // val is actually 'unsigned long int' and can't get < 0
                                if (val < (rlim_t) 0)
                                        break;
                        }
@@ -12694,7 +12682,7 @@ is_right_associativity(operator prec)
                || prec == PREC(TOK_CONDITIONAL));
 }
 
-typedef struct ARITCH_VAR_NUM {
+typedef struct {
        arith_t val;
        arith_t contidional_second_val;
        char contidional_second_val_initialized;
@@ -12702,9 +12690,9 @@ typedef struct ARITCH_VAR_NUM {
                           else is variable name */
 } v_n_t;
 
-typedef struct CHK_VAR_RECURSIVE_LOOPED {
+typedef struct chk_var_recursive_looped_t {
        const char *var;
-       struct CHK_VAR_RECURSIVE_LOOPED *next;
+       struct chk_var_recursive_looped_t *next;
 } chk_var_recursive_looped_t;
 
 static chk_var_recursive_looped_t *prev_chk_var_recursive;