Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. UGH! widechar buffer problem

UGH! widechar buffer problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    will1383
    wrote on last edited by
    #1

    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!

    T 1 Reply Last reply
    0
    • W will1383

      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!

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      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.

      W 1 Reply Last reply
      0
      • T Tim Smith

        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.

        W Offline
        W Offline
        will1383
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups