From 119940e7b4369e4844b9e44e16240d5186000c4b Mon Sep 17 00:00:00 2001 From: angie Date: Tue, 8 Aug 2023 12:18:23 -0400 Subject: [PATCH] Fix disassembly buffer size calculation for very small extraLJust parameters --- include/common/Utils.h | 3 +++ .../RabbitizerInstruction_Disassemble.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/common/Utils.h b/include/common/Utils.h index c218ce9..a6fdb17 100644 --- a/include/common/Utils.h +++ b/include/common/Utils.h @@ -50,6 +50,9 @@ extern "C" { #define ARRAY_COUNT(arr) (sizeof(arr) / sizeof((arr)[0])) +#define RAB_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define RAB_MIN(a, b) ((a) < (b) ? (a) : (b)) + #define RAB_STRINGIFY2(x) #x #define RAB_STRINGIFY(x) RAB_STRINGIFY2(x) diff --git a/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c b/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c index 578cb59..500fa81 100644 --- a/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c +++ b/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c @@ -68,9 +68,14 @@ size_t RabbitizerInstruction_disassembleInstruction(const RabbitizerInstruction size_t RabbitizerInstruction_getSizeForBufferDataDisasm(UNUSED const RabbitizerInstruction *self, int extraLJust) { size_t totalSize = 0; + int tempLJust; totalSize += strlen(".word"); - totalSize += RabbitizerConfig_Cfg.misc.opcodeLJust + extraLJust; + + tempLJust = RabbitizerConfig_Cfg.misc.opcodeLJust + extraLJust; + tempLJust = RAB_MAX(tempLJust, 0); + totalSize += tempLJust; + totalSize += 11; return totalSize; }