What Causes SIGBUS Errors?

The SIGBUS error is caused by 3 things:
  1. invalid address alignment
  2. non-existent physical address
  3. object specific hardware error
If you don't deal with hardware devices you can only get the first case.

Invalid address alignment is caused when you perform operations on a data object that is not aligned at the right boundaries. For example, attempting to read a int (32 bits or 4 bytes) and the address is not at a 4-byte boundary. The same would go for pointers (4-byte or 8-byte), longs (4-byte or 8-byte), and shorts (2-byte). The SIGBUS error commonly occurs through function calls which have pointer arguments.

Here is an example that will cause a SIGBUS error:

	main()
	{
		int *x;
		char buf[100];

		x = &buf[3];
		*x = 10000;
	}
In this example, the line "*x = .." will cause a SIGBUS because x is pointing to the address of &buf[3] which is clearly not at an int(4-byte) boundary. Note that changing 3 to either 4 or 8 would probably allow the code to run without problems.

For more information see signal(5). For OSF1 alpha systems also see uac(1). 1

Hosted by www.Geocities.ws