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

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.
This commit is contained in:
Jose E. Marchesi
2026-03-08 19:14:32 +01:00
parent 6c5de6335f
commit 891d1d0fcd
2 changed files with 18 additions and 7 deletions

View File

@@ -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))

View File

@@ -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