Skip to content

Commit

Permalink
disas/nanomips: Fix invalid PRId64 format calling img_format()
Browse files Browse the repository at this point in the history
Fix warnings such:

  disas/nanomips.c:3251:64: warning: format specifies type 'char *' but the argument has type 'int64' (aka 'long long') [-Wformat]
    return img_format("CACHE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
                                            ~~                 ^~~~~~~
                                            %lld

To avoid crashes such (kernel from commit f375ad6):

  $ qemu-system-mipsel -cpu I7200 -d in_asm -kernel generic_nano32r6el_page4k
  ...
  ----------------
  IN: __bzero
  0x805c6084:  20c4 6950      ADDU r13, a0, a2
  0x805c6088:  9089           ADDIU a0, 1
  Process 70261 stopped
  * thread #6, stop reason = EXC_BAD_ACCESS (code=1, address=0xfffffffffffffff0)
      frame #0: 0x00000001bfe38864 libsystem_platform.dylib`_platform_strlen + 4
  libsystem_platform.dylib`:
  ->  0x1bfe38864 <+4>:  ldr    q0, [x1]
      0x1bfe38868 <+8>:  adr    x3, #-0xc8                ; ___lldb_unnamed_symbol314
      0x1bfe3886c <+12>: ldr    q2, [x3], #0x10
      0x1bfe38870 <+16>: and    x2, x0, #0xf
  Target 0: (qemu-system-mipsel) stopped.
  (lldb) bt
  * thread #6, stop reason = EXC_BAD_ACCESS (code=1, address=0xfffffffffffffff0)
    * frame #0: 0x00000001bfe38864 libsystem_platform.dylib`_platform_strlen + 4
      frame #1: 0x00000001bfce76a0 libsystem_c.dylib`__vfprintf + 4544
      frame #2: 0x00000001bfd158b4 libsystem_c.dylib`_vasprintf + 280
      frame #3: 0x0000000101c22fb0 libglib-2.0.0.dylib`g_vasprintf + 28
      frame #4: 0x0000000101bfb7d8 libglib-2.0.0.dylib`g_strdup_vprintf + 32
      frame #5: 0x000000010000fb70 qemu-system-mipsel`img_format(format=<unavailable>) at nanomips.c:103:14 [opt]
      frame #6: 0x0000000100018868 qemu-system-mipsel`SB_S9_(instruction=<unavailable>, info=<unavailable>) at nanomips.c:12616:12 [opt]
      frame #7: 0x000000010000f90c qemu-system-mipsel`print_insn_nanomips at nanomips.c:589:28 [opt]

Fixes: 4066c15 ("disas/nanomips: Remove IMMEDIATE functions")
Reported-by: Stefan Weil <[email protected]>
Reviewed-by: Stefan Weil <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
philmd committed Nov 8, 2022
1 parent 2a2105a commit 04849c9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions disas/nanomips.c
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,8 @@ static char *CACHE(uint64 instruction, Dis_info *info)

const char *rs = GPR(rs_value, info);

return img_format("CACHE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
return img_format("CACHE 0x%" PRIx64 ", %" PRId64 "(%s)",
op_value, s_value, rs);
}


Expand All @@ -3274,7 +3275,8 @@ static char *CACHEE(uint64 instruction, Dis_info *info)

const char *rs = GPR(rs_value, info);

return img_format("CACHEE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
return img_format("CACHEE 0x%" PRIx64 ", %" PRId64 "(%s)",
op_value, s_value, rs);
}


Expand Down Expand Up @@ -5173,7 +5175,7 @@ static char *DADDIU_48_(uint64 instruction, Dis_info *info)

const char *rt = GPR(rt_value, info);

return img_format("DADDIU %s, %s", rt, s_value);
return img_format("DADDIU %s, %" PRId64, rt, s_value);
}


Expand Down Expand Up @@ -11859,7 +11861,7 @@ static char *PREF_S9_(uint64 instruction, Dis_info *info)

const char *rs = GPR(rs_value, info);

return img_format("PREF 0x%" PRIx64 ", %s(%s)",
return img_format("PREF 0x%" PRIx64 ", %" PRId64 "(%s)",
hint_value, s_value, rs);
}

Expand Down Expand Up @@ -11905,7 +11907,8 @@ static char *PREFE(uint64 instruction, Dis_info *info)

const char *rs = GPR(rs_value, info);

return img_format("PREFE 0x%" PRIx64 ", %s(%s)", hint_value, s_value, rs);
return img_format("PREFE 0x%" PRIx64 ", %" PRId64 "(%s)",
hint_value, s_value, rs);
}


Expand Down Expand Up @@ -12079,7 +12082,7 @@ static char *REPL_PH(uint64 instruction, Dis_info *info)

const char *rt = GPR(rt_value, info);

return img_format("REPL.PH %s, %s", rt, s_value);
return img_format("REPL.PH %s, %" PRId64, rt, s_value);
}


Expand Down Expand Up @@ -12613,7 +12616,7 @@ static char *SB_S9_(uint64 instruction, Dis_info *info)
const char *rt = GPR(rt_value, info);
const char *rs = GPR(rs_value, info);

return img_format("SB %s, %s(%s)", rt, s_value, rs);
return img_format("SB %s, %" PRId64 "(%s)", rt, s_value, rs);
}


Expand Down Expand Up @@ -12659,7 +12662,7 @@ static char *SBE(uint64 instruction, Dis_info *info)
const char *rt = GPR(rt_value, info);
const char *rs = GPR(rs_value, info);

return img_format("SBE %s, %s(%s)", rt, s_value, rs);
return img_format("SBE %s, %" PRId64 "(%s)", rt, s_value, rs);
}


Expand Down Expand Up @@ -12706,7 +12709,7 @@ static char *SC(uint64 instruction, Dis_info *info)
const char *rt = GPR(rt_value, info);
const char *rs = GPR(rs_value, info);

return img_format("SC %s, %s(%s)", rt, s_value, rs);
return img_format("SC %s, %" PRId64 "(%s)", rt, s_value, rs);
}


Expand All @@ -12729,7 +12732,7 @@ static char *SCD(uint64 instruction, Dis_info *info)
const char *rt = GPR(rt_value, info);
const char *rs = GPR(rs_value, info);

return img_format("SCD %s, %s(%s)", rt, s_value, rs);
return img_format("SCD %s, %" PRId64 "(%s)", rt, s_value, rs);
}


Expand Down Expand Up @@ -12776,7 +12779,7 @@ static char *SCE(uint64 instruction, Dis_info *info)
const char *rt = GPR(rt_value, info);
const char *rs = GPR(rs_value, info);

return img_format("SCE %s, %s(%s)", rt, s_value, rs);
return img_format("SCE %s, %" PRId64 "(%s)", rt, s_value, rs);
}


Expand Down Expand Up @@ -12868,7 +12871,7 @@ static char *SD_S9_(uint64 instruction, Dis_info *info)
const char *rt = GPR(rt_value, info);
const char *rs = GPR(rs_value, info);

return img_format("SD %s, %s(%s)", rt, s_value, rs);
return img_format("SD %s, %" PRId64 "(%s)", rt, s_value, rs);
}


Expand Down Expand Up @@ -12973,7 +12976,7 @@ static char *SDC1_S9_(uint64 instruction, Dis_info *info)
const char *ft = FPR(ft_value, info);
const char *rs = GPR(rs_value, info);

return img_format("SDC1 %s, %s(%s)", ft, s_value, rs);
return img_format("SDC1 %s, %" PRId64 "(%s)", ft, s_value, rs);
}


Expand Down Expand Up @@ -13066,7 +13069,8 @@ static char *SDC2(uint64 instruction, Dis_info *info)

const char *rs = GPR(rs_value, info);

return img_format("SDC2 CP%" PRIu64 ", %s(%s)", cs_value, s_value, rs);
return img_format("SDC2 CP%" PRIu64 ", %" PRId64 "(%s)",
cs_value, s_value, rs);
}


Expand All @@ -13091,7 +13095,8 @@ static char *SDM(uint64 instruction, Dis_info *info)
const char *rs = GPR(rs_value, info);
uint64 count3 = encode_count3_from_count(count3_value);

return img_format("SDM %s, %s(%s), 0x%" PRIx64, rt, s_value, rs, count3);
return img_format("SDM %s, %" PRId64 "(%s), 0x%" PRIx64,
rt, s_value, rs, count3);
}


Expand Down

0 comments on commit 04849c9

Please sign in to comment.