J
James Leddy
Hello,
I'd like to take a string passed as an argument and realloc() the string to
have more spaces. Then I thought that I would probably have to free() the
string. But now I am confused
If I free() the string in the called function what happens to the data that
that was passed by the calling function.
Ok, so what if I free()d it by the calling function. But then again I
didn't pass the string as a double pointer, so I don't know really how that
would work. And what if I passed a string literal in, how would the
calling function be responsible for that?
Here is the specific instance. As many of you may know, blowfish algorythim
bepends on a key, which I have chosen to represent as a string. I'm
supposed to wrap the string if I run out of chars, but since I need it in 4
char blocks, I decided to add three chars to the end
int InitializeBlowfish(char *key, size_t len)
{...
key = realloc(key, len + 4); //give 3 more spaces,
memcpy(key + len, key, sizeof(char) * 3);
....}
How do I go about free()ing the memory I realloc()ed?
I'd like to take a string passed as an argument and realloc() the string to
have more spaces. Then I thought that I would probably have to free() the
string. But now I am confused
If I free() the string in the called function what happens to the data that
that was passed by the calling function.
Ok, so what if I free()d it by the calling function. But then again I
didn't pass the string as a double pointer, so I don't know really how that
would work. And what if I passed a string literal in, how would the
calling function be responsible for that?
Here is the specific instance. As many of you may know, blowfish algorythim
bepends on a key, which I have chosen to represent as a string. I'm
supposed to wrap the string if I run out of chars, but since I need it in 4
char blocks, I decided to add three chars to the end
int InitializeBlowfish(char *key, size_t len)
{...
key = realloc(key, len + 4); //give 3 more spaces,
memcpy(key + len, key, sizeof(char) * 3);
....}
How do I go about free()ing the memory I realloc()ed?