File Stream change its address during writing text contents to the stream
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: File Stream change its address during writing text contents to the stream

  1. #1
    Join Date
    Apr 2013
    Posts
    3

    Question File Stream change its address during writing text contents to the stream

    Hi guys,

    I wrote a program to write text contents to file stream through fputs, the file stream address was changed
    in the middle of writing text content to the stream (11% text content have been put into the file stream),
    that cause the file stream pointer can be evaluated problem and raise exception on stream validation code in fputs library function, my question is what things could go wrong to make file stream pointer changed its address to something else or a NULL pointer if the file stream have not been flushed and closed.

    Thanks

    Jason

  2. #2
    Join Date
    Apr 1999
    Posts
    27,427

    Re: File Stream change its address during writing text contents to the stream

    Quote Originally Posted by jjsun View Post
    my question is what things could go wrong to make file stream pointer changed its address to something else or a NULL pointer if the file stream have not been flushed and closed.
    You wrote faulty code. Either a buffer overrun, uninitialized variable, invalid pointer access, etc.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Apr 2013
    Posts
    3

    Re: File Stream change its address during writing text contents to the stream

    Thanks Paul.

    The file stream pointer is global and initialized variable, I did some debug on this file stream, the address was changed to 0x00000000 or 0xsomeFFFF sometime or oxFFFFFFFF other time, and indeed only the file stream address change cause exception, but don't know what cause its address change, dose the file stream goes to buffer overrun or other buffer overrun, uninitialized variable, invalid pointer access to cause the file stream change its address end up to the file stream can not evaluated?

    Regards,

    Jason

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,632

    Re: File Stream change its address during writing text contents to the stream

    As Paul said you're doing something wrong in your code. Do you have other global variables? Is the code that access those variabels without flaws?

    What you can try is to declare an int just before and just after the filestream and set a data breakpoint on both. Hopefully that catches the offending code.
    Last edited by S_M_A; April 29th, 2013 at 02:35 PM.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  5. #5
    Join Date
    Apr 1999
    Posts
    27,427

    Re: File Stream change its address during writing text contents to the stream

    Quote Originally Posted by jjsun View Post
    Thanks Paul.

    The file stream pointer is global and initialized variable, I did some debug on this file stream, the address was changed to 0x00000000 or 0xsomeFFFF sometime or oxFFFFFFFF other time, and indeed only the file stream address change cause exception, but don't know what cause its address change,
    The reason for this is, again, bad coding on your part. Unless we see the code, that is all anyone can tell you. Unlike other programming languages, when you make a mistake in your code such as the ones I pointed out, anything can and will happen.

    Second, if you actually see your variable change while stepping into your program, then why is it you can't determine what may have changed the value? What line of code caused the address to change? Whatever that line of code is, that is what you should be investigating.

    Unless we actually see the code, just describing what you're doing is not enough information. A description is really what you would like the code to do, and then assumed that is what you coded the program to do -- it does not mean that the actual code is doing what you say it's doing. Let others see the code.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 29th, 2013 at 03:01 PM.

  6. #6
    Join Date
    Apr 2013
    Posts
    3

    Re: File Stream change its address during writing text contents to the stream

    Thanks Paul and S_M_A.

    The problem is solved now, the other buffer overrun cause the file stream address changed.

    Regards,

    Jason

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center