arduino / ArduinoCore-API

Hardware independent layer of the Arduino cores defining the official API
https://www.arduino.cc/reference/en/
GNU Lesser General Public License v2.1
202 stars 118 forks source link

Fix: do not call "memcpy" if there is a) no data to copy, or b) the src pointer is null. #217

Closed aentinger closed 1 year ago

jboynes commented 11 months ago

This PR fails to compile the tests on my desktop, perhaps due to an unhelpfully insightful newer compiler.

% make
Consolidate compiler generated dependencies of target test-ArduinoCore-API
[  1%] Building CXX object CMakeFiles/test-ArduinoCore-API.dir/src/CanMsg/test_CanMsg.cpp.o
In file included from .../ArduinoCore-API/test/src/CanMsg/test_CanMsg.cpp:11:
.../ArduinoCore-API/test/../api/CanMsg.h:58:36: error: address of array 'other.data' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
    if (this->data_length && other.data)
                          ~~ ~~~~~~^~~~
.../ArduinoCore-API/test/../api/CanMsg.h:70:38: error: address of array 'other.data' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
      if (this->data_length && other.data)
                            ~~ ~~~~~~^~~~
2 errors generated.
make[2]: *** [CMakeFiles/test-ArduinoCore-API.dir/src/CanMsg/test_CanMsg.cpp.o] Error 1
make[1]: *** [CMakeFiles/test-ArduinoCore-API.dir/all] Error 2
make: *** [all] Error 2

Compiler:

% c++ --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin