Skip to content

Commit 3f6be5e

Browse files
LaborEtArsdevyte
authored andcommitted
Adjusted buffer size algorithm (#4934)
Use cencode.h defined macros to calculate the needed buffer size.
1 parent 63ab79e commit 3f6be5e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cores/esp8266/base64.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ extern "C" {
3636
* @return String
3737
*/
3838
String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
39-
// base64 needs more size then the source data
40-
size_t size = ((length * 1.6f) + 1);
39+
// base64 needs more size then the source data, use cencode.h macros
40+
size_t size = ((doNewLines ? base64_encode_expected_len(length)
41+
: base64_encode_expected_len_nonewlines(length)) + 1);
4142
char * buffer = (char *) malloc(size);
4243
if(buffer) {
4344
base64_encodestate _state;

0 commit comments

Comments
 (0)