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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:54:57+00:00 2026-06-15T07:54:57+00:00

I am allocating enough memory for two pointers which I treat as arrays: //

  • 0

I am allocating enough memory for two pointers which I treat as arrays:

// Allocate memory for both adj and deg
int *adjdeg = malloc(sizeof(int)*n*n);

adj = adjdeg;
deg = adjdeg + n*n - n;

I am then using GNU’s bzero from string.h to initialize the values in the deg “array” to 0 (the adj “array” doesn’t need to be initialized to it since I write to it before I ever read from it). This works fine, and my program runs successfully, but valgrind reports many errors about use of initialized values whenever I read from deg (IE. deg[0]). Here is my call to bzero:

// My bzero call
bzero(deg, n);

valgrind is happy if I remove my call to bzero and use a loop like:

int i; 
for(i = 0; i < n; i++)
    deg[i] = 0;

Is there any way to tell valgrind that bzero is initializing that area in memory correctly? I’m using gcc 4.6.3 and valgrind 3.7.0

Note: I get the same errors in valgrind if I use memset instead of bzero.

  • 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-06-15T07:54:58+00:00Added an answer on June 15, 2026 at 7:54 am

    You should be using:

    bzero(deg, n * sizeof(int));
    

    As it is, you’re initializing n bytes, not n integers. For maximal portability, you should probably use memset() instead of bzero(), but you still need the sizeof(int) multiplier in the size:

    memset(deg, '\0', n * sizeof(int));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen resources show two ways of allocating memory while ensuring that there
I am dynamically allocating a struct which has a different struct as a member:
I am allocating memory for an object and if a particular statement following the
I was trying out some stuff allocating structs, which contain non-pod members, on the
I am currently trying to allocate the same amount of memory for a double
I have a multi threaded application where I allocate buffers with data, which then
I have a problem with memory allocation using malloc. Here is a fragment from
I'm a bit confused about allocating memory for my variables. If e.g. I'm creating
I get confused why you use dynamic allocation and the concept of allocating enough
When trying to get shared memory, shmget() often fails because being unable to allocate

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.