LennartHennigs / SimpleFSM

Arduino/ESP library to simplify setting up and running a state machine.
MIT License
69 stars 16 forks source link

Wrong type of memcopy argument #16

Closed fdufnews closed 1 month ago

fdufnews commented 12 months ago

Hi,

I got this errors at compile time

/home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.cpp: In member function 'void SimpleFSM::add(Transition*, int)':
/home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.cpp:149:64: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class Transition' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Werror=class-memaccess]
     memcpy(temp, transitions, num_standard * sizeof(Transition));
                                                                ^
In file included from /home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.h:14,
                 from /home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.cpp:2:
/home/frederic/Arduino/libraries/SimpleFSM/src/Transitions.h:46:7: note: 'class Transition' declared here
 class Transition : public AbstractTransition {
       ^~~~~~~~~~
/home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.cpp: In member function 'void SimpleFSM::add(TimedTransition*, int)':
/home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.cpp:189:60: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'class TimedTransition' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Werror=class-memaccess]
     memcpy(temp, timed, num_timed * sizeof(TimedTransition));
                                                            ^
In file included from /home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.h:14,
                 from /home/frederic/Arduino/libraries/SimpleFSM/src/SimpleFSM.cpp:2:
/home/frederic/Arduino/libraries/SimpleFSM/src/Transitions.h:64:7: note: 'class TimedTransition' declared here
 class TimedTransition : public AbstractTransition {
       ^~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors

This is caused by the first argument of memcopy that should be cast to (void*) Once corrected to this, no more errors

// line 149
    memcpy((void *)temp, transitions, num_standard * sizeof(Transition));

// line 189
    memcpy((void *)temp, timed, num_timed * sizeof(TimedTransition));

Regards,