[COMMITTED] a68: fix uninitialized memory in get_hole_symbol [PR algol68/124115]
Jose E. Marchesi
jemarch@gnu.org
Mon Feb 16 20:35:29 GMT 2026
The function get_hole_symbol is supposed to set *addrp to either true
or false. However it was only setting it to false, causing
uninitialized memory.
This patch also removes a gcc_asser tfrom a68_make_formal_hole_decl.
If the formal hole results in an empty symbol then it may result into
invalid assembly being generated, but that is akin to use an invalid
asm template.
Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>
gcc/algol68/ChangeLog
PR algol68/124115
* a68-low-holes.cc (get_hole_symbol): Always set *addrp to avoid
uninitialized memory.
* a68-low.cc (a68_make_formal_hole_decl): Remove assert.
gcc/testsuite/ChangeLog
PR algol68/124115
* algol68/compile/formal-hole-2.a68: New test.
---
gcc/algol68/a68-low-holes.cc | 7 +++++--
gcc/algol68/a68-low.cc | 3 +--
gcc/testsuite/algol68/compile/formal-hole-2.a68 | 6 ++++++
3 files changed, 12 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/algol68/compile/formal-hole-2.a68
diff --git a/gcc/algol68/a68-low-holes.cc b/gcc/algol68/a68-low-holes.cc
index 3eca4e4e0b2..eaf4ddfecb3 100644
--- a/gcc/algol68/a68-low-holes.cc
+++ b/gcc/algol68/a68-low-holes.cc
@@ -57,12 +57,15 @@ get_hole_symbol (NODE_T *p, bool *addrp)
gcc_assert (IS (str, ROW_CHAR_DENOTATION));
const char *cstr = NSYMBOL (str);
- if (strlen (cstr) > 0 && cstr[0] == '&' && addrp != NULL)
+ bool isaddr = false;
+ if (strlen (cstr) > 0 && cstr[0] == '&')
{
- *addrp = true;
+ isaddr = true;
cstr = cstr + 1;
}
+ if (addrp != NULL)
+ *addrp = isaddr;
return a68_string_process_breaks (p, cstr);
}
diff --git a/gcc/algol68/a68-low.cc b/gcc/algol68/a68-low.cc
index dcc974ad67d..7df38c801e6 100644
--- a/gcc/algol68/a68-low.cc
+++ b/gcc/algol68/a68-low.cc
@@ -642,8 +642,7 @@ a68_make_formal_hole_decl (NODE_T *p, const char *extern_symbol)
? TREE_TYPE (CTYPE (MOID (p)))
: CTYPE (MOID (p)));
- gcc_assert (strlen (extern_symbol) > 0);
- const char *sym = (extern_symbol[0] == '&'
+ const char *sym = (strlen (extern_symbol) > 0 && extern_symbol[0] == '&'
? extern_symbol + 1
: extern_symbol);
diff --git a/gcc/testsuite/algol68/compile/formal-hole-2.a68 b/gcc/testsuite/algol68/compile/formal-hole-2.a68
new file mode 100644
index 00000000000..9337a044f35
--- /dev/null
+++ b/gcc/testsuite/algol68/compile/formal-hole-2.a68
@@ -0,0 +1,6 @@
+{ Freestanding formal hole with &. }
+
+begin
+ ref int foo = nest C "&foo";
+ skip
+end
--
2.39.5
More information about the Algol68
mailing list