10-19-06 06:21 PM
Wes wrote:
> char* ofile = new char[sizeof(file) + 4];
[...]
> for(int i = 0; i < sizeof(file); i++)
> {
> ofile[i] = file[i];
> }
> // then tack on the '.enc'
> ofile[sizeof(file) + 1] = '.';
> ofile[sizeof(file) + 2] = 'e';
> ofile[sizeof(file) + 3] = 'n';
> ofile[sizeof(file) + 4] = 'c';
sizeof(file) will return the size of the file pointer (most likely 4),
not the number of characters in the string that file is pointing to.
You should use strlen(file) instead.
> tbuff = Encrypt(buffer);
This is probably the cause of your crash. You have, most likely, been
fooled by the fact that char pointers work differently than std::string.
If tbuff was a std::string then the above would copy the results of
Encrypt() to the tbuff variable, and all would be fine.
However, the tbuff variable is a char pointer. Initially you allocate 32
bytes for this buffer. However, the above assignment overwrites the
tbuff pointer with whatever pointer is returned by Encrypt(). The result
of Encrypt() is not copied into the initially allocated tbuff. If
Encrypt() returns an allocated buffer then you have a memory leak here,
otherwise you are probably returning garbage that is causing the
subsequent crash. The fact that it happens when you reach 15360 is
accidental.
--
mail1dotstofanetdotdk
[ Post a follow-up to this message ]
|