7

I'm getting weird seg fault that seems to be coming from somewhere not in my program...not explicitly anyway. I'm calling "strcmp" on two array's... Both arrays are stored in the same type of structs. I'm getting at one with dot notation and one through dereferencing with "->":

int name = strcmp(one.name, two->name);

It compiles fine but when I run it I get the seg fault. I've tried tracking it down with GDB but when I put breakpoints in just before where I think it should occur, it seg faults anyway. I'm getting:

Program received signal SIGSEGV, Segmentation fault.
__strcmp_ia32 () at ../sysdeps/i386/i686/multiarch/../strcmp.S:40
40  ../sysdeps/i386/i686/multiarch/../strcmp.S: No such file or directory.
    in ../sysdeps/i386/i686/multiarch/../strcmp.S

FML. Suggestions? Thanks!

MCP
  • 4,436
  • 12
  • 44
  • 53
  • 2
    Did you try a backtrace when it segfaults in gdb? – Mike Bailey May 17 '12 at 02:51
  • 2
    What is the value of `one.name`, `two`, and `two->name` at the point of call? – Mud May 17 '12 at 02:53
  • 4
    You have encountered a segmentation fault and the source for `strcmp` does not exist in your environment, When the system tries to lookup for it *after* the seg fault occurred. The source is not needed to be present it is a standard library function.So the problem is that you are overwritting the bounds of memory some other place.Running your program with valgrind or an memory analysis tool should give the exact details of where. – Alok Save May 17 '12 at 02:55
  • 1
    @Mud That comment made be go back through with a comb and I commented out some memory clean-up that I was doing... Now the seg fault is happening at a much clearer location. Going to backtrace in GDB and see what happens. stand by. – MCP May 17 '12 at 03:19
  • that helped. I was deleting pointers to an external (outside of the function) data, thinking that they were the only thing going away but somehow that was affecting a later reference to that data source. (two different hash tables using the same data...) The part that threw me was the weird error I was getting... It was vague enough that it reminded me of a library issue I had on an earlier program. Thanks guys! – MCP May 17 '12 at 03:44

1 Answers1

5

My suggestion: Compile it with -g and run it through valgrind.

Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93