I think this probably belongs here, since it seems to be an error with my C++, not my interpretation of winsock. However, feel free to move it if I'm wrong.

Okay, when I run this program, it returns the webpage okay, but I've been having problems once it's finished; it exits with this debug error: Run-Time Check Failure #2 - Stack around the variable 'stuff' was corrupted.

I don't think that recv will terminate the received data with '\0'. So if you receive more then one block of data ( that seems to be the purpose of the while loop ) you call strset() on a non terminated string and strset() will write over the bounds of stuff. Think you must not use any string-functions in this part of the code (including Write to File() ) because you will not get any 0-termination from recv.
Kurt

12-09-2005

nvoigt

Sidenote:

Code:

(char *)whichFunc

Casting away a const modifier ( especially without any reason ) will get you tarred and feathered where I work.

Casting away a const modifier ( especially without any reason ) will get you tarred and feathered where I work.

Good point, I shouldn't have done that... consider it removed :D

Zuk - what do I do about it? I mean, surely I need to use it as a string in order to write it to a text file? The thing is, I can actually get the data, but I just get this error. So could I just tell it to WriteToFile() a \0 after the loop, or should I put it into the loop itself?

12-09-2005

ZuK

Quote:

Originally Posted by timmygee

Zuk - what do I do about it? I mean, surely I need to use it as a string in order to write it to a text file? The thing is, I can actually get the data, but I just get this error. So could I just tell it to WriteToFile() a \0 after the loop, or should I put it into the loop itself?

The way you use WriteToFile() and strset() you should have a lot of spaces too many in your outputfile.
The best thing would be to open the file in binary mode and just write the nr of characters to the file that recv returns.
Like this

Ok that might not work exactly this way because you seem to write other things to that file as well. But you should get the idea.
If you still want to write the received data as string to the file you will have to concatenate the received blocks in memory using memcpy(), append the string terminator and use your WriteToFile() function to write the complete received data to the file.
Kurt

12-10-2005

timmygee

hmmm. but it is outputting into the textfile perfectly okay... I'm not at college right now, but once I get back, I'll try your modifications. That'll be on monday, so meh.

12-10-2005

ZuK

Quote:

Originally Posted by timmygee

hmmm. but it is outputting into the textfile perfectly okay... I'm not at college right now, but once I get back, I'll try your modifications. That'll be on monday, so meh.

I cannot test and prove my statements because I do not sit at a windows-box. But what I understand from the documentation recv() does not 0-terminate the received data ( it must not because it can be used to receive binary data as well ). So your call to strset() will fill the memory with spaces until it finds a 0-byte somewhere. In your WriteToFile() function you use strlen() to get the length of the received data witch again just searches for a 0-byte. That's why I think you should have a lot of spaces in your outputfile. ( maybe you just don't see them they are kind of invisible ;) )
Kurt