Skip to content
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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/coreclr/md/runtime/metamodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,17 @@ CMiniMdBase::InitColsForTable(
// should we write the data into the structure
{
const CMiniTableDef *pTemplate; // Template table definition.
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
Copy link
Member

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.

Copy link
Member

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:

// 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);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here:

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)
Copy link
Member

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."?

// for SetNewColumnDefinition call
//
memset(tempCols, 0, sizeof(markword_t));
CMiniColDef *pCols = BYTEARRAY_TO_COLDES(tempCols + sizeof(markword_t) - 1); // The col defs to init.
BYTE iOffset; // Running size of a record.
BYTE iSize; // Size of a field.
HRESULT hr = S_OK;
Expand All @@ -726,10 +736,8 @@ CMiniMdBase::InitColsForTable(
_ASSERTE(ARRAY_SIZE(pCols) >= pTable->m_cCols);

bExtra = 0;//<TODO>@FUTURE: save in schema header. until then use 0.</TODO>

iOffset = 0;

pTemplate = GetTableDefTemplate(ixTbl);
pTemplate = GetTableDefTemplate(ixTbl);

PREFIX_ASSUME(pTemplate->m_pColDefs != NULL);

Expand Down