1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Adjusted buffer size algorithm (#4934)

Use cencode.h defined macros to calculate the needed buffer size.
This commit is contained in:
LaborEtArs 2018-07-20 00:16:51 +02:00 committed by Develo
parent 63ab79e549
commit 3f6be5ecc8

View File

@ -36,8 +36,9 @@ extern "C" {
* @return String * @return String
*/ */
String base64::encode(uint8_t * data, size_t length, bool doNewLines) { String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
// base64 needs more size then the source data // base64 needs more size then the source data, use cencode.h macros
size_t size = ((length * 1.6f) + 1); size_t size = ((doNewLines ? base64_encode_expected_len(length)
: base64_encode_expected_len_nonewlines(length)) + 1);
char * buffer = (char *) malloc(size); char * buffer = (char *) malloc(size);
if(buffer) { if(buffer) {
base64_encodestate _state; base64_encodestate _state;