-2

I want to copy an uint8_t array to a uint8_t pointer

uint8_t temp_uint8_array[] = {0x15, 0x25, 0x32, 0x00, 0x52, 0xFD};

uint8_t* Buffer = temp_uint8_array;

And now :

Buffer = {0x15, 0x25, 0x32};

So I understand that my data is cut because of 0x00, is there a solution ?


As I have access to the size of tha datas to be copied I tried to use

memcpy(Buffer, &temp_uint8_array, local_length);

But it does not work

Clément
  • 37
  • 5

3 Answers3

1

uint8_t temp_uint8_array = is not an array but a syntax error.

So I understand that my data is cut because of 0x00

No it isn't. If you try to interpret the data as a string, then the 0x00 will get treated as a null terminator. But this is not a string.

is there a solution

Don't treat raw data as a string? memcpy will work perfectly fine.

But it does not work

What doesn't work? What is local_length and where did you get it from?

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • I tried to correct my syntax error in my post. My temp_uint8_array is the result from a copy from string data but this wotks well. I don't understand what you are saying when you say "Don't treat raw data as a string" local_length comes from a personnal function that returns the size of the param to be parsed (the size of the param in the original string). – Clément Oct 06 '21 at 09:23
  • 1
    @Clément Well then it is impossible to answer what exactly is going on in these artificial fragments ressembling the actual code. You have to post the actual code or a [mcve]. – Lundin Oct 06 '21 at 09:41
0

Ok so actually it was my variable viewer in my IDE that cuts my variable value so I can only see the value until the 0x00 but in memory the data has been copied.

Maybe it was interpreted as string so it display the value until the null terminator.

To know that I must have check what was going on in my mcu memory with th debugger.

Clément
  • 37
  • 5
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 06 '21 at 19:07
0

The memcpy isn’t correct :

memcpy(Buffer, &temp_uint8_array, …

As temp_uint8_array is an array then you should not prefix it with & :

memcpy(Buffer, temp_uint8_array,…

Buffer is pointing to temp_iint8_array so the memcpy does nothing but erasing bytes in the same memory location. You IDE might consider that uint8 array may be handled as char string and display contents until 0x00.

Ptit Xav
  • 3,006
  • 2
  • 6
  • 15