OpenCyphal / nunavut

Generate code from DSDL using PyDSDL and Jinja2
https://nunavut.readthedocs.io/
Other
39 stars 24 forks source link

C deserialization function returns a false-positive invalid argument error for zero-sized buffers #221

Closed pavel-kirienko closed 2 years ago

pavel-kirienko commented 3 years ago

Here:

https://github.com/UAVCAN/nunavut/blob/a90eac2749c1466bdff71a5bf19085e0c2de2299/src/nunavut/lang/c/templates/deserialization.j2#L14

If *inout_buffer_size_bytes == 0, buffer may be NULL because there is no data to deserialize, which is not an error.

The check should be updated like:

-- (buffer == {{ valuetoken_null }})
++ ((buffer == {{ valuetoken_null }}) && (0 != *inout_buffer_size_bytes))

This is a problem because libcanard intentionally emits null payload pointers for zero-sized payloads (as documented).