@@ -583,6 +583,7 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
583
583
CFAllocatorAllocateCallBack allocateFunc ;
584
584
void * newptr = NULL ;
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 );
@@ -670,6 +667,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
670
667
void CFAllocatorDeallocate (CFAllocatorRef allocator , void * ptr ) {
671
668
CFAllocatorDeallocateCallBack deallocateFunc ;
672
669
670
+ if (NULL != ptr ) {
673
671
if (NULL == allocator ) {
674
672
allocator = __CFGetDefaultAllocator ();
675
673
}
@@ -691,35 +689,38 @@ void CFAllocatorDeallocate(CFAllocatorRef allocator, void *ptr) {
691
689
}
692
690
#endif
693
691
deallocateFunc = __CFAllocatorGetDeallocateFunction (& allocator -> _context );
694
- if (NULL != ptr && NULL != deallocateFunc ) {
692
+ if (NULL != deallocateFunc ) {
695
693
INVOKE_CALLBACK2 (deallocateFunc , ptr , allocator -> _context .info );
696
694
}
695
+ }
697
696
}
698
697
699
698
CFIndex CFAllocatorGetPreferredSizeForSize (CFAllocatorRef allocator , CFIndex size , CFOptionFlags hint ) {
700
699
CFAllocatorPreferredSizeCallBack prefFunc ;
701
- CFIndex newsize = 0 ;
700
+ CFIndex newsize ;
702
701
702
+ #if !TARGET_OS_MAC
703
+ if (0 >= size ) {
704
+ return 0 ;
705
+ }
706
+ #endif
703
707
if (NULL == allocator ) {
704
708
allocator = __CFGetDefaultAllocator ();
705
709
}
706
-
707
- #if TARGET_OS_MAC
708
- if (_CFTypeGetClass (allocator ) == __CFISAForCFAllocator ()) {
709
- __CFGenericValidateType (allocator , _kCFRuntimeIDCFAllocator );
710
- }
711
- #else
712
- __CFGenericValidateType (allocator , _kCFRuntimeIDCFAllocator );
713
- #endif
714
710
#if TARGET_OS_MAC
715
711
if (_CFTypeGetClass (allocator ) != __CFISAForCFAllocator ()) { // malloc_zone_t *
716
712
return malloc_good_size (size );
717
713
}
714
+ if (0 >= size ) {
715
+ return 0 ;
716
+ }
718
717
#endif
718
+ __CFGenericValidateType (allocator , _kCFRuntimeIDCFAllocator );
719
719
prefFunc = __CFAllocatorGetPreferredSizeFunction (& allocator -> _context );
720
- if (0 < size && NULL ! = prefFunc ) {
721
- newsize = ( CFIndex )( INVOKE_CALLBACK3 ( prefFunc , size , hint , allocator -> _context . info )) ;
720
+ if (NULL = = prefFunc ) {
721
+ return size ;
722
722
}
723
+ newsize = (CFIndex )(INVOKE_CALLBACK3 (prefFunc , size , hint , allocator -> _context .info ));
723
724
if (newsize < size ) newsize = size ;
724
725
return newsize ;
725
726
}
0 commit comments