I have made a program in which I am handling files but I am getting this error
(I have run it through gdb
)
Program received signal SIGSEGV, Segmentation fault. 0x0016e50b in vfprintf () from /lib/tls/i686/cmov/libc.so.6
I am not getting the exact line that contain error.
Can anybody tell me
- what this error means
- does it occur for any special reason
- or is it general error occurring because of many reason?
What does this error mean?
It basically means that you're accessing memory that you're not supposed to be accessing.
Does it occur for any special reason?
A segmentation violation can occur for a huge number of reasons. However, since it's happening in vfprintf
, it's likely to be limited to something like:
- Invalid file pointer.
- Not passing enough parameters for the format string.
- Passing a NULL pointer for a C string.
- Passing a non-null-terminated pointer for a C string.
- Memory corruption from a totally different part of the program.
That's the most likely reasons.
Or is it a general error occurring because of many reasons?
As I said, it can occur for a vast number of reasons but it's probavly limited based on your circumstances.
Check all of the parameters before calling the printf
call (not with printf
of course, use some more robust debugging code such as printing each character of a string with flushing and fsyncing after each). And check that the file handle is valid and that the number of parameters passed to vprintf
matches those specified in the format string.
精彩评论