What could be causing this SIGSEV?

Jones
Unregistered
 
Post: #1
I'm receiving a memory violation (signal 11: SIGSEV) error when I run a program designed to test a small segment of flx. I extracted the error log, it can be viewed here: http://homepage.mac.com/gareth.cross/sigsevlog.txt

The line:

Code:
Thread 0 Crashed:
0   libstdc++.6.dylib     0x947779b8 std::basic_ifstream<char, std::char_traits<char> >::close() + 52

Makes me believe that the error is originating from my ifstream or ofstream declarations, or related commands.

Code:
Exception:  EXC_BAD_ACCESS (0x0001)
Codes:      KERN_INVALID_ADDRESS (0x0001) at 0xfffffff4

This also appears to be important, and I'm pretty sure it's telling me that the problem is originating from 0xfffffff4, although I'm not sure how to make any solution to this in my code. Are there any likely perpetrators of this?

It's a bit annoying, as I had just finised debugging all 30 of my compile errors, all on my own for once. Smile (Hurray-ness.) Some of them had required weird solutions, for example I actually hand to define the letter w in an array if I wanted to use it. Shock

Anyway, if you think you know what's wrong, you can take a look at my code here: http://homepage.mac.com/gareth.cross/FLX_Test_IO.zip

Thanks for any help available!
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
It's my guess that the string isn't NULL terminated. That way, it just keeps trying to read the string until it crashes from reaching a protected or invalid address. This may mean that your method of getting the string isn't grabbing what you want. To read it and see if it's even remotely what you want, you can set myString[126] = 0 before you print it out.
Quote this message in a reply
Jones
Unregistered
 
Post: #3
akb825 Wrote:It's my guess that the string isn't NULL terminated. That way, it just keeps trying to read the string until it crashes from reaching a protected or invalid address. This may mean that your method of getting the string isn't grabbing what you want. To read it and see if it's even remotely what you want, you can set myString[126] = 0 before you print it out.

Hmm, well I'm not using a loop to read in my FLX function, if that's what you mean... it just takes the words one by one like reading from an ifstream to a char array.

I tried reducing myString to only 16 spots, and that didn't change anything. I'll just go through the FLX functions that handle file opening and reading. Maybe I should also place put in the close file function. I'll see if that works.

EDIT:

Close function didn't help, not that it would anyway. :/

I only get one warning when I build, it says I'm not allowed to define an int as NULL. I somehow don't think that's it, but I'll change it anyway.
Quote this message in a reply
Jones
Unregistered
 
Post: #4
Update:

I added cout's after each function call. Not even the first appeared. I'm assuming that means the error is in the first function, unless the SIG message overrode it?
Quote this message in a reply
Jones
Unregistered
 
Post: #5
FIXED! FIXED! FIXED! Wow

Sorry, just a bit too happy.

In the end, I was trying to close streams that weren't open yet with my initial array purge. I'll just write a "is this the first purge" loop into there.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
Glad to see it's fixed, but you seem to have a complete misunderstanding of NULL terminated strings. For a C-style string, you have the characters in the array, then after the last character you have a 0, or NULL, terminator to mark the end. When a string is read, it is usually read from the beginning to the NULL terminator. In this case, when it was being read incorrectly, the function you were calling wouldn't put a NULL terminator in your string, which would mean that the cout function never stopped reading.
Quote this message in a reply
Jones
Unregistered
 
Post: #7
When I want to read to the end of something, I extract it's length with strlen and use a while loop. Huh
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #8
And how do you think strlen figures out the length of your string? Wink

From http://fxr.watson.org/fxr/source/lib/str...nux-2.4.22:
Code:
size_t strlen(const char * s)
{
        const char *sc;

        for (sc = s; *sc != '\0'; ++sc)
                /* nothing */;
        return sc - s;
}
Quote this message in a reply
Jones
Unregistered
 
Post: #9
Well yes, but what I meant was: why would I bother to do it myself. Rolleyes
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #10
Quote:Well yes,...

I mentioned it because your post was in response to akb825's, and it seemed to imply that you thought that the lack of a null ('\0') at the end of a char array didn't matter, because you were using strlen. Pascal, for instance, doesn't use a a terminator. Instead, the first byte contains the length of the string, and the Pascal equivalent of strlen simply returns that. Not so in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SIGSEV I can trace, but not fix (help needed) wyrmmage 20 6,985 Nov 25, 2006 11:03 PM
Last Post: wyrmmage