Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C error messages

Reply
Thread Tools

C error messages

 
 
Quentin Pope
Guest
Posts: n/a
 
      09-21-2011
Hello:

What is the principle difference between a Bus Error and a Segmentation
Fault please.

Thanks
QP
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      09-21-2011
Quentin Pope <(E-Mail Removed)> writes:

> What is the principle difference between a Bus Error and a Segmentation
> Fault please.


It's implementation-specific. Not all implementations have
either one.

The glibc manual describes one common distinction:

-- Macro: int SIGSEGV
This signal is generated when a program tries to read or write
outside the memory that is allocated for it, or to write memory
that can only be read. (Actually, the signals only occur when the
program goes far enough outside to be detected by the system's
memory protection mechanism.) The name is an abbreviation for
"segmentation violation".

Common ways of getting a `SIGSEGV' condition include dereferencing
a null or uninitialized pointer, or when you use a pointer to step
through an array, but fail to check for the end of the array. It
varies among systems whether dereferencing a null pointer generates
`SIGSEGV' or `SIGBUS'.

-- Macro: int SIGBUS
This signal is generated when an invalid pointer is dereferenced.
Like `SIGSEGV', this signal is typically the result of
dereferencing an uninitialized pointer. The difference between
the two is that `SIGSEGV' indicates an invalid access to valid
memory, while `SIGBUS' indicates an access to an invalid address.
In particular, `SIGBUS' signals often result from dereferencing a
misaligned pointer, such as referring to a four-word integer at an
address not divisible by four. (Each kind of computer has its own
requirements for address alignment.)

The name of this signal is an abbreviation for "bus error".

--
"...what folly I commit, I dedicate to you."
--William Shakespeare, _Troilus and Cressida_
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      09-22-2011
On Wed, 21 Sep 2011 20:25:55 +0000, Quentin Pope wrote:

> What is the principle difference between a Bus Error and a Segmentation
> Fault please.


Ultimately, it depends upon which interrupt the hardware generates.

Typically, SIGSEGV arises from accessing a virtual memory page which
is either not backed by physical memory or which doesn't permit the
requested operation (e.g. write to a read-only page), while SIGBUS arises
from a misaligned access on an architecture which has alignment
constraints.

 
Reply With Quote
 
Quentin Pope
Guest
Posts: n/a
 
      09-22-2011
Thanks Ben.

Would you say then that a Bus Error is a showstopper but a Segmentation
Fault is less serious, so it would be worth catching that signal, maybe
writing a message to a log file, but then continuing with the program?


On Wed, 21 Sep 2011 13:36:06 -0700, Ben Pfaff wrote:
> Quentin Pope <(E-Mail Removed)> writes:
>
>> What is the principle difference between a Bus Error and a Segmentation
>> Fault please.

>
> It's implementation-specific. Not all implementations have either one.
>
> The glibc manual describes one common distinction:
>
> -- Macro: int SIGSEGV
> This signal is generated when a program tries to read or write
> outside the memory that is allocated for it, or to write memory
> that can only be read. (Actually, the signals only occur when the
> program goes far enough outside to be detected by the system's
> memory protection mechanism.) The name is an abbreviation for
> "segmentation violation".
>
> Common ways of getting a `SIGSEGV' condition include dereferencing
> a null or uninitialized pointer, or when you use a pointer to step
> through an array, but fail to check for the end of the array. It
> varies among systems whether dereferencing a null pointer generates
> `SIGSEGV' or `SIGBUS'.
>
> -- Macro: int SIGBUS
> This signal is generated when an invalid pointer is dereferenced.
> Like `SIGSEGV', this signal is typically the result of
> dereferencing an uninitialized pointer. The difference between the
> two is that `SIGSEGV' indicates an invalid access to valid memory,
> while `SIGBUS' indicates an access to an invalid address. In
> particular, `SIGBUS' signals often result from dereferencing a
> misaligned pointer, such as referring to a four-word integer at an
> address not divisible by four. (Each kind of computer has its own
> requirements for address alignment.)
>
> The name of this signal is an abbreviation for "bus error".


 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      09-22-2011
Quentin Pope <(E-Mail Removed)> writes:

> Would you say then that a Bus Error is a showstopper but a Segmentation
> Fault is less serious, so it would be worth catching that signal, maybe
> writing a message to a log file, but then continuing with the program?


I wouldn't do that in either case.
--
"When I have to rely on inadequacy, I prefer it to be my own."
--Richard Heathfield
 
Reply With Quote
 
Joe Pfeiffer
Guest
Posts: n/a
 
      09-22-2011
Quentin Pope <(E-Mail Removed)> writes:
>
>
> On Wed, 21 Sep 2011 13:36:06 -0700, Ben Pfaff wrote:
>> Quentin Pope <(E-Mail Removed)> writes:
>>
>>> What is the principle difference between a Bus Error and a Segmentation
>>> Fault please.

>>
>> It's implementation-specific. Not all implementations have either one.
>>
>> The glibc manual describes one common distinction:
>>
>> -- Macro: int SIGSEGV
>> This signal is generated when a program tries to read or write
>> outside the memory that is allocated for it, or to write memory
>> that can only be read. (Actually, the signals only occur when the
>> program goes far enough outside to be detected by the system's
>> memory protection mechanism.) The name is an abbreviation for
>> "segmentation violation".
>>
>> Common ways of getting a `SIGSEGV' condition include dereferencing
>> a null or uninitialized pointer, or when you use a pointer to step
>> through an array, but fail to check for the end of the array. It
>> varies among systems whether dereferencing a null pointer generates
>> `SIGSEGV' or `SIGBUS'.
>>
>> -- Macro: int SIGBUS
>> This signal is generated when an invalid pointer is dereferenced.
>> Like `SIGSEGV', this signal is typically the result of
>> dereferencing an uninitialized pointer. The difference between the
>> two is that `SIGSEGV' indicates an invalid access to valid memory,
>> while `SIGBUS' indicates an access to an invalid address. In
>> particular, `SIGBUS' signals often result from dereferencing a
>> misaligned pointer, such as referring to a four-word integer at an
>> address not divisible by four. (Each kind of computer has its own
>> requirements for address alignment.)
>>
>> The name of this signal is an abbreviation for "bus error".


> Thanks Ben.
>
> Would you say then that a Bus Error is a showstopper but a Segmentation
> Fault is less serious, so it would be worth catching that signal, maybe
> writing a message to a log file, but then continuing with the program?


No. They're both showstoppers.

If anything, the segmentation violation is worse than the bus error --
really, the only thing that can cause it is a hosed data structure or
something even worse (like an OS bug). If you get one, you're dead.

A bus error can conceivably be a result of code with alignment errors
that could be reconstructed. I'm thinking of the yacc that shipped with
the first Sun Sparc machines, which generated code with exactly that
flaw, and which could conceivably have been patched-up (though fixing
yacc was obivously a more-right thing to do, and what happened in a
short time). Also, the original IBM POWER architecture specified that
unaligned accesses that crossed cache boundaries would trap, and were
supposed to be patched in a handler.

There are a very few applications people can point to that are
exceptions (seg fault handlers in debuggers are probably the poster
child). But if you are coding something that is one of those
exceptions, you know it and don't need to ask the question.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      09-23-2011
On 9/22/2011 5:07 PM, Quentin Pope wrote:
> Thanks Ben.
>
> Would you say then that a Bus Error is a showstopper but a Segmentation
> Fault is less serious, so it would be worth catching that signal, maybe
> writing a message to a log file, but then continuing with the program?


No. Both are evidence that your program has followed a bad
pointer (or bad array index), meaning that your code can no longer
trust its data. If you "recover" from either fault, what reason
have you to believe that any subsequent `if' will go in the right
direction? What degree of trust can you place in the program's
actions or output? The C Standard says that continuing from this
sort of signal yields undefined behavior; I believe (could be wrong
here) that POSIX says much the same thing. There is very little,
very very little, that can be done reliably after such an event.

Poor analogy, but maybe it gets the right flavor: After entrusting
your retirement savings to a financial advisor, you happen to catch
said advisor embezzling from your accounts. Do you write a message to
a log file and keep on going, or do you do something more drastic?

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      09-23-2011
Quentin Pope <(E-Mail Removed)> writes:
> Hello:
>
> What is the principle difference between a Bus Error and a Segmentation
> Fault please.


Given that it's possible for programs not written in C to generate the
same messages, and that there are implementations that support C and
which do not generate such messages, it should be fairly obvious that
your question has nothing to do with C.

However, I suspect you won't get full marks on your assignment if you
write that, so you still need to ask a platform-specific newsgroup to
do your homework for you.

Phil
--
"Religion is what keeps the poor from murdering the rich."
-- Napoleon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
There are no more messages on this topic. All messages in this topic may have expired or been deleted Coach 02 Computer Support 1 03-12-2007 03:44 PM
absence of router advertisment messages in reponse to roiuter solicitation messages sonia sainani Software 0 10-20-2006 09:20 AM
System error/Machine Error Messages =?Utf-8?B?TEFPRkE=?= Windows 64bit 7 07-25-2005 11:13 AM
i sent 2 messages about double messages monique Computer Support 0 11-27-2004 07:18 PM
will all these messages cause a problem . I am a new subscriber and my computer is downloading 100,000 messages. Will this cause any kind of a problem with my ability to store other items?? Camille White Camille White Computer Support 9 11-08-2004 01:13 AM



Advertisments