| 3154 | // a size, and a string to use when printing error if the allocation fails. |
| 3155 | |
| 3156 | pbyte PAllocate(long cb, CONST char *szType) |
| 3157 | { |
| 3158 | char szT[cchSzDef]; |
| 3159 | pbyte pb; |
| 3160 | |
| 3161 | #ifdef DEBUG |
| 3162 | pb = (pbyte)PAllocateCore(cb + sizeof(dword)*3); |
| 3163 | #else |
| 3164 | pb = (pbyte)PAllocateCore(cb); |
| 3165 | #endif |
| 3166 | |
| 3167 | // Handle success or failure of the allocation. |
| 3168 | Assert(szType != NULL); |
| 3169 | if (pb == NULL) { |
| 3170 | sprintf(szT, "%s: Not enough memory for %s (%ld bytes).", |
| 3171 | szAppName, szType, cb); |
| 3172 | PrintWarning(szT); |
| 3173 | } else { |
| 3174 | is.cAlloc++; |
| 3175 | is.cAllocTotal++; |
| 3176 | is.cbAllocSize += cb; |
| 3177 | } |
| 3178 | |
| 3179 | #ifdef DEBUG |
| 3180 | // Put sentinels at ends of allocation to check for buffer overruns. |
| 3181 | *(dword *)pb = dwCanary; |
| 3182 | *(dword *)(pb + sizeof(dword)) = cb; |
| 3183 | *(dword *)(pb + sizeof(dword)*2 + cb) = dwCanary; |
| 3184 | return pb + sizeof(dword)*2; |
| 3185 | #else |
| 3186 | return pb; |
| 3187 | #endif |
| 3188 | } |
| 3189 | |
| 3190 | |
| 3191 | // Free a memory buffer allocated with PAllocate(). |
no test coverage detected