changeset 32466:713c819e8b14

Don't do static_cast before type check (bug #64858) * pt-bytecode-vm.cc: Move static_cast inside if-statement to avoid undefined behaviour warning.
author Petter T. <petter.vilhelm@gmail.com>
date Sat, 04 Nov 2023 22:53:41 +0100
parents dec46ae43231
children 4fe09c1b4148
files libinterp/parse-tree/pt-bytecode-vm.cc
diffstat 1 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-bytecode-vm.cc	Sun Nov 05 10:25:29 2023 +0100
+++ b/libinterp/parse-tree/pt-bytecode-vm.cc	Sat Nov 04 22:53:41 2023 +0100
@@ -1775,17 +1775,25 @@
     // If the slot value is defined it is a octave_cached_value, since only
     // this opcode and SET_FOLDED_CST writes to the slot.
 
+    bool did_it = false;
     octave_base_value *ovb = bsp[slot].ovb;
-    octave_cached_value *ovbc = static_cast<octave_cached_value*> (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
+    if (ovb->is_defined ())
+      {
+        octave_cached_value *ovbc = static_cast<octave_cached_value *> (ovb);
+        if (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;
+
+            did_it = true;
+          }
+      }
+
+    if (! did_it)
       {
         // Put a octave_cached_value in the slot for SET_FOLDED_CST
         bsp[slot].ov = octave_value {new octave_cached_value};