From 3f6be5ecc8a57f8621e8f2ebf5f2b4dc20ec11b1 Mon Sep 17 00:00:00 2001 From: LaborEtArs Date: Fri, 20 Jul 2018 00:16:51 +0200 Subject: [PATCH] Adjusted buffer size algorithm (#4934) 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 a1e626189..3ae51f5a0 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;