From 4c937052c13b13053559a5aa2b1345545a185ca5 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 24 Feb 2022 09:01:42 -0700 Subject: Fix crash in Fortran code PR fortran/28801 points out a gdb crash that can be provoked by certain Fortran code. The bug is that f77_get_upperbound assumes the property is either a constant or undefined, but in this case it is PROP_LOCEXPR. This patch fixes the crash by making this function (and the lower-bound one as well) do the correct check before calling 'const_val'. Thanks to Andrew for writing the test case. Co-authored-by: Andrew Burgess Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28801 --- gdb/f-valprint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gdb/f-valprint.c') diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 6a199f17c1e..b64750bac7b 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -43,7 +43,7 @@ static void f77_get_dynamic_length_of_aggregate (struct type *); LONGEST f77_get_lowerbound (struct type *type) { - if (type->bounds ()->low.kind () == PROP_UNDEFINED) + if (type->bounds ()->low.kind () != PROP_CONST) error (_("Lower bound may not be '*' in F77")); return type->bounds ()->low.const_val (); @@ -52,7 +52,7 @@ f77_get_lowerbound (struct type *type) LONGEST f77_get_upperbound (struct type *type) { - if (type->bounds ()->high.kind () == PROP_UNDEFINED) + if (type->bounds ()->high.kind () != PROP_CONST) { /* We have an assumed size array on our hands. Assume that upper_bound == lower_bound so that we show at least 1 element. -- cgit v1.2.1