RadioHead\RHRouter.cpp compiler warning - is it a bug or shall I just ignore it?

sicco

Well-known member
In a T4.1 application I use the RFM95 SPI LoRa modules
Archived code attached.
When compiling I get this warning thrown at me.


Code:
In member function 'void RHRouter::deleteRoute(uint8_t)',
    inlined from 'void RHRouter::retireOldestRoute()' at C:\Users\HP\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0-beta2\libraries\RadioHead\RHRouter.cpp:148:16,
    inlined from 'void RHRouter::addRouteTo(uint8_t, uint8_t, uint8_t)' at C:\Users\HP\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0-beta2\libraries\RadioHead\RHRouter.cpp:79:22:
C:\Users\HP\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0-beta2\libraries\RadioHead\RHRouter.cpp:106:11: warning: 'void* memcpy(void*, const void*, size_t)' accessing 27 bytes at offsets 280 and 283 overlaps 24 bytes at offset 283 [-Wrestrict]
  106 |     memcpy(&_routes[index], &_routes[index+1],
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107 |            sizeof(RoutingTableEntry) * (RH_ROUTING_TABLE_SIZE - index - 1));
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In member function 'void RHRouter::deleteRoute(uint8_t)',
    inlined from 'void RHRouter::retireOldestRoute()' at C:\Users\HP\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0-beta2\libraries\RadioHead\RHRouter.cpp:148:16:
C:\Users\HP\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0-beta2\libraries\RadioHead\RHRouter.cpp:106:11: warning: 'void* memcpy(void*, const void*, size_t)' accessing 27 bytes at offsets 280 and 283 overlaps 24 bytes at offset 283 [-Wrestrict]
  106 |     memcpy(&_routes[index], &_routes[index+1],
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107 |            sizeof(RoutingTableEntry) * (RH_ROUTING_TABLE_SIZE - index - 1));
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Memory Usage on Teensy 4.1:
  FLASH: code:20728, data:6120, headers:8988   free for files:8090628
   RAM1: variables:8256, code:18088, padding:14680   free for local variables:483264
   RAM2: variables:16512  free for malloc/new:507776

Started using 1.58.0-beta2 - never had this before I think.
Now what?
 

Attachments

  • RFM95_Teensy41_SPI1_Receiver-221207a.zip
    2.2 KB · Views: 14
New compiler and it is checking things that previous versions of the compiler did not.

I believe that the description of memcpy is, that if the source and destination buffers overlap, then the results are undefined.
I believe that in most cases that I have seen: memcpy(&_routes[index], &_routes[index+1], ...
Will work fine. As long as the code in memcpy starts from the first byte of each... Which in most cases, I have seen it does...

But: memcpy(&_routes[index+1], &_routes[index], ...
Will screw up...

In overlapping cases, I believe that it is recommended to use memmove instead of memcpy.
 
Thank you KurtE. Makes sense. But the unease remains. I prefer code compiles with zero warnings - not just the code that I write but also the code that comes from libraries from I don't know where. I could now edit the code in the library that I use, but I guess those edits disappear again once I download the next version / update.
What is the process to initiate code fixes/polishing that will make it eventually all the way into the libraries that everyone downloads? Lookup who wrote it at send them an email? This forum?
 
Many of these compiler warnings have been fixed, but only available on github right now.

I'm going to package up 1.58-beta3 soon, with all (or most) of the compiler warning fixes and several recent fixes for use with Arduino 2.0.x on Windows. Right now I'm working on toolchains for the other 4 platforms, so with the next beta we can again have all platforms supported.
 
Back
Top