Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:09:01+00:00 2026-05-31T05:09:01+00:00

I had a bug in my code that went like this. char desc[25]; char

  • 0

I had a bug in my code that went like this.

char desc[25];
char name[20];
char address[20];
sprintf (desc, "%s %s", name, address);

Ideally this should give a segfault. However, I saw this give a bus error.
Wikipedia says something to the order of ‘Bus error is when the program tries to access an unaligned memory location or when you try to access a physical (not virtual) memory location that does not exist or is not allowed. ‘

The second part of the above statement sounds similar to a seg fault. So my question is, when do you get a SIGBUS and when a SIGSEGV?

EDIT:-
Quite a few people have mentioned the context. I’m not sure what context would be needed but this was a buffer overflow lying inside a static class function that get’s called from a number of other class functions. If there’s something more specific that I can give which will help, do ask.

Anyways, someone had commented that I should simply write better code. I guess the point of asking this question was “can an application developer infer anything from a SIGBUS versus a SIGSEGV?” (picked from that blog post below)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:09:02+00:00Added an answer on May 31, 2026 at 5:09 am

    As you probably realize, the base cause is undefined behavior in your
    program. In this case, it leads to an error detected by the hardware,
    which is caught by the OS and mapped to a signal. The exact mapping
    isn’t really specified (and I’ve seen integral division by zero result
    in a SIGFPE), but generally: SIGSEGV occurs when you access out of
    bounds, SIGBUS for other accessing errors, and SIGILL for an illegal
    instruction. In this case, the most likely explination is that your
    bounds error has overwritten the return address on the stack. If the
    return address isn’t correctly aligned, you’ll probably get a SIGBUS,
    and if it is, you’ll start executing whatever is there, which could
    result in a SIGILL. (But the possibility of executing random bytes as
    code is what the standards committee had in mind when they defined
    “undefined behavior”. Especially on machines with no memory
    protection, where you could end up jumping directly into the OS.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did you ever had a bug in your code, you could not resolve? I
I had a bug that caused an integer overflow, resulting in wrong (negative) timestamps
Recently I had to fix a bug that was reported from the field. While
I came across an odd bug in my code that revealed an interesting behavior
I have a bug in my current code that I have been banging my
I have code that boils down to the following: template <typename T> struct Foo
Recently I had a weird bug where I was concatenating a string with an
I have run into an interesting bug where it appears that when you select
I've got a chunk of C# code that is supposed to set VerticalScroll.Value within
I am getting a NullPointerException raised in this code very rarely. This is part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.