K
K
Kalombyr2017-08-25 15:06:27
C++ / C#
Kalombyr, 2017-08-25 15:06:27

What are the pitfalls of memmove on gcc STM32?

Greetings!
You need to shift the array left and right (not cyclically, protruding elements are removed).
To do this, I made the following code:

int N = MIN( (len-index), (QUEUE_SIZE-index2) ); 
 memmove(buf+index2, buf+index,  N * sizeof(int) );

Where
  • buf - static array (for example, int is specified, in real life void *),
  • QUEUE_SIZE - its length
  • len - the index of the last real element
  • index - from where
  • index2 - where
  • N - calculates how many elements to move

This is how it looks like:
QUEUE_SIZE = 12
len = 10
m[12]= 1_2_3_4_5_6_7_8_ 9_10_0_0
______|_______|_________________
__________index___index2_____________
index = 2 - where
index2 = 5 - where
The result should be like this:
m[12]= 1 2 0 0 0 3 4 5 6 7 8 9
This is how it turns out, but on stm32 sometimes NULL appears in buf[0], although it should not be there, and all other elements match in the right places. The length len is the same. What are the pitfalls of memmove() or where could I mess up?
Here is an example code in its entirety for experimentation: cpp.sh/9e436
PS The stack and heap sizes do not overlap each other, there is enough memory.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question