]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: fix possible TCL errors in gdb.threads/threadcrash.exp
authorGuinevere Larsen <guinevere@redhat.com>
Mon, 1 Sep 2025 14:48:30 +0000 (11:48 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Thu, 4 Sep 2025 17:56:37 +0000 (14:56 -0300)
The test gdb.threads/threadcrash.exp, among other things, creates a list
of the threads seen in the order that the "thread apply all backtrace"
would generate them, tests that this list is the same size as GDB's
count of threads, and then loops over the list to check that each
thread has the expected backtrace.

A problem occurs because the loop iterates on GDB's internal count of
threads, rather than the size of the list, but then attempts to acces
the n-th element of the list. If the list size is smaller than GDB's
internal thread count, it'll access past the end of the list and
generate TCL errors.

This commit fixes this by using the list's length instead.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.threads/threadcrash.exp

index 76d2c6c2541eaf5ddd5590c3e6dee9d685729fdb..8df857868aaee21f379e1f0d47a566a1a3ba7a20 100644 (file)
@@ -132,8 +132,9 @@ proc do_full_test {} {
        set pthread_kill ".*"
     }
 
-    for {set i 0} {$i < $thread_count } {incr i} {
-       set thread_num [expr [llength $test_list] - $i]
+    set loop_iterations [llength $test_list]
+    for {set i 0} {$i < $loop_iterations } {incr i} {
+       set thread_num [expr $loop_iterations - $i]
 
        set type [lindex $test_list $i]
        if { $type == 1 } {