l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 24: LUGOD election season has begun!
Page last updated:
2002 Jan 08 12:45

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] what is a bus error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] what is a bus error



Bus errors are a platform dependant thing. They can be caused by problems such as the integer 
alignment error below, where the computer tries to read a long from a memory location 
where the processor does not like to find the first byte of a long. This program didn't 
cause a bus error on my own x86, however it did cause a bus error on one of the HPs in the CS 
lab.

#include <iostream>
using namespace std;

int main()
{
  char * x = new char[16]; // the first byte has suitable alignment for anything

  for (int t=0;t<16;t++) x[t]=t;

  cout << reinterpret_cast<long*> (x) << endl;
  cout << reinterpret_cast<long*> (x+1) << endl;
 
  long a = *(reinterpret_cast<long*> (x+1)); 
  // there are no guarantees about the alignment of the second byte of data
  // so we could get a bus error here

  cout << setbase(ios::hex) << a << endl;

  delete[] x;
  return 0;
}

Matt Roper <matt@mattrope.com> spoke thus:
> In my experience, a bus error is caused by the same type of problem as a
> segmentation fault (i.e. out of bounds memory access).  I once had an
> out of bounds memory access in a program I wrote and found that
> depending on how far out of bounds my access was, the error message
> would change between "segmentation fault" and "bus error" (this program
> was running under Solaris on a Sun machine).
> 
> I'm not certain why one message appears sometimes and the other at other
> times, but one possibility (a wild guess) is that since some
> architectures use part of the address space to represent IO devices
> instead of memory locations, the "Bus Error" message will occur if the
> illegal memory location falls in the IO device address range and a
> "Segmentation Fault" will occur if the illegal memory location falls in
> the memory range.  FWIW, I've never seen a bus error message on x86
> Linux, so maybe it doesn't happen on the x86 architecture or maybe it's
> just triggered differently.
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.