Attention is currently required from: Edward O'Callaghan, Anastasia Klimchuk.
Patch set 2:Code-Review +1
3 comments:
File ft2232_spi.c:
Patch Set #2, Line 614: spi_data = calloc(1, sizeof(struct ft2232_data));
Can calloc() fail?
Patch Set #2, Line 614: sizeof(struct ft2232_data)
Using type names in sizeof() is discouraged. If someone retypes `spi_data`, this sizeof() would also need to be updated to avoid problems, but it's easy to miss it because this sizeof() is almost 300 lines away from the `spi_data` definition.
Instead, one can apply sizeof() to variables. In this case, since `spi_data` is a pointer, `sizeof(spi_data)` would return the size of a pointer. It is possible to "dereference" it in order to obtain the size of the data it points to. This works even if the pointer is NULL, as sizeof() only cares about the type.
TL;DR: You can and should use this as the size argument for calloc():
sizeof(*spi_data)
Patch Set #2, Line 617: memcpy(&spi_data->ftdic_context, &ftdic, sizeof(struct ftdi_context));
It should be possible to do a direct assignment:
spi_data->ftdic_context = ftdic;
If it doesn't work, I'm fine with keeping the memcpy(). However, please use `sizeof(ftdic)` for the length argument (see comment above).
To view, visit change 52256. To unsubscribe, or for help writing mail filters, visit settings.