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

  • Home
  • SEARCH
  • 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 6033113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:26:11+00:00 2026-05-23T05:26:11+00:00

I have a function where I’m trying to take a 16-bit from a large

  • 0

I have a function where I’m trying to take a 16-bit from a large chunk of data. I’m running this code on a Solaris box and I can compile without warning or error. When I run this code, however, whenever it gets to the part where I de-deference my pointer, I instantly get a bus error. The code looks something like:

void find_info(unsigned char* packet) {

int offset = 9;
uint16_t short_value = *(uint16_t*)(packet+offset);

}

The bus error occurs when I’m trying to de-reference that “packet+offset” pointer in order to get a short. I know for a fact there is data at packet[offset] and packet[offset+1]. On Linux and Cygwin this code works fine. As far as I know, I’m not doing anything revolutionary. What’s going on here?

  • 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-23T05:26:12+00:00Added an answer on May 23, 2026 at 5:26 am

    Sounds like an alignment problem. On the Sun SPARC processor, you can only access something like a short via a pointer that is divisible by some power of 2, typically 8. So the value of offset=9 is clearly going to cause a problem.

    See http://blogs.oracle.com/d/entry/on_misaligned_memory_accesses for more details.

    I can’t recommend any way of fixing this without seeing more context; but if you’re reading data from some input source, you could just read the bytes and convert to a short using ntohs (see the man page for ntohs for details).

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

Sidebar

Related Questions

In my Java code I have function that gets file from the client in
I have simple from written on C/gtk+ and i have function in this appliction.
This is what i have function GetEventsList(){ $result = mysql_query(SELECT * FROM `events`) or
I have function named: - (void) AddSortedCustomFeed :(NSMutableArray*) rssList; this function adds items(Articles) from
I have function like this: function update_List(){ LIST=[]; $.each(feed_urls,function(index,value){ $.getJSON(value, function(data) { $.each(data.feed.entry,function(i,val){ LIST.push(val.content.src);
I have this code in my controller (admin): function save(){ $model = $this->getModel('mymodel'); if
I have function defined this way: def f1 (a, b, c = None, d
i want to have function like delete file from database by using link instead
I have: function SelectSubTopics() { $.ajax({ url: /Administration/Tests/SelectSubTopics, data: { DataSource: $('#DataSource').val(), testID: $('#TestID').val(),
I have function for export data into csv file : $products = //databse query

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.