Browse Source

cmGlobal.h,cmLinkedHeap.h,cmMallocDebug.h: Fixed bug w/ NULL src ptrs to cmMemAllocStr()

master
kevin 11 years ago
parent
commit
3e3b1e2aa9
3 changed files with 39 additions and 36 deletions
  1. 1
    0
      cmGlobal.h
  2. 8
    8
      cmLinkedHeap.h
  3. 30
    28
      cmMallocDebug.h

+ 1
- 0
cmGlobal.h View File

@@ -99,6 +99,7 @@ extern "C" {
99 99
 
100 100
 
101 101
 #define cmStringNullGuard(p) ((p)==NULL?"<null>":(p)) //< If 'p'==NULL return the static string "<null>" otherwise return 'p'.
102
+#define cmStringLen(s)       ((s)==NULL? 0 : strlen(s))
102 103
 
103 104
   // Default return code indicating successful function completion.
104 105
 #define cmOkRC (0)                  

+ 8
- 8
cmLinkedHeap.h View File

@@ -52,10 +52,10 @@ extern "C" {
52 52
 #define cmLhResizeN( h,t,p,n) ((t*)cmLHeapAllocate(h,p,   n,sizeof(t), kAlignMmFl,              NULL,NULL,0))
53 53
 #define cmLhResizeNZ(h,t,p,n) ((t*)cmLHeapAllocate(h,p,   n,sizeof(t), kAlignMmFl  | kZeroMmFl, NULL,NULL,0))
54 54
 
55
-#define cmLhAllocStr(   h, str )       cmLHeapAllocStr( h, NULL, str, strlen(str), kAlignMmFl, NULL,NULL,0 )
56
-#define cmLhAllocStrN(  h, str, n )    cmLHeapAllocStr( h, NULL, str, n,           kAlignMmFl, NULL,NULL,0 )
57
-#define cmLhResizeStr(  h, p, str )    cmLHeapAllocStr( h, p,    str, strlen(str), kAlignMmFl, NULL,NULL,0 )
58
-#define cmLhResizeStrN( h, p, str, n ) cmLHeapAllocStr( h, p,    str, n,           kAlignMmFl, NULL,NULL,0 )
55
+#define cmLhAllocStr(   h, str )       cmLHeapAllocStr( h, NULL, str, cmStringLen(str), kAlignMmFl, NULL,NULL,0 )
56
+#define cmLhAllocStrN(  h, str, n )    cmLHeapAllocStr( h, NULL, str, n,                kAlignMmFl, NULL,NULL,0 )
57
+#define cmLhResizeStr(  h, p, str )    cmLHeapAllocStr( h, p,    str, cmStringLen(str), kAlignMmFl, NULL,NULL,0 )
58
+#define cmLhResizeStrN( h, p, str, n ) cmLHeapAllocStr( h, p,    str, n,                kAlignMmFl, NULL,NULL,0 )
59 59
 
60 60
 #define cmLhFree( h, p )           cmLHeapFree( h, p )
61 61
 #define cmLhFreePtr(h, p )         cmLHeapFreePtr( h, p ) 
@@ -70,10 +70,10 @@ extern "C" {
70 70
 #define cmLhResizeN( h,t,p,n) ((t*)cmLHeapAllocate(h,p,   n,sizeof(t), kAlignMmFl,              __FILE__,__FUNCTION__,__LINE__))
71 71
 #define cmLhResizeNZ(h,t,p,n) ((t*)cmLHeapAllocate(h,p,   n,sizeof(t), kAlignMmFl  | kZeroMmFl, __FILE__,__FUNCTION__,__LINE__))
72 72
 
73
-#define cmLhAllocStr(  h, str )        cmLHeapAllocStr( h, NULL, str, strlen(str),    kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
74
-#define cmLhAllocStrN( h, str, n )     cmLHeapAllocStr( h, NULL, str, n,              kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
75
-#define cmLhResizeStr( h, p, str )     cmLHeapAllocStr( h, p,    str, strlen(str),    kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
76
-#define cmLhResizeStrN( h, p, str, n ) cmLHeapAllocStr( h, p,    str, n,              kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
73
+#define cmLhAllocStr(  h, str )        cmLHeapAllocStr( h, NULL, str, cmStringLen(str),  kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
74
+#define cmLhAllocStrN( h, str, n )     cmLHeapAllocStr( h, NULL, str, n,                 kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
75
+#define cmLhResizeStr( h, p, str )     cmLHeapAllocStr( h, p,    str, cmStringLen(str),  kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
76
+#define cmLhResizeStrN( h, p, str, n ) cmLHeapAllocStr( h, p,    str, n,                 kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
77 77
 
78 78
 #define cmLhFree( h, p )           cmLHeapFreeDebug(    h, p, __FILE__,__FUNCTION__,__LINE__ )
79 79
 #define cmLhFreePtr(h, p )         cmLHeapFreePtrDebug( h, p, __FILE__,__FUNCTION__,__LINE__ ) 

+ 30
- 28
cmMallocDebug.h View File

@@ -93,6 +93,8 @@ extern "C" {
93 93
   // An example and test function for the cmMallocDebug manager.
94 94
   void     cmMdTest( cmRpt_t* rpt );
95 95
 
96
+
97
+
96 98
 #if cmDEBUG_FL == 0
97 99
 
98 100
   // Memory Allocation and Release Macros:
@@ -101,20 +103,20 @@ extern "C" {
101 103
   //
102 104
 
103 105
 #define cmMemAllocate( type, p, eleCnt, fl ) ((type*)cmMdAllocate( p, eleCnt, sizeof(type), fl )) 
104
-#define cmMemMalloc(   byteCnt )                 cmMdAllocate( NULL, byteCnt,           1, kAlignMmFl) 
105
-#define cmMemMallocZ(  byteCnt )                 cmMdAllocate( NULL, byteCnt,           1, kAlignMmFl | kZeroMmFl) 
106
-#define cmMemAlloc(    type, eleCnt )    ((type*)cmMdAllocate( NULL, eleCnt, sizeof(type), kAlignMmFl))
107
-#define cmMemAllocZ(   type, eleCnt )    ((type*)cmMdAllocate( NULL, eleCnt, sizeof(type), kAlignMmFl | kZeroMmFl))
108
-#define cmMemAllocStr(  str )                    cmMdAllocStr( NULL, str,    strlen(str),  kAlignMmFl )
109
-#define cmMemAllocStrN( str, charCnt )           cmMdAllocStr( NULL, str,    charCnt,      kAlignMmFl )
110
-#define cmMemResizeStr( p, str )                 cmMdAllocStr( p,    str,    strlen(str),  kAlignMmFl )
111
-#define cmMemResizeStrN(p, str, charCnt )       cmMdAllocStr( p,    str,    charCnt,      kAlignMmFl )
112
-#define cmMemResizeN(   n, p, eleCnt )          (cmMdAllocate( p,    eleCnt, n,            kAlignMmFl))
113
-#define cmMemResizeNZ(  n, p, eleCnt )          (cmMdAllocate( p,    eleCnt, n,            kAlignMmFl | kZeroMmFl ))
114
-#define cmMemResize(   type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type), kAlignMmFl))
115
-#define cmMemResizeZ(  type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type), kAlignMmFl | kZeroMmFl))
116
-#define cmMemResizeP(  type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type), kAlignMmFl | kPreserveMmFl))
117
-#define cmMemResizePZ( type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type), kAlignMmFl | kZeroMmFl | kPreserveMmFl))
106
+#define cmMemMalloc(   byteCnt )                 cmMdAllocate( NULL, byteCnt,           1,     kAlignMmFl) 
107
+#define cmMemMallocZ(  byteCnt )                 cmMdAllocate( NULL, byteCnt,           1,     kAlignMmFl | kZeroMmFl) 
108
+#define cmMemAlloc(    type, eleCnt )    ((type*)cmMdAllocate( NULL, eleCnt, sizeof(type),     kAlignMmFl))
109
+#define cmMemAllocZ(   type, eleCnt )    ((type*)cmMdAllocate( NULL, eleCnt, sizeof(type),     kAlignMmFl | kZeroMmFl))
110
+#define cmMemAllocStr(  str )                    cmMdAllocStr( NULL, str,    cmStringLen(str), kAlignMmFl )
111
+#define cmMemAllocStrN( str, charCnt )           cmMdAllocStr( NULL, str,    charCnt,          kAlignMmFl )
112
+#define cmMemResizeStr( p, str )                 cmMdAllocStr( p,    str,    cmStringLen(str), kAlignMmFl )
113
+#define cmMemResizeStrN(p, str, charCnt )       cmMdAllocStr( p,    str,    charCnt,           kAlignMmFl )
114
+#define cmMemResizeN(   n, p, eleCnt )          (cmMdAllocate( p,    eleCnt, n,                kAlignMmFl))
115
+#define cmMemResizeNZ(  n, p, eleCnt )          (cmMdAllocate( p,    eleCnt, n,                kAlignMmFl | kZeroMmFl ))
116
+#define cmMemResize(   type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type),     kAlignMmFl))
117
+#define cmMemResizeZ(  type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type),     kAlignMmFl | kZeroMmFl))
118
+#define cmMemResizeP(  type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type),     kAlignMmFl | kPreserveMmFl))
119
+#define cmMemResizePZ( type, p, eleCnt ) ((type*)cmMdAllocate( p,    eleCnt, sizeof(type),     kAlignMmFl | kZeroMmFl | kPreserveMmFl))
118 120
 #define cmMemFree(     ptr )                     cmMdFree( ptr )
119 121
 #define cmMemPtrFree(  ptrPtr )                  cmMdFreePtr(ptrPtr);
120 122
 
@@ -130,20 +132,20 @@ extern "C" {
130 132
   //
131 133
   //
132 134
 #define cmMemAllocate( type, p, eleCnt, pre, fl ) ((type*)cmMdAllocateDebug( p, eleCnt, sizeof(type), fl, __FUNCTION__, __FILE__, __LINE__ ))
133
-#define cmMemMalloc(   byteCnt )                 cmMdAllocateDebug( NULL, 1,      byteCnt,      kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ )
134
-#define cmMemMallocZ(  byteCnt )                 cmMdAllocateDebug( NULL, 1,      byteCnt,      kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ )
135
-#define cmMemAlloc(    type, eleCnt )    ((type*)cmMdAllocateDebug( NULL, eleCnt, sizeof(type), kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
136
-#define cmMemAllocZ(   type, eleCnt )    ((type*)cmMdAllocateDebug( NULL, eleCnt, sizeof(type), kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ ))
137
-#define cmMemAllocStr( str )                    (cmMdAllocStrDebug( NULL, str,    strlen(str),  kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
138
-#define cmMemAllocStrN(str, charCnt )           (cmMdAllocStrDebug( NULL, str,    charCnt,      kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
139
-#define cmMemResizeStr(p, str )                 (cmMdAllocStrDebug( p,    str,    strlen(str),  kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
140
-#define cmMemResizeStrN(p, str, charCnt )        (cmMdAllocStrDebug( p,    str,    charCnt,      kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
141
-#define cmMemResizeN(  n,    p, eleCnt )        (cmMdAllocateDebug( p,    eleCnt, n,            kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ ))
142
-#define cmMemResizeNZ( n,    p, eleCnt )        (cmMdAllocateDebug( p,    eleCnt, n,                         kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ ))      
143
-#define cmMemResize(   type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type), kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ )) 
144
-#define cmMemResizeZ(  type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type), kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ ))
145
-#define cmMemResizeP(  type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type), kAlignMmFl | kPreserveMmFl,             __FUNCTION__, __FILE__, __LINE__ )) 
146
-#define cmMemResizePZ( type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type), kAlignMmFl | kZeroMmFl | kPreserveMmFl, __FUNCTION__, __FILE__, __LINE__ ))
135
+#define cmMemMalloc(   byteCnt )                 cmMdAllocateDebug( NULL, 1,      byteCnt,          kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ )
136
+#define cmMemMallocZ(  byteCnt )                 cmMdAllocateDebug( NULL, 1,      byteCnt,          kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ )
137
+#define cmMemAlloc(    type, eleCnt )    ((type*)cmMdAllocateDebug( NULL, eleCnt, sizeof(type),     kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
138
+#define cmMemAllocZ(   type, eleCnt )    ((type*)cmMdAllocateDebug( NULL, eleCnt, sizeof(type),     kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ ))
139
+#define cmMemAllocStr( str )                    (cmMdAllocStrDebug( NULL, str,    cmStringLen(str), kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
140
+#define cmMemAllocStrN(str, charCnt )           (cmMdAllocStrDebug( NULL, str,    charCnt,          kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
141
+#define cmMemResizeStr(p, str )                 (cmMdAllocStrDebug( p,    str,    cmStringLen(str), kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
142
+#define cmMemResizeStrN(p, str, charCnt )       (cmMdAllocStrDebug( p,    str,    charCnt,          kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ ))
143
+#define cmMemResizeN(  n,    p, eleCnt )        (cmMdAllocateDebug( p,    eleCnt, n,                kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ ))
144
+#define cmMemResizeNZ( n,    p, eleCnt )        (cmMdAllocateDebug( p,    eleCnt, n,                kZeroMmFl,              __FUNCTION__, __FILE__, __LINE__ ))      
145
+#define cmMemResize(   type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type),     kAlignMmFl,             __FUNCTION__, __FILE__, __LINE__ )) 
146
+#define cmMemResizeZ(  type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type),     kAlignMmFl | kZeroMmFl, __FUNCTION__, __FILE__, __LINE__ ))
147
+#define cmMemResizeP(  type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type),     kAlignMmFl | kPreserveMmFl,             __FUNCTION__, __FILE__, __LINE__ )) 
148
+#define cmMemResizePZ( type, p, eleCnt ) ((type*)cmMdAllocateDebug( p,    eleCnt, sizeof(type),     kAlignMmFl | kZeroMmFl | kPreserveMmFl, __FUNCTION__, __FILE__, __LINE__ ))
147 149
 #define cmMemFree(     ptr )                     cmMdFreeDebug( ptr,                                                                  __FUNCTION__, __FILE__, __LINE__ )
148 150
 #define cmMemPtrFree(  ptrPtr )                  cmMdFreePtrDebug( (void**)ptrPtr,                                                    __FUNCTION__, __FILE__, __LINE__ )
149 151
 

Loading…
Cancel
Save