I need help to check if my code is correct. The code is too big to include entirely, so I will paste only the affected parts.
char *tmp;
tmp=Decode_URL(tmp_data);
sprintf(Data,"%s",tmp);
tmp=Decode_URL(tmp_backup1);
sprintf(DataB[0],"%s",tmp);
tmp=Decode_URL(tmp_backup2);
sprintf(DataB[1],"%s",tmp);
tmp=Decode_URL(tmp_backup3);
sprintf(DataB[2],"%s",tmp);
tmp=Decode_URL(tmp_backup4);
sprintf(DataB[3],"%s",tmp);
tmp=Decode_URL(tmp_backup5);
sprintf(DataB[4],"%s",tmp);
The Decode_URL function returns a char *.
So my question is, is it correct to always use tmp to receive the char * returned by the function? Or I should create more char *tmpx, one for each call to Decode_URL?
EDIT FOR MORE INFO:
char *Decode_URL(char *url){
char *check;
check=EnDeCrypt(some vars here);
return check;
}
char *EnDeCrypt(const char *pszText, int iTextLen, const char *pszKey)
{
char *cipher;
int a, b, i=0, j=0, k;
int ilen;
int sbox[256];
int key[256];
ilen = strlen(pszKey);
for (a=0; a < 256; a++)
{
key[a] = pszKey[a % ilen];
sbox[a] = a;
}
for (a=0, b=0; a < 256; a++)
{
b = (b + sbox[a] + key[a]) % 256;
swapints(sbox, a, b);
}
cipher = (char *)malloc(iTextLen);
for (a=0; a < iTextLen; a++)
{
i = (i + 1) % 256;
j = (j + sbox[i]) % 256;
swapints(sbox, i, j);
k = sbox[(sbox[i] + sbox[j]) % 256];
cipher[a] = pszText[a] ^ k;
}
return cipher;
}
Thanks
Decode_url()Decode_URL. If you return a pointer to a local variable (like an array inside the function) then you suddenly have what is known as undefined behavior.