Browse Source

mem: malloc(0) should return a valid pointer for free according to specs

Daniel-Constantin Mierla 11 years ago
parent
commit
f61ff34aac
2 changed files with 4 additions and 0 deletions
  1. 2 0
      mem/f_malloc.c
  2. 2 0
      mem/q_malloc.c

+ 2 - 0
mem/f_malloc.c

@@ -361,6 +361,8 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
 	MDBG("fm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
 			line);
 #endif
+	/*malloc(0) should return a valid pointer according to specs*/
+	if(unlikely(size==0)) size=4;
 	/*size must be a multiple of 8*/
 	size=ROUNDUP(size);
 /*	if (size>(qm->size-qm->real_used)) return 0; */

+ 2 - 0
mem/q_malloc.c

@@ -368,6 +368,8 @@ void* qm_malloc(struct qm_block* qm, unsigned long size)
 	MDBG("qm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
 			line);
 #endif
+	/*malloc(0) should return a valid pointer according to specs*/
+	if(unlikely(size==0)) size=4;
 	/*size must be a multiple of 8*/
 	size=ROUNDUP(size);
 	if (size>(qm->size-qm->real_used)) return 0;