In most cases, when something strange and incomprehensible happens, it is because of something else.
You may have dangling pointers in your code (even away from this function) pointing to some random memory locations.
Perhaps you used such a dangling pointer, and this could lead to overwriting some memory cells that you need. The result of this is that you changed the behavior of your program by changing some variable defined elsewhere, some constants, or even some code!
I suggest you debug your application using some tool that can check and report memory access errors, like Valgrind .
, , , ββ , , .