Skip to content

Allocating size of pointer instead the size of struct at lecture 85 #19

@fedi-nabli

Description

@fedi-nabli

At the end of lecture 85, the compiler outputs this warning message:

./parser.c:109:39: warning: 'memset' call operates on objects of type 'struct parser_history_switch' while the size is based on a different type 'struct parser_history_switch *' [-Wsizeof-pointer-memaccess]
memset(&history->_switch, 0, sizeof(&history->_switch));
~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~
./parser.c:109:39: note: did you mean to remove the addressof in the argument to 'sizeof' (and multiply it by the number of elements)?
memset(&history->_switch, 0, sizeof(&history->_switch));

To fix the issue, I changed the line from:
memset(&history->_switch, 0, sizeof(&history->_switch));
to:
memset(&history->_switch, 0, sizeof(history->_switch));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions