Skip to content

Commit 73d36bb

Browse files
authored
fix base64_encode_expected_len (#4786)
1 parent 8cda965 commit 73d36bb

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cores/esp8266/libb64/cencode.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ For details, see http://sourceforge.net/projects/libb64
77

88
#include "cencode.h"
99

10-
const int CHARS_PER_LINE = 72;
11-
1210
void base64_init_encodestate(base64_encodestate* state_in){
1311
state_in->step = step_A;
1412
state_in->result = 0;
1513
state_in->stepcount = 0;
16-
state_in->stepsnewline = CHARS_PER_LINE;
14+
state_in->stepsnewline = BASE64_CHARS_PER_LINE;
1715
}
1816

1917

@@ -72,7 +70,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
7270
*codechar++ = base64_encode_value(result);
7371

7472
++(state_in->stepcount);
75-
if ((state_in->stepcount == CHARS_PER_LINE/4) && (state_in->stepsnewline > 0)){
73+
if ((state_in->stepcount == BASE64_CHARS_PER_LINE/4) && (state_in->stepsnewline > 0)){
7674
*codechar++ = '\n';
7775
state_in->stepcount = 0;
7876
}

cores/esp8266/libb64/cencode.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ For details, see http://sourceforge.net/projects/libb64
88
#ifndef BASE64_CENCODE_H
99
#define BASE64_CENCODE_H
1010

11-
#define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3)
11+
#define BASE64_CHARS_PER_LINE 72
12+
13+
#define base64_encode_expected_len_nonewlines(n) ((((4 * (n)) / 3) + 3) & ~3)
14+
#define base64_encode_expected_len(n) \
15+
(base64_encode_expected_len_nonewlines(n) + ((n / ((BASE64_CHARS_PER_LINE * 3) / 4)) + 1))
16+
1217

1318
#ifdef __cplusplus
1419
extern "C" {

0 commit comments

Comments
 (0)