[PATCH] FT32: Remove recursion in ft32_opcode

James Bowman (FTDI-UK) james.bowman@ftdichip.com
Tue Aug 24 02:16:56 GMT 2021


The function ft32_opcode used recursion. This could cause a stack
overflow. Replaced with a pair of non-recursive functions.

https://sourceware.org/bugzilla/show_bug.cgi?id=28169


OK to apply?

James.


opcodes/ChangeLog:

2021-08-23  James Bowman  <james.bowman@ftdichip.com>

        * opcodes/ft32-dis.c (ft32_opcode): Split into two non-recursive functions

---
diff --git a/opcodes/ft32-dis.c b/opcodes/ft32-dis.c
index cefc99d..07ece1f 100644
--- a/opcodes/ft32-dis.c
+++ b/opcodes/ft32-dis.c
@@ -40,9 +40,8 @@ sign_extend(int bit, int value)
 }
 
 static void
-ft32_opcode(bfd_vma addr ATTRIBUTE_UNUSED,
-            unsigned int iword,
-            struct disassemble_info *info)
+ft32_opcode1(unsigned int iword,
+             struct disassemble_info *info)
 {
   const ft32_opc_info_t *oo;
 
@@ -50,14 +49,6 @@ ft32_opcode(bfd_vma addr ATTRIBUTE_UNUSED,
     if ((iword & oo->mask) == oo->bits)
       break;
 
-  unsigned int sc[2];
-  if (ft32_decode_shortcode((unsigned int)addr, iword, sc))
-    {
-      ft32_opcode(addr, sc[0], info);
-      fpr (stream, " ; ");
-      ft32_opcode(addr, sc[1], info);
-    }
-
   if (oo->name)
     {
       int f = oo->fields;
@@ -174,6 +165,24 @@ ft32_opcode(bfd_vma addr ATTRIBUTE_UNUSED,
     }
 }
 
+static void
+ft32_opcode(bfd_vma addr ATTRIBUTE_UNUSED,
+            unsigned int iword,
+            struct disassemble_info *info)
+{
+  unsigned int sc[2];
+  if (ft32_decode_shortcode((unsigned int)addr, iword, sc))
+    {
+      ft32_opcode1(sc[0], info);
+      fpr (stream, " ; ");
+      ft32_opcode1(sc[1], info);
+    }
+  else
+    {
+       ft32_opcode1(iword, info);
+    }
+}
+
 int
 print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
 {


More information about the Binutils mailing list