From e2c1cd46c06744beaceff42dd882de3a90f0a37c Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Sat, 15 Sep 2018 06:47:52 +0100 Subject: [PATCH] Correct use of strncpy function (#1247) The last argument should be the max size of the destination, not the source buffer. A null byte is added to the end of the destination buffer since strncpy only adds one if it does not truncate the source. This fixes the -Wstringop-overflow warning on GCC. --- arch/Sparc/SparcInstPrinter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/Sparc/SparcInstPrinter.c b/arch/Sparc/SparcInstPrinter.c index ebaa0707..da831874 100644 --- a/arch/Sparc/SparcInstPrinter.c +++ b/arch/Sparc/SparcInstPrinter.c @@ -358,8 +358,8 @@ void Sparc_printInst(MCInst *MI, SStream *O, void *Info) mnem = printAliasInstr(MI, O, Info); if (mnem) { // fixup instruction id due to the change in alias instruction - strncpy(instr, mnem, strlen(mnem)); - instr[strlen(mnem)] = '\0'; + strncpy(instr, mnem, sizeof(instr)); + instr[sizeof(instr) - 1] = '\0'; // does this contains hint with a coma? p = strchr(instr, ','); if (p)