-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add guard word before local var CMiniColDef[9] #73736
Add guard word before local var CMiniColDef[9] #73736
Conversation
Initialize the guard word so it does not pass the UsesAllocatedMemory test. Found running output of clang14 -fsanitize=address, then inspection
Tagging subscribers to this area: @tommcdon Issue DetailsInitialize the guard word so it does not pass the UsesAllocatedMemory Found running output of clang14 -fsanitize=address, then inspection Fixes #73718
|
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 use something like below for consistency with other places:
const int MaxCols = 9;
BYTE tempCols[MaxCols * sizeof(CMiniColDef) + 1];
_ASSERTE(MaxCols >= pTable->m_cCols);
// Mark the array of columns as not allocated (not ALLOCATED_MEMORY_MARKER) for SetNewColumnDefinition call bellow
tempCols[0] = 0;
CMiniColDef *pCols = BYTEARRAY_TO_COLDES(tempCols);
CMiniColDef pCols[9]; // The col defs to init. | ||
const int MaxCols = 9; | ||
typedef uint32_t markword_t; | ||
BYTE tempCols[sizeof(markword_t) + MaxCols * sizeof(CMiniColDef)]; // keep aligned |
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.
We use a single-byte marker everywhere in this code. I see no reason to use four bytes just at this particular place. This array contains 3-byte structures, so you cannot align them.
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.
Here is similar code in another function:
runtime/src/coreclr/md/enc/metamodelrw.cpp
Lines 3635 to 3638 in 2201016
// Mark the array of columns as not allocated (not ALLOCATED_MEMORY_MARKER) for SetNewColumnDefinition | |
// call bellow (code:#SetNewColumnDefinition_call) | |
*(BYTE *)(qbTempCols.Ptr()) = 0; | |
sTempTable.m_pColDefs = (CMiniColDef *)((BYTE *)(qbTempCols.Ptr()) + 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.
And here:
runtime/src/coreclr/md/runtime/metamodel.cpp
Lines 880 to 889 in 4710133
BYTE *newMemory = new (nothrow) BYTE[(sizeof(CMiniColDef)*pTable->m_cCols)+1]; | |
if (newMemory == NULL) | |
return E_OUTOFMEMORY; | |
// Mark the first byte in this as with the "allocated memory marker" | |
*newMemory = ALLOCATED_MEMORY_MARKER; | |
// Have the pointer point to the first Column Descriptor | |
pTable->m_pColDefs = BYTEARRAY_TO_COLDES(newMemory); |
|
||
_ASSERTE(MaxCols >= pTable->m_cCols); | ||
// | ||
// Mark the array of columns as not allocated (eg, not ALLOCATED_MEMORY_MARKER) |
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.
E.g. means “for example”. Did you actually mean "i.e."?
@RobertHenry6bev thanks for your contribution. Would you mind looking at the comments @AntonLapounov left? If you do not have time right now to respond we can move this PR to draft mode. |
Hi @RobertHenry6bev, I've moved this PR to draft mode. Once it is ready for review, please feel free to move out of draft mode. Thanks for your contributions! |
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Initialize the guard word so it does not pass the UsesAllocatedMemory
test.
Found running output of clang14 -fsanitize=address, then inspection
Fixes #73718