-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Harren
committed
Feb 22, 2004
1 parent
7082f52
commit 17e8e85
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
// What happens if malloc returns null? | ||
|
||
#include "testharness.h" | ||
#include <malloc.h> | ||
#include <sys/resource.h> | ||
#include <unistd.h> | ||
|
||
struct list { | ||
struct list* next; | ||
int data[1024*10]; | ||
}; | ||
|
||
int main() { | ||
struct list* p = 0; | ||
|
||
// This test tries to run out of memory. To avoid annoying other users, | ||
// put a 10MB limit on the memory that is allocated to this test. | ||
const int heapSize = 1024*1024*10; | ||
struct rlimit limit = {heapSize, heapSize}; | ||
int res = setrlimit(RLIMIT_DATA, &limit); | ||
if (res != 0){ | ||
printf("***setrlimit didn't work"); | ||
} | ||
|
||
while(1) { | ||
//Eventually, malloc returns null. Hopefully, CCured won't try to | ||
//dereference it. | ||
struct list* newp = malloc(sizeof(struct list)); | ||
if (! newp) { break; } | ||
newp->next = p; | ||
p = newp; | ||
} | ||
SUCCESS; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters