-
Notifications
You must be signed in to change notification settings - Fork 720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace sprintf with snprintf in many places #20474
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe in the compiler files you need to use TR::snprintfTrunc
; @jdmpapin could you confirm? (Something to do with windows and snprintf
not being defined by default).
At call sites where we're really confident that the buffer is large enough, The point of
If we're OK limiting ourselves to versions of the MSVC runtime library that include this change, then plain |
We've moved up to VS2022, and VS2013 and earlier are out of support so I think it's fine. |
curMsg += msgLen; | ||
maxMsgLen -= msgLen; | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct the indentation here.
curMsg += msgLen; | ||
maxMsgLen -= msgLen; | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
curMsg += msgLen; | ||
maxMsgLen -= msgLen; | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation; also several places below
runtime/vm/JFRChunkWriter.hpp
Outdated
@@ -222,8 +222,9 @@ class VM_JFRChunkWriter { | |||
writeIntermediateJFRChunkToFile() | |||
{ | |||
UDATA written = 0; | |||
char fileName[sizeof(intermediateChunkFileName) + 16 + sizeof(".jfr")]; | |||
sprintf(fileName, "%s%lX.jfr", intermediateChunkFileName, _vm->jfrState.jfrChunkCount); | |||
size_t fileNameLen = sizeof(intermediateChunkFileName) + 16 + sizeof(".jfr"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
may be necessary here
runtime/vm/JFRChunkWriter.hpp
Outdated
sprintf(fileName, "%s%lX.jfr", intermediateChunkFileName, _vm->jfrState.jfrChunkCount); | ||
size_t fileNameLen = sizeof(intermediateChunkFileName) + 16 + sizeof(".jfr"); | ||
char fileName[fileNameLen]; | ||
snprintf(fileName, fileNameLen, "%s%lX.jfr", intermediateChunkFileName, _vm->jfrState.jfrChunkCount); | ||
UDATA len = _bufferWriter->getSize(); | ||
IDATA fd = j9file_open(fileName, EsOpenWrite | EsOpenCreate | EsOpenTruncate , 0666); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're here, please remove the space before the last comma.
runtime/vm/linearswalk.c
Outdated
@@ -396,16 +396,20 @@ lswRecordSlot(J9StackWalkState * walkState, const void * slotAddress, UDATA slot | |||
|
|||
|
|||
static char * | |||
lswDescribeObject(J9VMThread * vmThread, char * dataPtr, J9Class ** class, J9Object * object) | |||
lswDescribeObject(J9VMThread * vmThread, char * dataPtr, UDATA dataSize, J9Class ** class, J9Object * object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest size_t
is preferable to UDATA
here and in the signature of lswDescribeSlot()
.
runtime/vm/linearswalk.c
Outdated
@@ -427,21 +431,30 @@ lswDescribeSlot(J9VMThread * vmThread, J9StackWalkState * walkState, J9SWSlot * | |||
case LSW_TYPE_INDIRECT_O_SLOT: | |||
case LSW_TYPE_O_SLOT: | |||
if (slot->data) { | |||
|
|||
char *newPtr = dataPtr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NULL
is just as good for an initial value here.
runtime/vm/linearswalk.c
Outdated
|
||
className = J9ROMCLASS_CLASSNAME(class->romClass); | ||
copySize = (J9UTF8_LENGTH(className) <= dataSize) ? J9UTF8_LENGTH(className) : LSW_STRING_MAX - 1; | ||
copySize = (J9UTF8_LENGTH(className) < dataSize) ? J9UTF8_LENGTH(className) : (dataSize > 0 ? dataSize - 1 : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing parentheses for (dataSize - 1)
.
3dbe0ac
to
6191097
Compare
I've pushed an update to address the initial review comments. |
runtime/compiler/env/VMJ9.cpp
Outdated
@@ -2628,25 +2628,25 @@ TR_J9VMBase::printTruncatedSignature(char *sigBuf, int32_t bufLen, J9UTF8 *class | |||
int32_t sigLen = J9UTF8_LENGTH(className) + J9UTF8_LENGTH(name) + J9UTF8_LENGTH(signature)+2; | |||
if (sigLen < bufLen) | |||
{ | |||
sigLen = sprintf(sigBuf, "%.*s.%.*s%.*s", J9UTF8_LENGTH(className), utf8Data(className), | |||
sigLen = snprintf(sigBuf, bufLen, "%.*s.%.*s%.*s", J9UTF8_LENGTH(className), utf8Data(className), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cast should be added until then.
runtime/compiler/env/VMJ9.cpp
Outdated
@@ -7051,7 +7054,7 @@ TR_J9VM::sampleSignature(TR_OpaqueMethodBlock * aMethod, char *buf, int32_t bufL | |||
int32_t len = J9UTF8_LENGTH(className)+J9UTF8_LENGTH(name)+J9UTF8_LENGTH(signature)+3; | |||
char * s = len <= bufLen ? buf : (memory ? (char*)memory->allocateHeapMemory(len) : NULL); | |||
if (s) | |||
sprintf(s, "%.*s.%.*s%.*s", J9UTF8_LENGTH(className), utf8Data(className), J9UTF8_LENGTH(name), utf8Data(name), J9UTF8_LENGTH(signature), utf8Data(signature)); | |||
snprintf(s, len, "%.*s.%.*s%.*s", J9UTF8_LENGTH(className), utf8Data(className), J9UTF8_LENGTH(name), utf8Data(name), J9UTF8_LENGTH(signature), utf8Data(signature)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cast should be used here ((size_t)len
).
sprintf(annNameBuffer,"parm(%d)",(flag & ANNOTATION_PARM_MASK) >> ANNOTATION_PARM_SHIFT); | ||
TR_ASSERT( strlen(annNameBuffer) < ANNO_NAMEBUF_LEN, "buffer length somehow exceeded\n"); | ||
size_t len = snprintf(annNameBuffer, sizeof(annNameBuffer), "parm(%d)",(flag & ANNOTATION_PARM_MASK) >> ANNOTATION_PARM_SHIFT); | ||
TR_ASSERT( len < sizeof(annNameBuffer), "buffer length somehow exceeded\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the space after the opening (
.
runtime/compiler/ilgen/Walker.cpp
Outdated
@@ -5059,7 +5068,8 @@ TR_J9ByteCodeIlGenerator::runMacro(TR::SymbolReference * symRef) | |||
char *secondArgType = nextSignatureArgument(arrayElementType); | |||
int arrayElementTypeLength = secondArgType - arrayElementType; | |||
|
|||
char *expandedArgsSignature = (char*)comp()->trMemory()->allocateStackMemory(numElements * arrayElementTypeLength + 1); | |||
size_t argsLen = numElements * arrayElementTypeLength + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing parentheses:
size_t argsLen = (numElements * arrayElementTypeLength) + 1;
There is one remaining place that will require a coordinated merge with OMR. Signed-off-by: Peter Shipton <[email protected]>
Pushed the new updates. |
There is one remaining place that will require a coordinated merge with OMR.