[COMMITTED] a68: fix calls to strtol and stroll [PR algol68/124372]

Jose E. Marchesi jemarch@gnu.org
Sun Mar 8 19:13:05 GMT 2026


This commit fixes the following problems related to parsing integer
and bits denotations:

1. strtou?l should be used only if itis 64-bit long.  Otherwise, use
   strtou?l.

2. Use unsigned conversions for bits denotations radix, for
consistency.

Tested in i686-linux-gnu and x86_64-linux-gnu.

Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>

gcc/algol68/ChangeLog

	PR algol68/124372
	* a68-low-units.cc (a68_lower_denotation): Call to strtoull if
	INT64_T_IS_LONG is not defined, strtol otherwise.
	* a68-parser-scanner.cc (get_next_token): Use strtoul for radix
	instead of strtol.
---
 gcc/algol68/a68-low-units.cc      | 20 +++++++++++++++-----
 gcc/algol68/a68-parser-scanner.cc |  5 +++--
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gcc/algol68/a68-low-units.cc b/gcc/algol68/a68-low-units.cc
index 86eb68cc141..3cbf131112b 100644
--- a/gcc/algol68/a68-low-units.cc
+++ b/gcc/algol68/a68-low-units.cc
@@ -287,18 +287,28 @@ a68_lower_denotation (NODE_T *p, LOW_CTX_T ctx)
 	s = SUB (p);
 
       type = CTYPE (moid);
-      int64_t radix = strtol (NSYMBOL (s), &end, 10);
-      gcc_assert (end != NSYMBOL (s) && *end == 'r');
+      errno = 0;
+#if defined(INT64_T_IS_LONG)
+      uint64_t radix = strtoul (NSYMBOL (s), &end, 10);
+#else
+      uint64_t radix = strtoull (NSYMBOL (s), &end, 10);
+#endif
+      gcc_assert (errno == 0 && end != NSYMBOL (s) && *end == 'r');
       end++;
-      int64_t val = strtol (end, &end, radix);
-      gcc_assert (end[0] == '\0');
+      errno = 0;
+#if defined(INT64_T_IS_LONG)
+      uint64_t val = strtoul (end, &end, radix);
+#else
+      uint64_t val = strtoull (end, &end, radix);
+#endif
+      gcc_assert (errno == 0 && end[0] == '\0');
       return build_int_cst (type, val);
     }
   else if (moid == M_REAL
 	   || moid == M_LONG_REAL
 	   || moid == M_LONG_LONG_REAL)
     {
-      /* SIZETY INT */
+      /* SIZETY REAL */
       tree type;
       NODE_T *s = NO_NODE;
       if (IS (SUB (p), LONGETY) || IS (SUB (p), SHORTETY))
diff --git a/gcc/algol68/a68-parser-scanner.cc b/gcc/algol68/a68-parser-scanner.cc
index af1251f125d..097accd5322 100644
--- a/gcc/algol68/a68-parser-scanner.cc
+++ b/gcc/algol68/a68-parser-scanner.cc
@@ -1675,8 +1675,9 @@ get_next_token (bool in_format,
 	  /* Parse the radix, which is expressed in base 10.  */
 	  (sym++)[0] = c;
 	  char *end;
-	  int64_t radix = strtol (A68_PARSER (scan_buf), &end, 10);
-	  gcc_assert (end != A68_PARSER (scan_buf) && *end == 'r');
+	  errno = 0;
+	  uint64_t radix = strtoul (A68_PARSER (scan_buf), &end, 10);
+	  gcc_assert (errno == 0 && end != A68_PARSER (scan_buf) && *end == 'r');
 
 	  /* Get the rest of the bits literal.  Typographical display features
 	     are allowed in the reference language between the digit symbols
-- 
2.39.5



More information about the Algol68 mailing list