fixed bugs in opcodes/z80-dis.c relating to indexed operands

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

fixed bugs in opcodes/z80-dis.c relating to indexed operands

Bugzilla from arnold.metselaar@planet.nl
Hello,

With my quick fix from yesterday I introduced some new bugs.
I have undone yesterdays changes and tackled some other issues as well.

Arnold

opcodes/ChangeLog:
        * z80-dis.c (struct buffer, prt_d, prt_d_n, arit_d, ld_r_d,
        ld_d_r, pref_xd_cb): Use signed char to hold data to be
        disassembled.
        * z80-dis.c (TXTSIZ): Increase buffer size to 24, this fixes
        buffer overflows when disassembling instructions like
        ld (ix+123),0x23
        * z80-dis.c (opc_ind, pref_xd_cb): Suppress '+' in an indexed
        operand, if the offset is negative.

Index: opcodes/z80-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/z80-dis.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -p -r1.2 -r1.3
--- opcodes/z80-dis.c   17 Jan 2006 21:15:56 -0000      1.2
+++ opcodes/z80-dis.c   18 Jan 2006 13:48:46 -0000      1.3
@@ -26,7 +26,7 @@ struct buffer
   bfd_vma base;
   int n_fetch;
   int n_used;
-  unsigned char data[4];
+  signed char data[4];
 } ;

 typedef int (*func)(struct buffer *, disassemble_info *, char *);
@@ -39,7 +39,7 @@ struct tab_elt
   char *        text;
 } ;

-#define TXTSIZ 16
+#define TXTSIZ 24
 /* Names of 16-bit registers.  */
 static char * rr_str[] = { "bc", "de", "hl", "sp" };
 /* Names of 8-bit registers.  */
@@ -61,7 +61,7 @@ fetch_data (struct buffer *buf, disassem
     abort ();

   r = info->read_memory_func (buf->base + buf->n_fetch,
-                             buf->data + buf->n_fetch,
+                             (unsigned char*) buf->data + buf->n_fetch,
                              n, info);
   if (r == 0)
     buf->n_fetch += n;
@@ -377,7 +377,7 @@ static int
 prt_d (struct buffer *buf, disassemble_info * info, char *txt)
 {
   int d;
-  unsigned char *p;
+  signed char *p;

   p = buf->data + buf->n_fetch;

@@ -398,7 +398,7 @@ prt_d_n (struct buffer *buf, disassemble
 {
   char mytxt[TXTSIZ];
   int d;
-  unsigned char *p;
+  signed char *p;

   p = buf->data + buf->n_fetch;

@@ -418,7 +418,7 @@ static int
 arit_d (struct buffer *buf, disassemble_info * info, char *txt)
 {
   char mytxt[TXTSIZ];
-  unsigned char c;
+  signed char c;

   c = buf->data[buf->n_fetch - 1];
   snprintf (mytxt, TXTSIZ, txt, arit_str[(c >> 3) & 7]);
@@ -429,7 +429,7 @@ static int
 ld_r_d (struct buffer *buf, disassemble_info * info, char *txt)
 {
   char mytxt[TXTSIZ];
-  unsigned char c;
+  signed char c;

   c = buf->data[buf->n_fetch - 1];
   snprintf (mytxt, TXTSIZ, txt, r_str[(c >> 3) & 7]);
@@ -440,7 +440,7 @@ static int
 ld_d_r(struct buffer *buf, disassemble_info * info, char *txt)
 {
   char mytxt[TXTSIZ];
-  unsigned char c;
+  signed char c;

   c = buf->data[buf->n_fetch - 1];
   snprintf (mytxt, TXTSIZ, txt, r_str[c & 7]);
@@ -454,16 +454,16 @@ pref_xd_cb (struct buffer * buf, disasse
     {
       int d;
       char arg[TXTSIZ];
-      unsigned char *p;
+      signed char *p;

       buf->n_used = 4;
       p = buf->data;
       d = p[2];

       if (((p[3] & 0xC0) == 0x40) || ((p[3] & 7) == 0x06))
-       snprintf (arg, TXTSIZ, "(%s+%d)", txt, d);
+       snprintf (arg, TXTSIZ, "(%s%+d)", txt, d);
       else
-       snprintf (arg, TXTSIZ, "(%s+%d),%s", txt, d, r_str[p[3] & 7]);
+       snprintf (arg, TXTSIZ, "(%s%+d),%s", txt, d, r_str[p[3] & 7]);

       if ((p[3] & 0xc0) == 0)
        info->fprintf_func (info->stream, "%s %s",
@@ -494,18 +494,18 @@ static struct tab_elt opc_ind[] =
   { 0x2B, 0xFF, prt, "dec %s" },
   { 0x29, 0xFF, addvv, "%s" },
   { 0x09, 0xCF, prt_rr, "add %s," },
-  { 0x34, 0xFF, prt_d, "inc (%s+%%d)" },
-  { 0x35, 0xFF, prt_d, "dec (%s+%%d)" },
-  { 0x36, 0xFF, prt_d_n, "ld (%s+%%d),0x%%02x" },
+  { 0x34, 0xFF, prt_d, "inc (%s%%+d)" },
+  { 0x35, 0xFF, prt_d, "dec (%s%%+d)" },
+  { 0x36, 0xFF, prt_d_n, "ld (%s%%+d),0x%%%%02x" },

   { 0x76, 0xFF, dump, "h" },
-  { 0x46, 0xC7, ld_r_d, "ld %%s,(%s+%%%%d)" },
-  { 0x70, 0xF8, ld_d_r, "ld (%s+%%%%d),%%s" },
+  { 0x46, 0xC7, ld_r_d, "ld %%s,(%s%%%%+d)" },
+  { 0x70, 0xF8, ld_d_r, "ld (%s%%%%+d),%%s" },
   { 0x64, 0xF6, ld_v_v, "%s" },
   { 0x60, 0xF0, ld_r_r, "ld %s%%s,%%s" },
   { 0x44, 0xC6, ld_r_r, "ld %%s,%s%%s" },

-  { 0x86, 0xC7, arit_d, "%%s(%s+%%%%d)" },
+  { 0x86, 0xC7, arit_d, "%%s(%s%%%%+d)" },
   { 0x84, 0xC6, arit_r, "%%s%s%%s" },

   { 0xE1, 0xFF, prt, "pop %s" },