Skip to content

Commit

Permalink
Correct use of strncpy function (#1247)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brookst authored and aquynh committed Sep 15, 2018
1 parent d70e2b2 commit e2c1cd4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arch/Sparc/SparcInstPrinter.c
Expand Up @@ -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)
Expand Down

0 comments on commit e2c1cd4

Please sign in to comment.