Browse code

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

Daniel-Constantin Mierla authored on 02/12/2013 19:42:12
Showing 2 changed files
... ...
@@ -361,6 +361,8 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
361 361
 	MDBG("fm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
362 362
 			line);
363 363
 #endif
364
+	/*malloc(0) should return a valid pointer according to specs*/
365
+	if(unlikely(size==0)) size=4;
364 366
 	/*size must be a multiple of 8*/
365 367
 	size=ROUNDUP(size);
366 368
 /*	if (size>(qm->size-qm->real_used)) return 0; */
... ...
@@ -368,6 +368,8 @@ void* qm_malloc(struct qm_block* qm, unsigned long size)
368 368
 	MDBG("qm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
369 369
 			line);
370 370
 #endif
371
+	/*malloc(0) should return a valid pointer according to specs*/
372
+	if(unlikely(size==0)) size=4;
371 373
 	/*size must be a multiple of 8*/
372 374
 	size=ROUNDUP(size);
373 375
 	if (size>(qm->size-qm->real_used)) return 0;