Home Dashboard Directory Help
Search

calloc crashes if total size > _HEAP_MAXREQ by Jonathan Jones MW


Status: 

Closed
 as Fixed Help for as Fixed


0
0
Sign in
to vote
Type: Bug
ID: 356599
Opened: 7/17/2008 12:09:37 PM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

If you call calloc, and the total size being allocated exceeds _HEAP_MAXREQ or would overflow, the program will crash immediately with the following error:

The exception unknown software exception (0xc000000d) occurred in the application ...

The expectation is that calloc simply sets errno and returns a NULL pointer. If you call malloc or realloc with a value greater than _HEAP_MAXREQ, they do set errno and return NULL, but not calloc.
Details
Sign in to post a comment.
Posted by Microsoft on 8/18/2009 at 11:12 AM
Hello,

This issue has been fixed in the CRT for Visual Studio 2010.

Pat Brenner
Visual C++ Libraries Development
Posted by Jonathan Jones MW on 8/22/2008 at 8:09 AM
I see that the issue was moved from Resolved to Closed. However, there is still no information about which versions(s) of Visual Studio contain the fix. I need to know when the fix will be available.

Thanks,
- Jon
Posted by Jonathan Jones MW on 7/30/2008 at 10:20 AM
I see that the issue was marked as Resolved (Fixed). This is great! Can someone provide details as to the resolution and in which version(s) of Visual Studio the fix is available?

Thanks,
- Jon
Posted by Jonathan Jones MW on 7/18/2008 at 8:20 AM
I found a machine with VS 2008. It still crashes for me.
Posted by PShaffer on 7/18/2008 at 7:31 AM
The code, as posted, fails the allocation under VS2008. It returns a null pointer and sets errno to 12. If you make a request for < _HEAP_MAXREQ, then the allocation succeeds.
Posted by Jonathan Jones MW on 7/18/2008 at 6:55 AM
The size must be > _HEAP_MAXREQ. If it's = _HEAP_MAXREQ, it will still work (not crash), at least in VS 2005 SP1.
Posted by Microsoft on 7/18/2008 at 2:32 AM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by PShaffer on 7/17/2008 at 5:21 PM
I don't have VS2005 SP1, just VS2008. So I can't validate the bug. I can verify it works properly under VS2008. Here's the code I used.

#include "stdafx.h"

#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>


int _tmain(int argc, _TCHAR* argv[])
{
    errno_t error;
    size_t size = _HEAP_MAXREQ;

    char *buffer;

    buffer = (char*)calloc( size, sizeof( char ) );
    _get_errno(&error);

    if ( buffer != NULL )
        printf( "buffer allocated" );
    else
        printf( "cannot allocate buffer" );

    free( buffer );

}
Sign in to post a workaround.