Skip to content

Commit 03fcfc6

Browse files
committed
Change rt_printf_impl.cpp
1 parent f25f0d6 commit 03fcfc6

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

src/runtime_src/xocl/api/printf/rt_printf_impl.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,52 +1009,55 @@ std::string convertArg(const PrintfArg& arg, const ConversionSpec& conversion)
10091009
{
10101010
std::string retval = "";
10111011
char formatStr[32];
1012-
strcpy(formatStr, "%");
1012+
size_t pos = 0;
1013+
formatStr[pos++] = '%';
10131014
if (conversion.m_leftJustify)
1014-
strcat(formatStr, "-");
1015+
formatStr[pos++] = '-';
10151016
if (conversion.m_signPlus)
1016-
strcat(formatStr, "+");
1017+
formatStr[pos++] = '+';
10171018
if (conversion.m_prefixSpace)
1018-
strcat(formatStr, " ");
1019+
formatStr[pos++] = ' ';
10191020
if (conversion.m_alternative)
1020-
strcat(formatStr, "#");
1021+
formatStr[pos++] = '#';
10211022
if (conversion.m_padZero)
1022-
strcat(formatStr, "0");
1023+
formatStr[pos++] = '0';
10231024
if (conversion.m_fieldWidth) {
1024-
char *buf = formatStr + strlen(formatStr);
1025-
sprintf(buf, "%d", conversion.m_fieldWidthValue);
1025+
char *buf = &formatStr[pos];
1026+
pos += sprintf(buf, "%d", conversion.m_fieldWidthValue);
10261027
}
10271028
if (conversion.m_precision) {
1028-
char *buf = formatStr + strlen(formatStr);
1029-
sprintf(buf, ".%d", conversion.m_precisionValue);
1029+
char *buf = &formatStr[pos];
1030+
pos += sprintf(buf, ".%d", conversion.m_precisionValue);
10301031
}
10311032
switch ( conversion.m_lengthModifier ) {
10321033
case ConversionSpec::CS_CHAR: {
1033-
strcat(formatStr, "hh");
1034+
std::memcpy(&formatStr[pos], "hh", 2);
1035+
pos += 2;
10341036
break;
10351037
}
10361038
case ConversionSpec::CS_SHORT: {
1037-
strcat(formatStr, "h");
1039+
formatStr[pos++] = 'h';
10381040
break;
10391041
}
10401042
case ConversionSpec::CS_INT_FLOAT: {
10411043
// TODO: Vec Only...
1042-
//strcat(formatStr, "hl");
1044+
// std::memcpy(&formatStr[pos], "hl", 2);
1045+
// pos += 2;
10431046
break;
10441047
}
10451048
case ConversionSpec::CS_LONG: {
10461049
// HACK: LONG only supported for non vectors now...
10471050
if ( conversion.m_vectorSize == 1 ) {
1048-
strcat(formatStr, "l");
1051+
formatStr[pos++] = 'l';
10491052
}
10501053
break;
10511054
}
10521055
default:
10531056
break;
10541057
}
10551058

1056-
strcat(formatStr, " ");
1057-
formatStr[strlen(formatStr)-1] = conversion.m_specifier;
1059+
formatStr[pos++] = conversion.m_specifier;
1060+
formatStr[pos] = '\0';
10581061
// TODO: later make this dynamically size... for now 1024 should be sufficient
10591062
int bufLen = 1024;
10601063
char *printBuf = new char[bufLen];

0 commit comments

Comments
 (0)