AnsweredAssumed Answered

Use of memset and memcpy

Question asked by england.sara on Sep 26, 2011
Latest reply on Sep 27, 2011 by Trevor
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++.

#include <stdio.h>
#include <stdlib.h>
#include <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

Outcomes