@@ -581,8 +581,9 @@ CFAllocatorRef CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorContext *c
581
581
582
582
void * CFAllocatorAllocate (CFAllocatorRef allocator , CFIndex size , CFOptionFlags hint ) {
583
583
CFAllocatorAllocateCallBack allocateFunc ;
584
- void * newptr = NULL ;
584
+ void * newptr ;
585
585
586
+ if (0 < size ) {
586
587
if (NULL == allocator ) {
587
588
allocator = __CFGetDefaultAllocator ();
588
589
}
@@ -594,16 +595,14 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
594
595
#else
595
596
__CFGenericValidateType (allocator , _kCFRuntimeIDCFAllocator );
596
597
#endif
597
- if (0 == size ) return NULL ;
598
598
#if TARGET_OS_MAC
599
599
if (_CFTypeGetClass (allocator ) != __CFISAForCFAllocator ()) { // malloc_zone_t *
600
600
return malloc_zone_malloc ((malloc_zone_t * )allocator , size );
601
601
}
602
602
#endif
603
- newptr = NULL ;
604
603
allocateFunc = __CFAllocatorGetAllocateFunction (& allocator -> _context );
605
- if (allocateFunc ) {
606
- newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , size , hint , allocator -> _context .info );
604
+ if (NULL == allocateFunc ) return NULL ;
605
+ newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , size , hint , allocator -> _context .info );
607
606
}
608
607
return newptr ;
609
608
}
@@ -631,14 +630,12 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
631
630
return malloc_zone_malloc ((malloc_zone_t * )allocator , newsize );
632
631
}
633
632
#endif
634
- newptr = NULL ;
635
633
allocateFunc = __CFAllocatorGetAllocateFunction (& allocator -> _context );
636
- if (allocateFunc ) {
637
- newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , newsize , hint , allocator -> _context .info );
638
- }
634
+ if (NULL == allocateFunc ) return NULL ;
635
+ newptr = (void * )INVOKE_CALLBACK3 (allocateFunc , newsize , hint , allocator -> _context .info );
639
636
return newptr ;
640
637
}
641
- if (NULL != ptr && 0 = = newsize ) {
638
+ if (NULL != ptr && 0 > = newsize ) {
642
639
#if TARGET_OS_MAC
643
640
if (_CFTypeGetClass (allocator ) != __CFISAForCFAllocator ()) { // malloc_zone_t *
644
641
#if defined(DEBUG )
@@ -655,7 +652,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
655
652
}
656
653
return NULL ;
657
654
}
658
- if (NULL == ptr && 0 = = newsize ) return NULL ;
655
+ if (NULL == ptr && 0 > = newsize ) return NULL ;
659
656
#if TARGET_OS_MAC
660
657
if (_CFTypeGetClass (allocator ) != __CFISAForCFAllocator ()) { // malloc_zone_t *
661
658
return malloc_zone_realloc ((malloc_zone_t * )allocator , ptr , newsize );
@@ -700,6 +697,7 @@ CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex siz
700
697
CFAllocatorPreferredSizeCallBack prefFunc ;
701
698
CFIndex newsize = 0 ;
702
699
700
+ if (0 < size ) {
703
701
if (NULL == allocator ) {
704
702
allocator = __CFGetDefaultAllocator ();
705
703
}
@@ -717,10 +715,11 @@ CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex siz
717
715
}
718
716
#endif
719
717
prefFunc = __CFAllocatorGetPreferredSizeFunction (& allocator -> _context );
720
- if (0 < size && NULL != prefFunc ) {
718
+ if (NULL != prefFunc ) {
721
719
newsize = (CFIndex )(INVOKE_CALLBACK3 (prefFunc , size , hint , allocator -> _context .info ));
722
720
}
723
721
if (newsize < size ) newsize = size ;
722
+ }
724
723
return newsize ;
725
724
}
726
725
0 commit comments