From f2e6199fcb6ce75be74017285b2485499e084670 Mon Sep 17 00:00:00 2001 From: Francois Berder Date: Wed, 27 Mar 2019 09:38:44 +0000 Subject: [PATCH] RSP: Fix undefined behavior in RDP_LogDlist When calling sprintf, source and destination must not overlap otherwise it is undefined behavior as specified by C99 standard, 7.19.6.6. Signed-off-by: Francois Berder --- Source/RSP/log.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/RSP/log.cpp b/Source/RSP/log.cpp index a685dae7f..152ef8c6e 100644 --- a/Source/RSP/log.cpp +++ b/Source/RSP/log.cpp @@ -182,17 +182,23 @@ void RDP_LogDlist ( void ) } for (count = 0; count < 0x10; count ++, Pos++ ) { + char tmp[3]; if ((count % 4) != 0 || count == 0) { - sprintf(Hex,"%s %02X",Hex,Mem[Pos]); + sprintf(tmp,"%02X",Mem[Pos]); + strcat(Hex," "); + strcat(Hex,tmp); } else { - sprintf(Hex,"%s - %02X",Hex,Mem[Pos]); + sprintf(tmp,"%02X",Mem[Pos]); + strcat(Hex," - "); + strcat(Hex,tmp); } if (Mem[Pos] < 30 || Mem[Pos] > 127) { strcat(Ascii,"."); } else { - sprintf(Ascii,"%s%c",Ascii,Mem[Pos]); + sprintf(tmp,"%c",Mem[Pos]); + strcat(Ascii,tmp); } } RDP_Message(" %s %s",Hex, Ascii);