Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

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

  1. #1
    Member
    Join Date
    Jan 2022
    Location
    Netherlands
    Posts
    41

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

    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?
    Attached Files Attached Files

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    11,381
    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.

  3. #3
    Member
    Join Date
    Jan 2022
    Location
    Netherlands
    Posts
    41
    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?

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    11,381
    I agree with you, I also prefer to remove all warnings. That way when a new shows up, you are much more likely to see it and hopefully resolve it.

    There are a few options here:

    I believe that Paul fixed this warning with the commit: https://github.com/PaulStoffregen/Ra...2a4f2ebc439485

    Not sure if that was done before or after the beta

    Nope not in beta.
    Last edited by KurtE; 12-08-2022 at 01:44 PM.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,393
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •