Skip to content

Commit

Permalink
Adjusted buffer size algorithm (#4934)
Browse files Browse the repository at this point in the history
Use cencode.h defined macros to calculate the needed buffer size.
  • Loading branch information
LaborEtArs authored and devyte committed Jul 19, 2018
1 parent 63ab79e commit 3f6be5e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cores/esp8266/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3f6be5e

Please sign in to comment.