# HG changeset patch # User Petter T. # Date 1699058104 -3600 # Node ID 09ee4030e927bb39a39006f33674bc40014fc6b6 # Parent ba52044813f134eb45db6c0f142138c3dcede2c9 Do type check before static_cast to wrong type The virtual function is_defined() was called on a pointer to octave_cached_value , when the object actually was a octave_base_value. The type check call need to be done on a pointer to the base class to be standard compliant. * pt-bytecode-vm.cc: Comply diff -r ba52044813f1 -r 09ee4030e927 libinterp/parse-tree/pt-bytecode-vm.cc --- a/libinterp/parse-tree/pt-bytecode-vm.cc Sat Nov 04 01:35:04 2023 +0100 +++ b/libinterp/parse-tree/pt-bytecode-vm.cc Sat Nov 04 01:35:04 2023 +0100 @@ -1772,15 +1772,22 @@ unsigned char b0 = *ip++; unsigned char b1 = *ip++; - octave_cached_value *ovb = static_cast (bsp[slot].ovb); - if (ovb->is_defined () && ovb->cache_is_valid ()) - { - PUSH_OV (ovb->get_cached_value ()); + // If the slot value is defined it is a octave_cached_value, since only + // this opcode and SET_FOLDED_CST writes to the slot. + + octave_base_value *ovb = bsp[slot].ovb; + octave_cached_value *ovbc = static_cast (ovb); + if (ovb->is_defined () && ovbc->cache_is_valid ()) + { + // Use the cached value. Push it to the stack. + PUSH_OV (ovbc->get_cached_value ()); + // Jump over the initialization code (the folded code) of the cached value int target = USHORT_FROM_UCHARS (b0, b1); ip = code + target; } else { + // Put a octave_cached_value in the slot for SET_FOLDED_CST bsp[slot].ov = octave_value {new octave_cached_value}; } }