]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
msp430: extended_dst disassembly
authorAlan Modra <amodra@gmail.com>
Sun, 5 Oct 2025 23:23:03 +0000 (09:53 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 6 Oct 2025 03:01:30 +0000 (13:31 +1030)
This avoids a gcc-14.2 bug reporting an "error: null destination
pointer" on an sprintf buffer that is not NULL.  Don't ask me why this
happens to work.

* msp430-dis.c (msp430_singleoperand): Don't overprint op or
comm for extended_dst.

opcodes/msp430-dis.c

index bf705f0739c555a0cd1e6e630a601743a1be77a8..4285e8818c626b9071cd08050c49a5b1c8ec3b37 100644 (file)
@@ -259,9 +259,6 @@ msp430_singleoperand (disassemble_info *info,
                {
                  cmd_len += 2;
                  *cycles = 4;
-                 sprintf (op, "0x%04x", dst);
-                 sprintf (comm, "PC rel. abs addr 0x%04x",
-                          PS ((short) (addr + 2) + dst));
                  if (extended_dst)
                    {
                      dst |= extended_dst << 16;
@@ -269,6 +266,12 @@ msp430_singleoperand (disassemble_info *info,
                      sprintf (comm, "PC rel. abs addr 0x%05lx",
                               (long)((addr + 2 + dst) & 0xfffff));
                    }
+                 else
+                   {
+                     sprintf (op, "0x%04x", dst);
+                     sprintf (comm, "PC rel. abs addr 0x%04x",
+                              PS ((short) (addr + 2) + dst));
+                   }
                }
              else
                return -1;
@@ -280,12 +283,13 @@ msp430_singleoperand (disassemble_info *info,
                {
                  cmd_len += 2;
                  *cycles = 4;
-                 sprintf (op, "&0x%04x", PS (dst));
                  if (extended_dst)
                    {
                      dst |= extended_dst << 16;
                      sprintf (op, "&0x%05x", dst & 0xfffff);
                    }
+                 else
+                   sprintf (op, "&0x%04x", PS (dst));
                }
              else
                return -1;
@@ -339,9 +343,6 @@ msp430_singleoperand (disassemble_info *info,
              if (msp430dis_opcode_signed (addr + 2, info, &dst, comm))
                {
                  cmd_len += 2;
-                 sprintf (op, "#%d", dst);
-                 if (dst > 9 || dst < 0)
-                   sprintf (comm, "#0x%04x", PS (dst));
                  if (extended_dst)
                    {
                      dst |= extended_dst << 16;
@@ -351,6 +352,12 @@ msp430_singleoperand (disassemble_info *info,
                      if (dst > 9 || dst < 0)
                        sprintf (comm, "#0x%05x", dst);
                    }
+                 else
+                   {
+                     sprintf (op, "#%d", dst);
+                     if (dst > 9 || dst < 0)
+                       sprintf (comm, "#0x%04x", PS (dst));
+                   }
                }
              else
                return -1;
@@ -367,9 +374,6 @@ msp430_singleoperand (disassemble_info *info,
              if (msp430dis_opcode_signed (addr + 2, info, &dst, comm))
                {
                  cmd_len += 2;
-                 sprintf (op, "0x%04x", PS (dst));
-                 sprintf (comm, "PC rel. 0x%04x",
-                          PS ((short) addr + 2 + dst));
                  if (extended_dst)
                    {
                      dst |= extended_dst << 16;
@@ -377,6 +381,12 @@ msp430_singleoperand (disassemble_info *info,
                      sprintf (comm, "PC rel. 0x%05lx",
                               (long)((addr + 2 + dst) & 0xfffff));
                    }
+                 else
+                   {
+                     sprintf (op, "0x%04x", PS (dst));
+                     sprintf (comm, "PC rel. 0x%04x",
+                              PS ((short) addr + 2 + dst));
+                   }
                }
              else
                return -1;
@@ -387,12 +397,13 @@ msp430_singleoperand (disassemble_info *info,
              if (msp430dis_opcode_signed (addr + 2, info, &dst, comm))
                {
                  cmd_len += 2;
-                 sprintf (op, "&0x%04x", PS (dst));
                  if (extended_dst)
                    {
                      dst |= extended_dst << 16;
                      sprintf (op, "&0x%05x", dst & 0xfffff);
                    }
+                 else
+                   sprintf (op, "&0x%04x", PS (dst));
                }
              else
                return -1;