Currently nanopb relies on realloc() to efficiently increase size of allocated arrays, without extra copying.
For some allocators this assumption is incorrect. Most notably newlib-nano implements realloc() as malloc() + memcpy() + free().
The logic in pb_decode.c should be reworked so that it does something smart about this. If decoding from a buffer, one could look ahead to see how many items there are in array. If decoding from stream, some kind of preallocation logic should be applied.
Currently nanopb relies on
realloc()
to efficiently increase size of allocated arrays, without extra copying.For some allocators this assumption is incorrect. Most notably newlib-nano implements
realloc()
asmalloc() + memcpy() + free()
.The logic in
pb_decode.c
should be reworked so that it does something smart about this. If decoding from a buffer, one could look ahead to see how many items there are in array. If decoding from stream, some kind of preallocation logic should be applied.