codewitch-honey-crisis / gfx

GFX is a device independent graphics library primarily intended for IoT MCUs but not limited to that.
https://honeythecodewitch.com/gfx
MIT License
110 stars 10 forks source link

-Werror=stringop-truncation leads to error / warning for strncpy operations in gfx/src/gfx_svg_doc.cpp #18

Closed fschuetz closed 1 year ago

fschuetz commented 1 year ago

In the file gfx/src/gfx_svg_doc.cpp there are many operations that copy part of a memory area into another but tuncate it, for example in function svg_parese_attr(...) is the statement strncpy(name, s.value(), sizeof(name));. If compiled with the compiler flag -Werror=stringop-truncation leads to errors (this flag is default when building under espidf under platformio manually as release). In that specific case:

components/gfx/src/gfx_svg_doc.cpp:330:12: error: 'char* strncpy(char*, const char*, size_t)' output may be truncated copying 32 bytes from a string of length 2047 [-Werror=stringop-truncation]
  330 |     strncpy(name, s.value(), sizeof(name));

The error (or warning) can be avoided by using memcpy with the same arguments. Eg. memcpy(name, s.value(), sizeof(name)); in this case.

The affected statements in 0a32e53 are:

codewitch-honey-crisis commented 1 year ago

thanks, i'll get on it

codewitch-honey-crisis commented 1 year ago

Okay, I just checked it in. It's currently going through my CI/CD process but you can use the bits in the repo already. Let me know if you have any other problems. I really appreciate all your help, and how thorough you are about reporting. It helps me move quickly to make fixes.

codewitch-honey-crisis commented 1 year ago

I'm marking this as completed for now, but reopen if necessary.