I have a very weird problem. I have been using ReadFile() for reading data from a device connected to the PC over USB. As the data to be read is received in chunks of 64 bytes, always, ReadFile() is called with 64 bytes to read. However, when i have to read a frame less than 64 bytes, occasionally a crash occurs.

I shall give an example of the code written:

//Memory allocation done to read 100 bytes from device - This value is known in prior and hence memory is allocated exactly
// First read of 64 bytes
// Second read of 64 bytes

-> Here data that would be sent from the device is only 100-64 = 36. Hence, even if I say a read for 64 bytes, there would be no scenario where data greater than 36bytes. hence, this code should work (though i know it is incorrect to allocate less memory and call ReadFile for size greater than the memory allocation).

Question: Could ReadFile() crash if data read is done for more bytes than memory allocation done (though we know what is the exact size of data i need to read)

PS: The reason for such kind of an implementation was a small flaw in design of the code that was developed.

5 Years
Discussion Span
Last Post by Salem

Well the answer would begin by you producing a debug build, then running the code in a debugger (say WinDbg), and from there finding out some actual usable information about the crash.

As opposed to merely speculating about where the problem might be with little or no evidence (at least none you bothered to tell us about anyway).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.