|
@@ -1,5 +1,4 @@
|
|
#include "Base64.h"
|
|
#include "Base64.h"
|
|
-#include <math.h>
|
|
|
|
|
|
|
|
using namespace Framework;
|
|
using namespace Framework;
|
|
|
|
|
|
@@ -63,7 +62,7 @@ bool Framework::base64Decode(Text base64, char** data, int* length)
|
|
return false;
|
|
return false;
|
|
l++;
|
|
l++;
|
|
}
|
|
}
|
|
- *length = (int)ceil(l / 4.f) * 3;
|
|
|
|
|
|
+ *length = (l * 3) / 4;
|
|
*data = new char[*length + 1];
|
|
*data = new char[*length + 1];
|
|
while (base64[k])
|
|
while (base64[k])
|
|
{
|
|
{
|
|
@@ -75,7 +74,7 @@ bool Framework::base64Decode(Text base64, char** data, int* length)
|
|
char_array_3[0] = (unsigned char)((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
|
|
char_array_3[0] = (unsigned char)((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
|
|
char_array_3[1] = (unsigned char)(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
|
|
char_array_3[1] = (unsigned char)(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
|
|
char_array_3[2] = (unsigned char)(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);
|
|
char_array_3[2] = (unsigned char)(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);
|
|
- for (i = 0; (i < 3); i++)
|
|
|
|
|
|
+ for (i = 0; (i < 3) && n < *length; i++)
|
|
(*data)[n++] = char_array_3[i];
|
|
(*data)[n++] = char_array_3[i];
|
|
i = 0;
|
|
i = 0;
|
|
}
|
|
}
|
|
@@ -90,7 +89,7 @@ bool Framework::base64Decode(Text base64, char** data, int* length)
|
|
char_array_3[0] = (unsigned char)((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
|
|
char_array_3[0] = (unsigned char)((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
|
|
char_array_3[1] = (unsigned char)(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
|
|
char_array_3[1] = (unsigned char)(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
|
|
char_array_3[2] = (unsigned char)(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);
|
|
char_array_3[2] = (unsigned char)(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);
|
|
- for (j = 0; (j < i - 1); j++)
|
|
|
|
|
|
+ for (j = 0; (j < i - 1) && n < *length; j++)
|
|
(*data)[n++] = char_array_3[j];
|
|
(*data)[n++] = char_array_3[j];
|
|
}
|
|
}
|
|
(*data)[*length] = '\0';
|
|
(*data)[*length] = '\0';
|