calloc crashes if total size > _HEAP_MAXREQ - by Jonathan Jones MW

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 356599 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 7/17/2008 12:09:37 PM
Access Restriction Public


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.
Sign in to post a comment.
Posted by Microsoft on 8/18/2009 at 11:12 AM

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.

- 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?

- 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 ) );

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

    free( buffer );