rprata / sgfx

SGFX is a lightweight embedded library for displays and touchscreens providing everything required to build a fully featured embedded GUI.
MIT License
23 stars 8 forks source link

ibutterfree_config_read: ‘strncpy’ output truncated before terminating nul copying #26

Closed ghost closed 4 years ago

ghost commented 4 years ago
Descrição:
Scanning dependencies of target ibutterfree
[  4%] Building C object src/CMakeFiles/ibutterfree.dir/utils/ibutterfree_config.c.o
/home/diegocatalao/Desktop/workspace/ibutterfree/src/utils/ibutterfree_config.c: In function ‘ibutterfree_config_read’:
/home/diegocatalao/Desktop/workspace/ibutterfree/src/utils/ibutterfree_config.c:11:3: error: ‘strncpy’ output truncated before terminating nul copying 8 bytes from a string of the same length [-Werror=stringop-truncation]
   11 |   strncpy(m_bfcs->fdfb, FB, strlen(FB));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/diegocatalao/Desktop/workspace/ibutterfree/src/utils/ibutterfree_config.c:12:3: error: ‘strncpy’ output truncated before terminating nul copying 17 bytes from a string of the same length [-Werror=stringop-truncation]
   12 |   strncpy(m_bfcs->fdev, INPUT, strlen(INPUT));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/diegocatalao/Desktop/workspace/ibutterfree/src/utils/ibutterfree_config.c:30:6: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
   30 |      strncpy(m_bfcs->fdev, buff + 5, strlen(buff + 5) - 1);
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/diegocatalao/Desktop/workspace/ibutterfree/src/utils/ibutterfree_config.c:30:38: note: length computed here
   30 |      strncpy(m_bfcs->fdev, buff + 5, strlen(buff + 5) - 1);
      |                                      ^~~~~~~~~~~~~~~~
/home/diegocatalao/Desktop/workspace/ibutterfree/src/utils/ibutterfree_config.c:24:6: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
   24 |      strncpy(m_bfcs->fdfb, buff + 5, strlen(buff + 5) - 1);
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/diegocatalao/Desktop/workspace/ibutterfree/src/utils/ibutterfree_config.c:24:38: note: length computed here
   24 |      strncpy(m_bfcs->fdfb, buff + 5, strlen(buff + 5) - 1);
      |                                      ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/ibutterfree.dir/build.make:96: src/CMakeFiles/ibutterfree.dir/utils/ibutterfree_config.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:147: src/CMakeFiles/ibutterfree.dir/all] Error 2
make: *** [Makefile:104: all] Error 2

error: argument 1 null where non-null expected [-Werror=nonnull]

[  4%] Building C object src/CMakeFiles/ibutterfree.dir/utils/ibutterfree_config.c.o
[  8%] Building C object src/CMakeFiles/ibutterfree.dir/core/ibutterfree_surface.c.o
/home/diegocatalao/Desktop/workspace/ibutterfree/src/core/ibutterfree_surface.c: In function ‘ibutterfree_surface_set_description’:
/home/diegocatalao/Desktop/workspace/ibutterfree/src/core/ibutterfree_surface.c:111:3: error: argument 1 null where non-null expected [-Werror=nonnull]
  111 |   memcpy(surface->desc, desc, sizeof(IButterFreeSurfaceDescription));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/diegocatalao/Desktop/workspace/ibutterfree/includes/core/ibutterfree.h:30,
                 from /home/diegocatalao/Desktop/workspace/ibutterfree/includes/core/ibutterfree_surface.h:25,
                 from /home/diegocatalao/Desktop/workspace/ibutterfree/src/core/ibutterfree_surface.c:1:
/usr/include/string.h:43:14: note: in a call to function ‘memcpy’ declared here
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/ibutterfree.dir/build.make:135: src/CMakeFiles/ibutterfree.dir/core/ibutterfree_surface.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:147: src/CMakeFiles/ibutterfree.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
rprata commented 4 years ago

Como o código é compilado com -werror deve-se tirar os warnings.

rprata commented 4 years ago

@diegocatalao , poderia fazer checkout desse branch e testar em seu ambiente:

https://github.com/rprata/ibutterfree/tree/issue/26

rprata commented 4 years ago

4d2cce1f10a29bfb906b477f1421bce9cad314bd