Blame src/regression/malloc-0.c
|
Szabolcs Nagy |
cfa23c |
// commit: 26031da0f83a2a3ed52190077931ee6c18dfd689 2011-02-20
|
|
Szabolcs Nagy |
cfa23c |
// malloc(0) should return unique pointers
|
|
Szabolcs Nagy |
2a160f |
// (often expected and gnulib replaces malloc if malloc(0) returns 0)
|
|
Szabolcs Nagy |
cfa23c |
#include <stdlib.h>
|
|
Szabolcs Nagy |
cfa23c |
#include "test.h"
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
int main(void)
|
|
Szabolcs Nagy |
cfa23c |
{
|
|
Szabolcs Nagy |
cfa23c |
void *p = malloc(0);
|
|
Szabolcs Nagy |
cfa23c |
void *q = malloc(0);
|
|
Szabolcs Nagy |
cfa23c |
void *r = malloc(0);
|
|
Szabolcs Nagy |
cfa23c |
if (!p || !q || !r)
|
|
Szabolcs Nagy |
cfa23c |
t_error("malloc(0) returned NULL\n");
|
|
Szabolcs Nagy |
cfa23c |
if (p == q || p == r || q == r)
|
|
Szabolcs Nagy |
cfa23c |
t_error("malloc(0) returned non-unique pointers: %p, %p, %p\n", p, q, r);
|
|
Szabolcs Nagy |
cfa23c |
free(q);
|
|
Szabolcs Nagy |
cfa23c |
free(p);
|
|
Szabolcs Nagy |
cfa23c |
free(r);
|
|
Szabolcs Nagy |
cfa23c |
return t_status;
|
|
Szabolcs Nagy |
cfa23c |
}
|