Skip to content

memcpy with size of a pointer confusing (or a bug) #118

@thnkslprpt

Description

@thnkslprpt

Checklist

  • I reviewed the Contributing Guide.
  • I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.

Describe the bug
This ends up working I think because the values end up the same, with the current logic, but copying the sizeof a pointer is such a strong anti-pattern (if not an outright bug) that it might be worth changing how this memcpy is done.

Code snips

void CS_ProcessNewEepromMemoryDefinitionTable(const CS_Def_EepromMemory_Table_Entry_t *DefinitionTblPtr,
const CS_Res_EepromMemory_Table_Entry_t *ResultsTblPtr, uint16 NumEntries,
uint16 Table)
{
CS_Def_EepromMemory_Table_Entry_t *StartOfDefTable = NULL;
CS_Def_EepromMemory_Table_Entry_t *DefEntry = NULL;
CS_Res_EepromMemory_Table_Entry_t *StartOfResultsTable = NULL;
CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
uint16 Loop = 0;
uint16 NumRegionsInTable = 0;
uint16 PreviousState = CS_STATE_EMPTY;
char TableType[CS_TABLETYPE_NAME_SIZE];
memcpy(&StartOfResultsTable, ResultsTblPtr, sizeof(StartOfResultsTable));
memcpy(&StartOfDefTable, DefinitionTblPtr, sizeof(StartOfDefTable));

Expected behavior
Just assign to StartOfResultsTable directly.

Reporter Info
Avi Weiss   @thnkslprpt

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions