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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:51:05+00:00 2026-05-13T10:51:05+00:00

I’ve got a function that takes a pointer to a buffer, and the size

  • 0

I’ve got a function that takes a pointer to a buffer, and the size of that buffer (via a pointer). If the buffer’s not big enough, it returns an error value and sets the required length in the out-param:

// FillBuffer is defined in another compilation unit (OBJ file).
// Whole program optimization is off.
int FillBuffer(__int_bcount_opt(*pcb) char *buffer, size_t *pcb);

I call it like this:

size_t cb = 12;
char *p = (char *)malloc(cb);
if (!p)
    return ENOMEM;

int result;
for (;;)
{
    result = FillBuffer(p, &cb);
    if (result == ENOBUFS)
    {
        char *q = (char *)realloc(p, cb);
        if (!q)
        {
            free(p);
            return ENOMEM;
        }

        p = q;
    }
    else
        break;
}

Visual C++ 2010 (with code analysis cranked to the max) complains with 'warning C6001: Using uninitialized memory 'p': Lines: ...'. It reports line numbers covering pretty much the entire function.

Visual C++ 2008 doesn’t. As far as I can tell, this code’s OK. What am I missing? Or what is VC2010 missing?

  • 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-13T10:51:06+00:00Added an answer on May 13, 2026 at 10:51 am

    This has to be a bug in Visual Studio 2010. Wrapping malloc removes the warning, as in the following tested code:

    char * mymalloc(int i)  
    {  
        return (char *) malloc(i);  
    }
    
    // ...
    
    void *r = mymalloc(cb);
    
    char *p;
    
    p = (char *) malloc(cb);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just playing around with this CSS Style span .LV_validation_message {… May 14, 2026 at 7:05 pm
  • Editorial Team
    Editorial Team added an answer I suggest that you use projection transformations with Deep Zoom… May 14, 2026 at 7:05 pm
  • Editorial Team
    Editorial Team added an answer I agree with you completely, and I do sometimes use… May 14, 2026 at 7:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.