L
leonard.guillaume
Hi guys,
I use dynamic char arrays and I'm trying to get rid of the garbage in
it. Let me show you the code and then I'll explain more in details.
----------------------------------------------------------------------------------------------------
CFile oFile("User.tcx", CFile::modeRead);
CRijndael oDecrypt;
long size;
char* buffer,* buf;
size = oFile.GetLength();
buffer = new char[size];
memset(buffer, 0, size);
oFile.Read(buffer,size);
oFile.Close();
buf = new char[size];
int size_t = strlen(buf);
memset(buf, 0, size);
oDecrypt.Decrypt(buffer, buf, size, CRijndael::CBC);
CFile iFile("test_r.xml", CFile::modeCreate|CFile::modeWrite);
iFile.Write(buf, strlen(buf));
iFile.Close();
----------------------------------------------------------------------------------------------------
Ok so the big idea of the code above is :
1. Reads User.tcx which is a Rijndael encoded file and load everything
in a buffer which has the size of the file.
2. Throw the buffer to the Decrypt function which will use a second
buffer (*buf) to write the results. The *buf variable has the same size
as the *buffer and the encrypted file.
3. Write the results in *.buf to an XML file by using strlen(buf) in
order to avoid too many caracters to be written.
After that, I can see my whole XML file into the source file, but the
XML won't show up in a browser. All the code is there but I always get
garbage like this at the end of the file :
ýýýý
The weird thing is that strlen(buffer), strlen(buf) are giving me 2864
as the size of the buffers. But, the variable "size" which is the size
of the file in size = oFile.GetLength(); is showing 2848. I don't know
if this has something to do with the garbage, but I can assure you that
I do not resize my arrays.
In fact, if I do this :
buffer = new char[2848];
int len = strlen(buffer);
it will still gives me 2864 as strlen(buffer). Of course, if I use
memset the length goes down to 0, but the fact is that even if I
hardcode my dynamic arrays to 2848, they will size to 2864. Again, I
don't know if this has something to do with the garbage, but I'm
curious.
Bottom line, How can I get rid of the garbage into my written file ? I
don't really care having it in the buffer or not, as long as it's not
in the XML output file. And I must use dynamic arrays, since not all
files has the same size.
Thanks for any help
Guillaume
I use dynamic char arrays and I'm trying to get rid of the garbage in
it. Let me show you the code and then I'll explain more in details.
----------------------------------------------------------------------------------------------------
CFile oFile("User.tcx", CFile::modeRead);
CRijndael oDecrypt;
long size;
char* buffer,* buf;
size = oFile.GetLength();
buffer = new char[size];
memset(buffer, 0, size);
oFile.Read(buffer,size);
oFile.Close();
buf = new char[size];
int size_t = strlen(buf);
memset(buf, 0, size);
oDecrypt.Decrypt(buffer, buf, size, CRijndael::CBC);
CFile iFile("test_r.xml", CFile::modeCreate|CFile::modeWrite);
iFile.Write(buf, strlen(buf));
iFile.Close();
----------------------------------------------------------------------------------------------------
Ok so the big idea of the code above is :
1. Reads User.tcx which is a Rijndael encoded file and load everything
in a buffer which has the size of the file.
2. Throw the buffer to the Decrypt function which will use a second
buffer (*buf) to write the results. The *buf variable has the same size
as the *buffer and the encrypted file.
3. Write the results in *.buf to an XML file by using strlen(buf) in
order to avoid too many caracters to be written.
After that, I can see my whole XML file into the source file, but the
XML won't show up in a browser. All the code is there but I always get
garbage like this at the end of the file :
ýýýý
The weird thing is that strlen(buffer), strlen(buf) are giving me 2864
as the size of the buffers. But, the variable "size" which is the size
of the file in size = oFile.GetLength(); is showing 2848. I don't know
if this has something to do with the garbage, but I can assure you that
I do not resize my arrays.
In fact, if I do this :
buffer = new char[2848];
int len = strlen(buffer);
it will still gives me 2864 as strlen(buffer). Of course, if I use
memset the length goes down to 0, but the fact is that even if I
hardcode my dynamic arrays to 2848, they will size to 2864. Again, I
don't know if this has something to do with the garbage, but I'm
curious.
Bottom line, How can I get rid of the garbage into my written file ? I
don't really care having it in the buffer or not, as long as it's not
in the XML output file. And I must use dynamic arrays, since not all
files has the same size.
Thanks for any help
Guillaume