Re: signal BUS (invalid address alignment)

Discussion in 'C++' started by Ron Natalie, Aug 21, 2003.

  1. Ron Natalie

    Ron Natalie Guest

    "Suresh" <> wrote in message news:...

    > 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).
    Ron Natalie, Aug 21, 2003
    #1
    1. Advertising

  2. Ron Natalie

    Artie Gold Guest

    Ron Natalie wrote:
    > "Suresh" <> wrote in message news:...
    >
    >
    >>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


    --
    Artie Gold -- Austin, Texas
    Artie Gold, Aug 21, 2003
    #2
    1. Advertising

  3. Ron Natalie

    Ron Natalie Guest

    "Artie Gold" <> wrote in message news:...

    >
    > 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.
    Ron Natalie, Aug 21, 2003
    #3
  4. Ron Natalie

    Artie Gold Guest

    Ron Natalie wrote:
    > "Artie Gold" <> wrote in message news:...
    >
    >
    >>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


    --
    Artie Gold -- Austin, Texas
    Artie Gold, Aug 21, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Artie Gold
    Replies:
    0
    Views:
    500
    Artie Gold
    Aug 21, 2003
  2. Mike Wahler
    Replies:
    2
    Views:
    483
    Ron Natalie
    Aug 22, 2003
  3. Jay Hamilton
    Replies:
    1
    Views:
    421
    Victor Bazarov
    Aug 11, 2006
  4. ADS7328

    invalid address alignment

    ADS7328, May 22, 2007, in forum: C++
    Replies:
    3
    Views:
    493
    Victor Bazarov
    May 22, 2007
  5. ADS7328

    invalid address alignment

    ADS7328, May 22, 2007, in forum: C++
    Replies:
    2
    Views:
    382
    red floyd
    May 22, 2007
Loading...

Share This Page