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.
This commit is contained in:
Tim Brooks 2018-09-15 06:47:52 +01:00 committed by Nguyen Anh Quynh
parent d70e2b286a
commit e2c1cd46c0
1 changed files with 2 additions and 2 deletions

View File

@ -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)