Ver a proveniência

WARNING: REDESIGNED: `EncodeDataBase64()`, NULL terminated string returned

Note that returned output size considers the NULL terminator as an additional byte.
master
Ray há 2 dias
ascendente
cometimento
afb52b19a4
2 ficheiros alterados com 5 adições e 2 eliminações
  1. +1
    -1
      src/raylib.h
  2. +4
    -1
      src/rcore.c

+ 1
- 1
src/raylib.h Ver ficheiro

@ -1153,7 +1153,7 @@ RLAPI long GetFileModTime(const char *fileName); // Get file mo
// Compression/Encoding functionality // Compression/Encoding functionality
RLAPI unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize); // Compress data (DEFLATE algorithm), memory must be MemFree() RLAPI unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize); // Compress data (DEFLATE algorithm), memory must be MemFree()
RLAPI unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize); // Decompress data (DEFLATE algorithm), memory must be MemFree() RLAPI unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize); // Decompress data (DEFLATE algorithm), memory must be MemFree()
RLAPI char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize); // Encode data to Base64 string, memory must be MemFree()
RLAPI char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize); // Encode data to Base64 string (includes NULL terminator), memory must be MemFree()
RLAPI unsigned char *DecodeDataBase64(const char *data, int *outputSize); // Decode Base64 string data, memory must be MemFree() RLAPI unsigned char *DecodeDataBase64(const char *data, int *outputSize); // Decode Base64 string data, memory must be MemFree()
RLAPI unsigned int ComputeCRC32(unsigned char *data, int dataSize); // Compute CRC32 hash code RLAPI unsigned int ComputeCRC32(unsigned char *data, int dataSize); // Compute CRC32 hash code
RLAPI unsigned int *ComputeMD5(unsigned char *data, int dataSize); // Compute MD5 hash code, returns static int[4] (16 bytes) RLAPI unsigned int *ComputeMD5(unsigned char *data, int dataSize); // Compute MD5 hash code, returns static int[4] (16 bytes)

+ 4
- 1
src/rcore.c Ver ficheiro

@ -2539,6 +2539,7 @@ unsigned char *DecompressData(const unsigned char *compData, int compDataSize, i
} }
// Encode data to Base64 string // Encode data to Base64 string
// NOTE: Returned string includes NULL terminator, considered on outputSize
char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize) char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize)
{ {
static const unsigned char base64encodeTable[] = { static const unsigned char base64encodeTable[] = {
@ -2549,7 +2550,7 @@ char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize)
static const int modTable[] = { 0, 2, 1 }; static const int modTable[] = { 0, 2, 1 };
*outputSize = 4*((dataSize + 2)/3);
*outputSize = 4*((dataSize + 2)/3) + 1; // Adding +1 for NULL terminator
char *encodedData = (char *)RL_MALLOC(*outputSize); char *encodedData = (char *)RL_MALLOC(*outputSize);
@ -2571,6 +2572,8 @@ char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize)
for (int i = 0; i < modTable[dataSize%3]; i++) encodedData[*outputSize - 1 - i] = '='; // Padding character for (int i = 0; i < modTable[dataSize%3]; i++) encodedData[*outputSize - 1 - i] = '='; // Padding character
encodedData[*outputSize - 1] = '\0';
return encodedData; return encodedData;
} }

Carregando…
Cancelar
Guardar