UGH! widechar buffer problem
-
Hi all, I'm using fgetwc to get characters from a file. In ALL cases BUT 1, It calls this like it is supposed to (in _FGETWC.C): if ((stream->_cnt -= sizeof(wchar_t)) >= 0) -----> return *((wchar_t *)(stream->_ptr))++; else return (wint_t) _filwbuf(stream); In this single case (and there's about 300 of them), this gets called: if ((stream->_cnt -= sizeof(wchar_t)) >= 0) return *((wchar_t *)(stream->_ptr))++; else -------------> return (wint_t) _filwbuf(stream); And my application goes out the window, along with my monitor :mad: I can move the information around in the data file, and it's fine, but when in a specific order I get this every time. :confused: I really have no idea what is going on here. My gut says it has something to do with the wide character buffer going out of whack. Any ideas or suggestions? Thanks alot!
-
Hi all, I'm using fgetwc to get characters from a file. In ALL cases BUT 1, It calls this like it is supposed to (in _FGETWC.C): if ((stream->_cnt -= sizeof(wchar_t)) >= 0) -----> return *((wchar_t *)(stream->_ptr))++; else return (wint_t) _filwbuf(stream); In this single case (and there's about 300 of them), this gets called: if ((stream->_cnt -= sizeof(wchar_t)) >= 0) return *((wchar_t *)(stream->_ptr))++; else -------------> return (wint_t) _filwbuf(stream); And my application goes out the window, along with my monitor :mad: I can move the information around in the data file, and it's fine, but when in a specific order I get this every time. :confused: I really have no idea what is going on here. My gut says it has something to do with the wide character buffer going out of whack. Any ideas or suggestions? Thanks alot!
When CRTL (C-Runtime Library) routines start to crash, it almost always means you have other bugs in your program that is trashing memory. Data structures used by the CRTL are getting trashed and thus crashing. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
When CRTL (C-Runtime Library) routines start to crash, it almost always means you have other bugs in your program that is trashing memory. Data structures used by the CRTL are getting trashed and thus crashing. Tim Smith I'm going to patent thought. I have yet to see any prior art.
Yes that is true. I found a really weird case though. As it turns out, the FILE stream buffer is allocated in 4k segments. When you do an fread, the fread checks the size left in the buffer and puts as much as it can into that buffer and sets a flag saying the buffer is full. At that point a new buffer is allocated and fread continues along it's merry way. In my case I'm using fgetwc, which gets 2 characters (4 bytes). It checks to see if there is enough space in the buffer for the 2 characters, and if so puts it in. If there is not enough space (meaning there is only 2 bytes left in the buffer), it returns 2 chars worth of jargen, causing the application to bomb. Becuase it only occurs when there I am calling fgetwc and there is only 2 bytes left in the buffer, I am rarely seeing this case but am able to easily reproduce the problem. My solution, to not use fputwc and fgetwc anymore, but to use fwrite and fread. You can find this in the _FGETWC.C that came with VC++ 6.0