[Bug 264656] sh(1): should disregard trailing blanks in variables in arithmetic expressions.
Date: Mon, 13 Jun 2022 12:50:13 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264656
--- Comment #1 from Rajeev Pillai <rajeev_v_pillai@yahoo.com> ---
A better patch is this one (saves 2 function calls):
---START---
diff -urN bin/sh.orig/arith_yacc.c bin/sh/arith_yacc.c
--- bin/sh.orig/arith_yacc.c 2022-05-12 04:53:55.000000000 +0000
+++ bin/sh/arith_yacc.c 2022-06-13 12:39:52.888785000 +0000
@@ -35,6 +35,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <ctype.h>
#include <limits.h>
#include <errno.h>
#include <inttypes.h>
@@ -92,6 +93,13 @@
/* NOTREACHED */
}
+static inline int is_blank(const char *p)
+{
+ while (isspace((unsigned char)*p))
+ p++;
+ return *p == '\0';
+}
+
static arith_t arith_lookupvarint(char *varname)
{
const char *str;
@@ -105,7 +113,7 @@
str = "0";
errno = 0;
result = strtoarith_t(str, &p);
- if (errno != 0 || *p != '\0')
+ if (errno != 0 || !is_blank(p))
yyerror("variable conversion error");
return result;
}
---END---
--
You are receiving this mail because:
You are the assignee for the bug.