Skip to main content
sara2
Associate
September 26, 2011
Question

Use of memset and memcpy

  • September 26, 2011
  • 11 replies
  • 8584 views
Posted on September 26, 2011 at 11:27

Hello,

I am using STM32-P103 to decode NMEA sentences with some codes that they were already written and making small changes in them and I have notice that the use of functions like memset and memcpy makes the system go into an infinite loop where it can't come out.

Is there a way to make it work with out getting it stuck there or an equivalent function to it?

I am using Eclipse and C++.

&sharpinclude <stdio.h>

&sharpinclude <stdlib.h>

&sharpinclude <string.h>

char* sixbit2bin(char* sixbit, int length)

{

    int i = 0;

    int value = 0;

    static char ret[MAX_RET];

    char tmp[10];

    memset(ret,0,sizeof(ret));

    if(length<=0)

        return NULL;

    for(i=0;i<length;i++)

    {

        value = sixbit[i]+40;

        if(value>128)

            value+= 32;

        else

            value+= 40;

        memset(tmp,0,sizeof(tmp));

        memcpy(&ret[6*i],&tmp[2],6);

    }

    ret[6*i] = '\0';

    return ret;

}

This is one of the functions in which it gets stuck...

Sorry if this is a stupid question but I can't find my way out of the problem. Thanksss

#fault-handler #fault-handler #fault-exception
    This topic has been closed for replies.

    11 replies

    trevor23
    Associate III
    September 27, 2011
    Posted on September 27, 2011 at 11:21

    Also check your stack usage as you have some big(ish) buffers declared local

    e.g. char source[168+1];

    Do you know what size your stack size is set to currently?