From 8190b9eea44e3c649b8bff8196596aee17540939 Mon Sep 17 00:00:00 2001 From: LaborEtArs Date: Tue, 17 Jul 2018 14:30:54 +0200 Subject: [PATCH] Adjusted buffer size algorithm Use cencode.h defined macros to calculate the needed buffer size. --- cores/esp8266/base64.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/base64.cpp b/cores/esp8266/base64.cpp index a1e6261890..3ae51f5a0f 100644 --- a/cores/esp8266/base64.cpp +++ b/cores/esp8266/base64.cpp @@ -36,8 +36,9 @@ extern "C" { * @return String */ String base64::encode(uint8_t * data, size_t length, bool doNewLines) { - // base64 needs more size then the source data - size_t size = ((length * 1.6f) + 1); + // base64 needs more size then the source data, use cencode.h macros + size_t size = ((doNewLines ? base64_encode_expected_len(length) + : base64_encode_expected_len_nonewlines(length)) + 1); char * buffer = (char *) malloc(size); if(buffer) { base64_encodestate _state;