🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #42785

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

#42785
From: Rusty, Paul , Russell
Date: Sun, 22 Oct 1995 00:00
66 lines
2279 bytes
In message <4645v5$81f@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 <strnbrg@rahul.net>

--
Rusty.Russell@adelaide.maptek.com.au           "Engineer? So you drive trains?"
DO NOT BEND, FOLD OR MUTILATE IN ANY WAY THIS SCREEN.    #include <stddisclm.h>
Technical Details
Message-ID: <199510220545.PAA01931@gauss.adelaide.maptek.com.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <4645v5$81f@bug.rahul.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,6261c102f92a410a
X-Google-Attributes: gid11318c,public
From: Rusty.Russell@adelaide.maptek.com.au (Rusty, Paul ,  Russell)
Subject: Re: What does "bus error" (signal 7) mean?
Date: 1995/10/22
Message-ID: <199510220545.PAA01931@gauss.adelaide.maptek.com.au>
X-Deja-AN: 117898359
distribution: gnu
sender: daemon@cis.ohio-state.edu
references: <4645v5$81f@bug.rahul.net>
organization: GNUs Not Usenet
newsgroups: gnu.gcc.help