开发者

memory error in c program [closed]

开发者_如何学JAVA It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜