Replace deprecated APIs in rt_printf_impl.cpp#9833
Closed
hyunjiki-amd wants to merge 1 commit into
Closed
Conversation
Collaborator
Author
|
Will implemented in terms of std::string instead of c-style arrays |
| char *buf = formatStr + strlen(formatStr); | ||
| sprintf(buf, "%d", conversion.m_fieldWidthValue); | ||
| char *buf = &formatStr[pos]; | ||
| pos += sprintf(buf, "%d", conversion.m_fieldWidthValue); |
Contributor
There was a problem hiding this comment.
warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
pos += sprintf(buf, "%d", conversion.m_fieldWidthValue);
^| char *buf = formatStr + strlen(formatStr); | ||
| sprintf(buf, ".%d", conversion.m_precisionValue); | ||
| char *buf = &formatStr[pos]; | ||
| pos += sprintf(buf, ".%d", conversion.m_precisionValue); |
Contributor
There was a problem hiding this comment.
warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
pos += sprintf(buf, ".%d", conversion.m_precisionValue);
^
stsoe
reviewed
May 26, 2026
Collaborator
There was a problem hiding this comment.
This doesn't really change the brain dead code. Please prompt AI with what I quote below.
Then review if response is any good. Perplexity's response looked pretty good, but I didn't have the time to review.
This code is completely brain-dead, please rewrite to use std::string and no unsafe strXXX functions.
std::string convertArg(const PrintfArg& arg, const ConversionSpec& conversion)
{
std::string retval = "";
char formatStr[32];
strcpy(formatStr, "%");
if (conversion.m_leftJustify)
strcat(formatStr, "-");
if (conversion.m_signPlus)
strcat(formatStr, "+");
if (conversion.m_prefixSpace)
strcat(formatStr, " ");
if (conversion.m_alternative)
strcat(formatStr, "#");
if (conversion.m_padZero)
strcat(formatStr, "0");
if (conversion.m_fieldWidth) {
char *buf = formatStr + strlen(formatStr);
sprintf(buf, "%d", conversion.m_fieldWidthValue);
}
if (conversion.m_precision) {
char *buf = formatStr + strlen(formatStr);
sprintf(buf, ".%d", conversion.m_precisionValue);
}
switch ( conversion.m_lengthModifier ) {
case ConversionSpec::CS_CHAR: {
strcat(formatStr, "hh");
break;
}
case ConversionSpec::CS_SHORT: {
strcat(formatStr, "h");
break;
}
case ConversionSpec::CS_INT_FLOAT: {
// TODO: Vec Only...
//strcat(formatStr, "hl");
break;
}
case ConversionSpec::CS_LONG: {
// HACK: LONG only supported for non vectors now...
if ( conversion.m_vectorSize == 1 ) {
strcat(formatStr, "l");
}
break;
}
default:
break;
}
strcat(formatStr, " ");
formatStr[strlen(formatStr)-1] = conversion.m_specifier;
// TODO: later make this dynamically size... for now 1024 should be sufficient
int bufLen = 1024;
char *printBuf = new char[bufLen];
switch ( arg.m_typeInfo ) {
case PrintfArg::AT_PTR: {
snprintf(printBuf, bufLen, formatStr, arg.ptr);
retval = printBuf;
break;
}
case PrintfArg::AT_STR: {
snprintf(printBuf, bufLen, formatStr, arg.str.c_str());
retval = printBuf;
break;
}
case PrintfArg::AT_INT: {
snprintf(printBuf, bufLen, formatStr, arg.int_arg);
retval = printBuf;
break;
}
case PrintfArg::AT_UINT: {
snprintf(printBuf, bufLen, formatStr, arg.uint_arg);
retval = printBuf;
break;
}
case PrintfArg::AT_FLOAT: {
snprintf(printBuf, bufLen, formatStr, arg.float_arg);
retval = printBuf;
break;
}
case PrintfArg::AT_INTVEC: {
size_t comma = 0;
for (auto val : arg.intVec) {
if (comma++) retval += ",";
snprintf(printBuf, bufLen, formatStr, val);
retval += printBuf;
}
break;
}
case PrintfArg::AT_UINTVEC: {
size_t comma = 0;
for (auto val : arg.uintVec) {
if (comma++) retval += ",";
snprintf(printBuf, bufLen, formatStr, val);
retval += printBuf;
}
break;
}
case PrintfArg::AT_FLOATVEC: {
size_t comma = 0;
for (auto val : arg.floatVec) {
if (comma++) retval += ",";
snprintf(printBuf, bufLen, formatStr, val);
retval += printBuf;
}
break;
}
}
delete[] printBuf;
return retval;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem solved by the commit
To meet the driver compliance, banned APIs must be replaced according to https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/28719-banned-api-usage-use-updated-function-replacement
Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered
Issue fixed: driver compliance
How problem was solved, alternative solutions (if any) and why they were rejected
Replace deprecated APIs in core/common (e.g., strncpy to memcpy)
Risks (if any) associated the changes in the commit
None
What has been tested and how, request additional testing if necessary
Confirmed that the build is successful with the changes locally
Documentation impact (if any)
None
Signed-off-by: Hyunji Kim Hyunji.Kim@amd.com