Build: Fix #1640: Change strcpy to snprintf.

This commit is contained in:
John Kessenich 2019-02-18 22:25:58 -07:00
parent 9f538c7207
commit bce1f51096
2 changed files with 6 additions and 6 deletions

View File

@ -866,8 +866,7 @@ int TPpContext::CPPextension(TPpToken* ppToken)
if (token != PpAtomIdentifier) if (token != PpAtomIdentifier)
parseContext.ppError(ppToken->loc, "extension name expected", "#extension", ""); parseContext.ppError(ppToken->loc, "extension name expected", "#extension", "");
assert(strlen(ppToken->name) <= MaxTokenLength); snprintf(extensionName, sizeof(extensionName), "%s", ppToken->name);
strcpy(extensionName, ppToken->name);
token = scanToken(ppToken); token = scanToken(ppToken);
if (token != ':') { if (token != ':') {

View File

@ -1116,7 +1116,7 @@ int TPpContext::tokenize(TPpToken& ppToken)
parseContext.ppError(ppToken.loc, "character literals not supported", "\'", ""); parseContext.ppError(ppToken.loc, "character literals not supported", "\'", "");
continue; continue;
default: default:
strcpy(ppToken.name, atomStrings.getString(token)); snprintf(ppToken.name, sizeof(ppToken.name), "%s", atomStrings.getString(token));
break; break;
} }
@ -1185,8 +1185,8 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
case PpAtomAnd: case PpAtomAnd:
case PpAtomOr: case PpAtomOr:
case PpAtomXor: case PpAtomXor:
strcpy(ppToken.name, atomStrings.getString(resultToken)); snprintf(ppToken.name, sizeof(ppToken.name), "%s", atomStrings.getString(resultToken));
strcpy(pastedPpToken.name, atomStrings.getString(token)); snprintf(pastedPpToken.name, sizeof(pastedPpToken.name), "%s", atomStrings.getString(token));
break; break;
default: default:
parseContext.ppError(ppToken.loc, "not supported for these tokens", "##", ""); parseContext.ppError(ppToken.loc, "not supported for these tokens", "##", "");
@ -1198,7 +1198,8 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", ""); parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", "");
return resultToken; return resultToken;
} }
strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name)); snprintf(&ppToken.name[0] + strlen(ppToken.name), sizeof(ppToken.name) - strlen(ppToken.name),
"%s", pastedPpToken.name);
// correct the kind of token we are making, if needed (identifiers stay identifiers) // correct the kind of token we are making, if needed (identifiers stay identifiers)
if (resultToken != PpAtomIdentifier) { if (resultToken != PpAtomIdentifier) {