PeachCompiler icon indicating copy to clipboard operation
PeachCompiler copied to clipboard

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

Open fedi-nabli opened this issue 1 year ago • 1 comments

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

fedi-nabli avatar Mar 02 '24 11:03 fedi-nabli

Hello Fedi, Thanks for reaching out, once theres enough issue reports I will go through them all and create a lecture addressing any issues.

Thanks Dan

nibblebits avatar Nov 20 '24 19:11 nibblebits