C is powerful but extremely permissive, you can do what you want with memory and be able to build.
Kernel does not complain as long as you play with your own process memory.
Here process writes out of the buffer memory but still in the process stack memory, probably overwriting
a return address. This is why the error comes later when process tries to access or execute the previously corrupted address. Process is then killed by the kernel via a signal (Bus error, segfault, etc…).
Yes that would be an instinctive practice
In my defence valgrind is not very good for bound checking on stack arrays.
Best solution is static code analysis or compiling with a stack guard.
Compiling with -fstack-protector reports the error:
Writing GPIO_36: value=1
*** stack smashing detected ***: /home/root/toggly terminated
May I also suggest to also have a look at the 96BoardsGPIO lib .
Documentation issue has been reported.