-
April 29th, 2013, 12:39 PM
#1
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
-
April 29th, 2013, 12:53 PM
#2
Re: File Stream change its address during writing text contents to the stream
Originally Posted by jjsun
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
-
April 29th, 2013, 02:02 PM
#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
-
April 29th, 2013, 02:27 PM
#4
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.
-
April 29th, 2013, 02:56 PM
#5
Re: File Stream change its address during writing text contents to the stream
Originally Posted by jjsun
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.
-
April 29th, 2013, 04:22 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|