Re: signal BUS (invalid address alignment)

R

Ron Natalie

Suresh said:
My C++ program crashes with "signal BUS (invalid address alignment)" at
random places. Does anyone know what this could mean ? What is the cause of
signal BUS ?

I suspect, it's "invalid address alignment" just as it says. Typically, you are violating
the alignment constranits, etc...

char foo[10];
*(int*)(foo+1) = 1;

for example on a machine that requires int's to be aligned on some multiple number
of bytes.

The historical word SIGBUS comes from the UNIX signal names which was derived
from the PDP-11 BUS ERROR processor trap. There were two things that would cause
this trap. One was accessing words on odd addresses. The other was accessing a
memory address that, while mapped in to your address space, didn't answer (missing or
otherwise not responding).
 
A

Artie Gold

Ron said:
My C++ program crashes with "signal BUS (invalid address alignment)" at
random places. Does anyone know what this could mean ? What is the cause of
signal BUS ?


I suspect, it's "invalid address alignment" just as it says. Typically, you are violating
the alignment constranits, etc...

char foo[10];
*(int*)(foo+1) = 1;

for example on a machine that requires int's to be aligned on some multiple number
of bytes.

The historical word SIGBUS comes from the UNIX signal names which was derived
from the PDP-11 BUS ERROR processor trap. There were two things that would cause
this trap. One was accessing words on odd addresses. The other was accessing a
memory address that, while mapped in to your address space, didn't answer (missing or
otherwise not responding).

While you may have diagnosed the problem, the OP mentioned "random"
crashes; a pure misalignment situation as you've illustrated would
happen directly at the site. [NFI]

HTH,
--ag
 
R

Ron Natalie

Artie Gold said:
While you may have diagnosed the problem, the OP mentioned "random"
crashes; a pure misalignment situation as you've illustrated would
happen directly at the site. [NFI]

Well it's not clear what he means by random. Most likely if it means it doesn't
always happen, that it's a uninitialized variable causing a misaligned pointer
access. It can also because his program just sometimes happens to do it's
accesses aligned and sometimes not alligned without any true "randomness"
but just fails or not fails in different situations.
 
A

Artie Gold

Ron said:
While you may have diagnosed the problem, the OP mentioned "random"
crashes; a pure misalignment situation as you've illustrated would
happen directly at the site. [NFI]


Well it's not clear what he means by random. Most likely if it means it doesn't
always happen, that it's a uninitialized variable causing a misaligned pointer
access. It can also because his program just sometimes happens to do its
accesses aligned and sometimes not alligned without any true "randomness"
but just fails or not fails in different situations.

Valid point!

....and unless it _is_ flaky hardware (could be, I guess) it's obviously
not random in any real sense. It can sure _look_ that way though!

--ag

BTW -- [NFI] == no flame intended
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top