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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:34:31+00:00 2026-05-31T01:34:31+00:00

I am new to C programming and I am getting confused with the pointer

  • 0

I am new to C programming and I am getting confused with the pointer math. I have an array of characters of size 32. It is my understanding that this means that the array is also 32 bytes since a character variable is 1 byte big therefore 32 characters * 1 byte = 32 bytes. The problem is when having a function that has a void pointer that is pointing to an array of characters as described before. I believe that the code segment

for (count = 0; count < size; count++)
*((int*) raw_sk + count) = 0

should set all of the slots in the raw_sk buffer should be set to 0. However, when I run the program, I get a segmentation fault. I thought that it could be possibly be the fact that I am adding count to the address. I thought that if I were to add one to an address I would be moving to the next slot in the array. Can someone please point out where I am going wrong? The function I am using is below.
Thanks!

void
write_skfile (const char *skfname, void *raw_sk, size_t raw_sklen)
{
  int fdsk = 0;
  char *s = NULL;
  int status = 0;
  int count = 0;
  int size = (raw_sklen);


  /* armor the raw symmetric key in raw_sk using armor64 */
  s = armor64(raw_sk, raw_sklen);

  /* now let's write the armored symmetric key to skfname */

  if ((fdsk = open (skfname, O_WRONLY|O_TRUNC|O_CREAT, 0600)) == -1) {
    perror (getprogname ());

    /*scrubs the armored buffer*/
    for(count = 0; count < armor64len(s); count++)
    s[count] = '0';

    free (s);

    /* scrub the buffer that's holding the key before exiting */
   for (count = 0; count < size; count++)
    *((int*)raw_sk + count) = 0;

    exit (-1);
  }
  else {
    status = write (fdsk, s, strlen (s));
    if (status != -1) {
      status = write (fdsk, "\n", 1);
    }

   for (count = 0; (size_t)count < 22; count++)
    *((int*)raw_sk + count) = 0;

   free (s);
    close (fdsk);

    /* do not scrub the key buffer under normal circumstances
       (it's up to the caller) */ 

    if (status == -1) {
      printf ("%s: trouble writing symmetric key to file %s\n", 
          getprogname (), skfname);
      perror (getprogname ());

    /* scrub the buffer that's holding the key before exiting */

       /* scrub the buffer that's holding the key before exiting MY CODE
    for (count = 0; count < size; count++)
    *((int*)raw_sk + count) = 0;*/

      exit (-1);
    }
  }
}
  • 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-31T01:34:32+00:00Added an answer on May 31, 2026 at 1:34 am

    You are incrementing the pointer by the size of an int. That is wrong. If you want to zero out the array you increment by the size of a char. Better yet, just use memset.

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

Sidebar

Related Questions

Pretty new to Java programming, but I'm having trouble getting this to run. I
I am new to iOS programming. I am getting an Incompatible integer to pointer
let's say that you in your new programming work your boss comes and says
I always believed that when starting to learn a new programming language programmer must
I've came across this new acronym, SOFEA, apparently a new programming paradigm for web
I'm pretty new to programming and am generally confused by header files and includes.
I am new to programming, so please accept my apologies if this question is
I am new to database programming, so I'd like help getting on the right
I'm new to programming with the Win32 API, and I'm still getting used to
I'm new at programming, new on this site too, so hello... I'm attempting to

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.