From 03466a680634e06fa91eeced376f2f07413ff007 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sun, 22 Mar 2020 18:55:14 -0700 Subject: [PATCH] SCP: Tolerate commas in decimal numbers during expression evaluation --- scp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/scp.c b/scp.c index 562b9dfa..9f8f4dac 100644 --- a/scp.c +++ b/scp.c @@ -14778,8 +14778,34 @@ else { *buf = '\0'; } else { /* Decimal Number */ - while (isdigit (*cptr)) - *buf++ = *cptr++; + int digits = 0; + int commas = 0; + const char *cp = cptr; + + /* Ignore commas in decimal numbers */ + while (isdigit (*cp) || (*cp == ',')) { + if (*cp == ',') + ++commas; + else + ++digits; + ++cp; + } + if ((commas > 0) && (commas != (digits - 1)/3)) { + *stat = SCPE_INVEXPR; + return cptr; + } + while (commas--) { + cp -= 4; + if (*cp != ',') { + *stat = SCPE_INVEXPR; + return cptr; + } + } + while (isdigit (*cptr) || (*cptr == ',')) { + if (*cptr != ',') + *buf++ = *cptr; + ++cptr; + } *buf = '\0'; } }