version 1.3, 2015/04/20 18:19:49
|
version 1.4, 2015/09/25 20:24:20
|
|
|
#include "types.h" | #include "types.h" |
#include <pal/strings.h> | #include <pal/strings.h> |
#include "alloc.h" | #include "alloc.h" |
|
#include <pal/intsafe.h> |
#include <pal/format.h> | #include <pal/format.h> |
#include "class.h" | #include "class.h" |
#include "base64.h" | #include "base64.h" |
|
|
| |
if( *str == NULL ) // This is the first time we are called | if( *str == NULL ) // This is the first time we are called |
{ | { |
|
size_t allocSize = 0; |
|
if (SizeTAdd(size, 4, &allocSize) == S_OK && |
|
SizeTMult(allocSize, sizeof(unsigned char), &allocSize) == S_OK) |
|
{ |
// prepend length in 4 bytes | // prepend length in 4 bytes |
*str = (char*)PAL_Malloc((size + 4) * sizeof(unsigned char)); |
*str = (char*)PAL_Malloc(allocSize); |
|
} |
|
else |
|
{ |
|
// Overflow |
|
return -1; |
|
} |
| |
if (!*str) | if (!*str) |
return -1; | return -1; |
|
|
totalSize = p1 + p2 + p3 + p4; | totalSize = p1 + p2 + p3 + p4; |
skipSize = totalSize; | skipSize = totalSize; |
totalSize += size; | totalSize += size; |
newStr = (char*)PAL_Malloc(totalSize * sizeof(unsigned char)); |
size_t allocSize = 0; |
|
if (SizeTMult(totalSize, sizeof(unsigned char), &allocSize) == S_OK) |
|
{ |
|
newStr = (char*)PAL_Malloc(allocSize); |
|
} |
|
|
if (!newStr) | if (!newStr) |
{ | { |
PAL_Free(arr->data); | PAL_Free(arr->data); |