Skip to content

fix base64_encode_expected_len #4786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cores/esp8266/libb64/cencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ For details, see http://sourceforge.net/projects/libb64

#include "cencode.h"

const int CHARS_PER_LINE = 72;

void base64_init_encodestate(base64_encodestate* state_in){
state_in->step = step_A;
state_in->result = 0;
state_in->stepcount = 0;
state_in->stepsnewline = CHARS_PER_LINE;
state_in->stepsnewline = BASE64_CHARS_PER_LINE;
}


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

++(state_in->stepcount);
if ((state_in->stepcount == CHARS_PER_LINE/4) && (state_in->stepsnewline > 0)){
if ((state_in->stepcount == BASE64_CHARS_PER_LINE/4) && (state_in->stepsnewline > 0)){
*codechar++ = '\n';
state_in->stepcount = 0;
}
Expand Down
7 changes: 6 additions & 1 deletion cores/esp8266/libb64/cencode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ For details, see http://sourceforge.net/projects/libb64
#ifndef BASE64_CENCODE_H
#define BASE64_CENCODE_H

#define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3)
#define BASE64_CHARS_PER_LINE 72

#define base64_encode_expected_len_nonewlines(n) ((((4 * (n)) / 3) + 3) & ~3)
#define base64_encode_expected_len(n) \
(base64_encode_expected_len_nonewlines(n) + ((n / ((BASE64_CHARS_PER_LINE * 3) / 4)) + 1))


#ifdef __cplusplus
extern "C" {
Expand Down