Browse Source

Fix #229 by returning zero instead of -1.

pull/230/head
EinMByte 9 years ago
parent
commit
c612d21639
  1. 2
      base64.cpp
  2. 4
      base64.h

2
base64.cpp

@ -133,7 +133,7 @@ namespace data
while ( *ps-- == P64 ) outCount--; while ( *ps-- == P64 ) outCount--;
ps = (unsigned char *)InBuffer; ps = (unsigned char *)InBuffer;
if (outCount > len) return -1; if (outCount > len) return 0;
pd = OutBuffer; pd = OutBuffer;
auto endOfOutBuffer = OutBuffer + outCount; auto endOfOutBuffer = OutBuffer + outCount;
for ( i = 0; i < n; i++ ){ for ( i = 0; i < n; i++ ){

4
base64.h

@ -17,6 +17,7 @@ namespace data
* @param InCount length of the input array * @param InCount length of the input array
* @param OutBuffer array to store output characters * @param OutBuffer array to store output characters
* @param len length of the output buffer * @param len length of the output buffer
* @note zero is returned when the output buffer is too small
*/ */
size_t ByteStreamToBase64 (const uint8_t * InBuffer, size_t InCount, char * OutBuffer, size_t len); size_t ByteStreamToBase64 (const uint8_t * InBuffer, size_t InCount, char * OutBuffer, size_t len);
@ -28,6 +29,7 @@ namespace data
* @param OutBuffer array to store output bytes * @param OutBuffer array to store output bytes
* @param len length of the output buffer * @param len length of the output buffer
* @todo Do not return a negative value on failure, size_t could be unsigned. * @todo Do not return a negative value on failure, size_t could be unsigned.
* @note zero is returned when the output buffer is too small
*/ */
size_t Base64ToByteStream (const char * InBuffer, size_t InCount, uint8_t * OutBuffer, size_t len ); size_t Base64ToByteStream (const char * InBuffer, size_t InCount, uint8_t * OutBuffer, size_t len );
@ -40,6 +42,7 @@ namespace data
* @param len length of the input buffer * @param len length of the input buffer
* @param outBuf array to store output bytes * @param outBuf array to store output bytes
* @param outLen length of the output array * @param outLen length of the output array
* @note zero is returned when the output buffer is too small
*/ */
size_t Base32ToByteStream (const char * inBuf, size_t len, uint8_t * outBuf, size_t outLen); size_t Base32ToByteStream (const char * inBuf, size_t len, uint8_t * outBuf, size_t outLen);
@ -50,6 +53,7 @@ namespace data
* @param len length of the input buffer * @param len length of the input buffer
* @param outBuf array to store output characters * @param outBuf array to store output characters
* @param outLen length of the output array * @param outLen length of the output array
* @note zero is returned when the output buffer is too small
*/ */
size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen); size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen);
} }

Loading…
Cancel
Save