Build: Fix #1640: Change strcpy to snprintf.

This commit is contained in:
John Kessenich 2019-02-18 22:25:58 -07:00
Родитель 9f538c7207
Коммит bce1f51096
2 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

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

Просмотреть файл

@ -1116,7 +1116,7 @@ int TPpContext::tokenize(TPpToken& ppToken)
parseContext.ppError(ppToken.loc, "character literals not supported", "\'", "");
continue;
default:
strcpy(ppToken.name, atomStrings.getString(token));
snprintf(ppToken.name, sizeof(ppToken.name), "%s", atomStrings.getString(token));
break;
}
@ -1185,8 +1185,8 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
case PpAtomAnd:
case PpAtomOr:
case PpAtomXor:
strcpy(ppToken.name, atomStrings.getString(resultToken));
strcpy(pastedPpToken.name, atomStrings.getString(token));
snprintf(ppToken.name, sizeof(ppToken.name), "%s", atomStrings.getString(resultToken));
snprintf(pastedPpToken.name, sizeof(pastedPpToken.name), "%s", atomStrings.getString(token));
break;
default:
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", "##", "");
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)
if (resultToken != PpAtomIdentifier) {