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 7629627
In Process

The Archive Base Latest Questions

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

I am new to C and have a question about initializing a structure. I

  • 0

I am new to C and have a question about initializing a structure. I am using a structure that I have not created and so I don’t know what is inside of it. Therefore, I did not initialize it but the compiler complained. So I set it equal to NULL but I got a segmentation fault. Then I looked up how to set everything to 0 and it said to set it equal to {0}. That too gave me a segmentation fault. Since I know the function I am calling is correct, and that the array I pass it is of the correct size, I am almost certain it has something to do with the way I initialize the structure. The initialization is

struct aes_ctx *aes_struct = {0}

The header for the function is

void aes_setkey(aes_ctx *aes, const void *key, u_int len);

The way that I am calling it is

aes_setkey(aes_struct, aes, CCA_STRENGTH);

where aes is a buffer of size 16, CCA_STRENGTH is a constant int of 16.

To sum up the problem, I think that the way that I initialize the structure causes it to be unusable later on. Any help that can be given to me on this would be so appreciated!
Thanks!

  • 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:52:59+00:00Added an answer on May 31, 2026 at 5:52 am

    You cannot initialize a pointer that way (well, you can, it just doesn’t point to anythign valid). Something like this is what you are after:

    struct aes_ctx aes_struct = {0};
    

    You can then pass the address of aes_struct to the function, but that depends on whether or not you need to dynamically allocate this thing (required scope and the size of the type will dictate this).

    So…

    struct aes_ctx aes_struct = {0};
    aes_setkey(&aes_struct, aes, CCA_STRENGTH);
    

    Or

    struct aes_ctx *aes_struct = malloc(sizeof(struct aes_ctx));
    /* you may want to initialize the structure via memset or some init function */
    aes_setkey(aes_struct, aes, CCA_STRENGTH);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have a question about how to structure communication between a (new) Firefox extension
I'm new in using MVC and I have a question about summarizing the row
I'm new to Puppet and have a question about working with dependencies. I'm using
I have been asked to post a new question about how to correctly sort
I'm new to Windows development and I have a question. I'm using a Mac
I have a question about the Singleton Pattern and MEF. I'm new in implementing
I am new to Stack Overflow and have a question about JSF 2.0 and
I have a question about Scheme. I am fairly new to the language, and
I'm new to Rails development and I have a question about handling an unknown

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.