Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What does "bus error" (signal 7) mean?

6,570 views
Skip to first unread message

Theodore Sternberg

unread,
Oct 19, 1995, 3:00:00 AM10/19/95
to
"Signal 7" is how one of my programs exits, and in gdb I am told "Program
received signal SIGBUS, Bus error". This happens after some I/O
operations. I know I'm being a little vague here, but would someone
please tell me what "bus error" means, in a general way?

Many thanks!

Ted Sternberg
San Jose, California, USA

--
Theodore Sternberg <str...@rahul.net>

Rusty, Paul , Russell

unread,
Oct 22, 1995, 3:00:00 AM10/22/95
to
In message <4645v5$8...@bug.rahul.net> you write:
> "Signal 7" is how one of my programs exits, and in gdb I am told "Program
> received signal SIGBUS, Bus error". This happens after some I/O
> operations. I know I'm being a little vague here, but would someone
> please tell me what "bus error" means, in a general way?

Yes, you are being a little vague. It has various meanings on
different machines, but it is generally caused by a memory access
error: ie. you were reading or writing where you weren't supposed to
in memory.

The main culprit, besides running off the end of an array or using an
invalid pointer (esp. NULL pointers) is non-aligned memory accesses: on
some machines, types with size > 1 (eg. int, float, double) need to be
aligned on word boundaries, eg. "int"s might need to be at addresses 0,
4, 8, .... (This is generally true on RISC machines).

An example might be:
#include <stdio.h>

int main()
{
char array[5];
int *i = array + 1;

*i = 7;
}

Here if array is 4 byte aligned, then i is off by 1; illegal on most
machines. Trying to write to it usually causes a bus error.

An example of overrunning an array might be:
#include <stdio.h>

int main()
{
char tinybuffer[5];

fgets(tinybuffer, 5000, stdin);
}

Where we are allowing someone to try to put 5000 characters in a 5
character buffer! This will usually give a segmentation fault
(SIGSEGV, 11).

HTH,
Rusty.

>
> Many thanks!
>
> Ted Sternberg
> San Jose, California, USA
>
> --
> Theodore Sternberg <str...@rahul.net>

--
Rusty....@adelaide.maptek.com.au "Engineer? So you drive trains?"
DO NOT BEND, FOLD OR MUTILATE IN ANY WAY THIS SCREEN. #include <stddisclm.h>

0 new messages