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

HELP: What the hell is "bus error"?

0 views
Skip to first unread message

Carnage

unread,
Jan 5, 1997, 3:00:00 AM1/5/97
to

I keep getting "bus error" with a program that I'm writing. Recalling that you
also get this error when Netscape 3 runs Java stuff, I tried doing the
"LD_PRELOAD" fix with my program (by setting LD_PRELOAD to an earlier libc ...
in my case I set it to /lib/libc.so.5.2.18). To my dismay, it worked.

I say "dismay" because now I know it has something to do with that change they
did with the current libc's. What exactly does "bus error" mean?

The error happens at a free() call. I seem to remember reading that free()ing
a NULL pointer will cause this error or something. Am I right? I hope not
because the pointer which I am free()ing is NOT a NULL pointer. And if I'm
right, I'm at a complete loss as to what could be wrong.

What else causes a bus error?

What makes this problem especially annoying is this: when I link the module
(it's a module of string handling routines, so I call morestring.c) with the
"test program" which I used to test the routines in that module, it worked
fine. Thinking that morestring.c was now a bug free module, I went ahead and
used it in my "real program". That's when things went screwy. I know the code
in my "real program" is ok because it works fine without the calls to the
routines in morestring.c.

(I don't know if that above paragraph was clear or not. If somebody is really
interested, I can tar+gzip the above modules and email it so you can take a
look at it. 'Tho its not big, it's probably too big to post to the newsgroup.)

Can somebody please shed some light on this mystery? The following is my
system setup:

Debian GNU/Linux v1.1 distribution
Linux kernel v2.0.12
gcc v2.7.2
libc v5.4.13
(I also have several other, older, libc's on my system).


Thanks in advance for any help on this!

--
==============================================================================
Arcadio Alivio Sincero, Jr.
Undergraduate Computer Science Major/Linux Enthusiast/Competitive Bodybuilder
email: S5...@aacci.aacc.cc.md.us
WWW: Not available yet -- still looking for free webspace!

"Bare feet magnetize sharp metal objects so they point upward from the floor,
especially in the dark."


Soeren Juelsgaard

unread,
Jan 5, 1997, 3:00:00 AM1/5/97
to

car...@consultant.umd.edu (Carnage) writes:

>
>
> I keep getting "bus error" with a program that I'm writing. Recalling that you
> also get this error when Netscape 3 runs Java stuff, I tried doing the
> "LD_PRELOAD" fix with my program (by setting LD_PRELOAD to an earlier libc ...
> in my case I set it to /lib/libc.so.5.2.18). To my dismay, it worked.
>
> I say "dismay" because now I know it has something to do with that change they
> did with the current libc's. What exactly does "bus error" mean?
>
> The error happens at a free() call. I seem to remember reading that free()ing
> a NULL pointer will cause this error or something. Am I right? I hope not
> because the pointer which I am free()ing is NOT a NULL pointer. And if I'm
> right, I'm at a complete loss as to what could be wrong.
>
> What else causes a bus error?

If you do free on a ptr that is altered since it was malloc'ed you
would also get a bus error.

[SNIP]

Regards

/**********************************************************\
|* Soeren Juelsgaard *|
|* ju...@kom.auc.dk *|
|* Aalborg University *|
|* Department of Communication Technology *|
|* Applied Signal Processing and Implementation *|
\**********************************************************/


Paul Bunyk

unread,
Jan 5, 1997, 3:00:00 AM1/5/97
to

"bus error" generally means you have violated memory protection
rules. If it would happen to me on a call to free(), I would not only
check if I'm freeing a NULL pointer (actually it *is* a valid
operation, at least according to man 3 free, though I remember
compiling my program with some brain-damaging DOS compiler which
complained on that too). More important is to be sure that you are
free()'ing a pointer which *was* obtained by malloc() or calloc() and
you are free()ing it only *once*! You may want to look at Electric
Fence library, try linking your program against this and see if it
would report any more information on what went wrong. Check
man libefence.

Good luck!

Paul


--
("`-''-/").___..--''"`-._ UNIX *is* user-friendly, he is just very
`6_ 6 ) `-. ( ).`-.__.`) picky about who his friends are...
(_Y_.)' ._ ) `._ `. ``-..-' Paul Bunyk, graduate student
_..`--'_..-_/ /--'_.' ,'art by (and part-time UN*X sysadm)
(il),-'' (li),' ((!.-' F. Lee http://pbunyk.physics.sunysb.edu/~paul

Joe Pfeiffer

unread,
Jan 6, 1997, 3:00:00 AM1/6/97
to

In article <5anmhh$s...@dailyplanet.wam.umd.edu> car...@consultant.umd.edu (Carnage) writes:

I keep getting "bus error" with a program that I'm writing. Recalling that you
also get this error when Netscape 3 runs Java stuff, I tried doing the
"LD_PRELOAD" fix with my program (by setting LD_PRELOAD to an earlier libc ...
in my case I set it to /lib/libc.so.5.2.18). To my dismay, it worked.

I say "dismay" because now I know it has something to do with that change they
did with the current libc's. What exactly does "bus error" mean?

The error happens at a free() call. I seem to remember reading that free()ing
a NULL pointer will cause this error or something. Am I right? I hope not
because the pointer which I am free()ing is NOT a NULL pointer. And if I'm
right, I'm at a complete loss as to what could be wrong.

What else causes a bus error?

Back in the PDP-11 days, before memory protection, if you tried to
access a non-existent memory location the result was a hardware bus
error. Today, I don't exactly what the difference between a bus error
and a segmentation violation is, but in either case you're looking for
a wild pointer.
--
Joseph J. Pfeiffer, Jr., Ph.D. Phone -- (505) 646-1605
Department of Computer Science FAX -- (505) 646-1002
New Mexico State University http://www.cs.nmsu.edu/~pfeiffer

One fish, two fish, red fish, blue fish: Dr. Seuss
Next fit, first fit, best fit, worst fit: Dr. Pfeiffer
-- note at the end of a final exam submitted by one of my students
this semester

Andy Vaught

unread,
Jan 7, 1997, 3:00:00 AM1/7/97
to

pfei...@nmsu.edu (Joe Pfeiffer) writes:

>In article <5anmhh$s...@dailyplanet.wam.umd.edu> car...@consultant.umd.edu (Carnage) writes:

>> I keep getting "bus error" with a program that I'm writing.

>Back in the PDP-11 days, before memory protection, if you tried to


>access a non-existent memory location the result was a hardware bus
>error. Today, I don't exactly what the difference between a bus error
>and a segmentation violation is, but in either case you're looking for
>a wild pointer.
>--
>Joseph J. Pfeiffer, Jr., Ph.D. Phone -- (505) 646-1605
>Department of Computer Science FAX -- (505) 646-1002
>New Mexico State University http://www.cs.nmsu.edu/~pfeiffer


A "bus error" also will occur on more modern machines like the sparc
when you try to write a word (4 bytes) to a memory address that is not
a multiple of four. The i386 will do a nonaligned write, but with a
performance hit.

Andy

--
-----------------
Andy Vaught
an...@green.la.asu.edu .... do iters=1, 10
: : /call msolve(a,b,x,i,iters,tol)
Arizona State University ======|write(6,201) iters, tol
Tempe, Arizona, USA OOOOOO \enddo return

Andrew Berry

unread,
Jan 8, 1997, 3:00:00 AM1/8/97
to

car...@consultant.umd.edu (Carnage) writes:

> What else causes a bus error?

Bus errors are also caused by non-aligned pointers. On many systems,
'int', 'long', 'float' etc values must aligned with a word boundary. If
you try to write one of these values into a memory address that isn't
word-aligned, you get a bus error. This often occurs when you pack a
chunk of memory yourself (instead of using a C struct) and put numeric
data after a variable-length string, for example. Note that malloc
always returns a word-aligned pointer.

This might be the problem.

Ciao,
--
AndyB (Andrew Berry)
=======================================================================
email: an...@dstc.edu.au \||/ Department of Computer Science
voice: +61 7 3365 3241 @@ The University of Queensland
fax: +61 7 3365 1999 \/ Australia 4072
=========== http://www.dstc.edu.au/AU/staff/andrew-berry.html =========


Ingo Molnar

unread,
Jan 10, 1997, 3:00:00 AM1/10/97
to

In comp.os.linux.development.apps Carnage <car...@consultant.umd.edu> wrote:

: What else causes a bus error?

the first group:
-------------------------------------------------------------------------------->
pc5829:~/linux/linux/arch/i386/kernel$ grep SIGBUS *.c
traps.c:DO_ERROR(11, SIGBUS, "segment not present", segment_not_present, current)
traps.c:DO_ERROR(12, SIGBUS, "stack segment", stack_segment, current)
<--------------------------------------------------------------------------------

these are hardware faults which are not used by Linux but are properly caught and
converted into SIGBUS. Applications which use some kind of segmentation model on
the i386 platform could generate such hardware traps too.

other Linux platforms might generate SIGBUS too for certain hardware faults.

the second group:
-------------------------------------------------------------------------------->
pc5829:~/linux/linux/mm$ grep SIGBUS *.c
filemap.c: * and results in a SIGBUS, while a private mapping just maps in a zero page.
memory.c: force_sig(SIGBUS, current);
vmscan.c: kill_proc(pid, SIGBUS, 1);
<--------------------------------------------------------------------------------

These are memory allocation problems for all 7 Linux platforms: first, if the
kernel is hopelessly overworked, and cannot allocate a free page (no matter how
hard it tries), it generates a SIGBUS for the current process.
Second, if you write past the end of file in a shared mapping.

(hope i have found all the SIGBUS sources and have explained them sufficiently :)

-- mingo


Sean Walton

unread,
Jan 10, 1997, 3:00:00 AM1/10/97
to

I would amend this assertion with "On a FEW systems...". I honestly,
have never had this problem with Intel processors. I just checked
and found that Sparc barfs; Intel does not.

For those that want to write portable source: I would recommend
staying away from cross-type casting (e.g. char* => int*) unless
you're willing to ensure word alignment.

-Sean Walton, KB7rfa

Andrew Berry (an...@willow.dstc.edu.au) wrote:
: car...@consultant.umd.edu (Carnage) writes:

: > What else causes a bus error?

: Bus errors are also caused by non-aligned pointers. On many systems,

Rob Janssen

unread,
Jan 11, 1997, 3:00:00 AM1/11/97
to

>car...@consultant.umd.edu (Carnage) writes:

>> What else causes a bus error?

>Bus errors are also caused by non-aligned pointers. On many systems,
>'int', 'long', 'float' etc values must aligned with a word boundary. If
>you try to write one of these values into a memory address that isn't
>word-aligned, you get a bus error. This often occurs when you pack a
>chunk of memory yourself (instead of using a C struct) and put numeric
>data after a variable-length string, for example. Note that malloc
>always returns a word-aligned pointer.

>This might be the problem.

Not on the Intel x86 processor family. It handles non-aligned accesses.

Rob
--
+------------------------------------+--------------------------------------+
| Rob Janssen pe1...@amsat.org | WWWhome: http://www.pe1chl.demon.nl/ |
| AMPRnet: r...@pe1chl.ampr.org | AX.25 BBS: PE1CHL@PI8WNO.#UTR.NLD.EU |
+------------------------------------+--------------------------------------+

MaRTiN WhItE

unread,
Jan 16, 1997, 3:00:00 AM1/16/97
to

>
> : > What else causes a bus error?
>

I was working on an industrial machine mounted under a press table and during
the early setup of the press when it was still slamming down sig bus errors
would occur because cards were knocked so hard the jumped in the slot
monentarily and caused a sig bus the current process on the cpu.

I had vi die with a sig bus during working with the machine once.

of coures all this was under the second best unix varinant in my mind QNX.
I assume things would be similar if the machine had been running linux.


___ Signed,
/ /__ Martin -Hyper Boy- White
/______> Blade 'til you can't Blade anymore...
()()()() Then go code some in Linux...


0 new messages