From b61b3dd13e0a34c6fd32200d2b0a4f469d4ce501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 26 Aug 2023 15:43:18 +0800 Subject: [PATCH] fix: encode bufsz (#19) --- base16384.h | 2 +- file.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/base16384.h b/base16384.h index f4bb985..fd19063 100644 --- a/base16384.h +++ b/base16384.h @@ -43,7 +43,7 @@ typedef enum base16384_err_t base16384_err_t; #undef define_base16384_err_t -#define BASE16384_ENCBUFSZ (BUFSIZ*1024/7*7) +#define BASE16384_ENCBUFSZ (BUFSIZ*1024/7*7+7) #define BASE16384_DECBUFSZ (BUFSIZ*1024/8*8+16) // base16384_encode_len calc min buf size to fill encode result diff --git a/file.c b/file.c index 1b5c9bd..0d07623 100644 --- a/file.c +++ b/file.c @@ -62,7 +62,7 @@ base16384_err_t base16384_encode_file(const char* input, const char* output, cha return base16384_err_fopen_output_file; } if(!inputsize || inputsize > BASE16384_ENCBUFSZ) { // stdin or big file, use encbuf & fread - inputsize = BASE16384_ENCBUFSZ/8*8; + inputsize = BASE16384_ENCBUFSZ-7; #if defined _WIN32 || defined __cosmopolitan } #endif @@ -113,7 +113,7 @@ base16384_err_t base16384_encode_fp(FILE* input, FILE* output, char* encbuf, cha if(!output) { return base16384_err_fopen_output_file; } - off_t inputsize = BASE16384_ENCBUFSZ/8*8; + off_t inputsize = BASE16384_ENCBUFSZ-7; size_t cnt = 0; fputc(0xFE, output); fputc(0xFF, output); @@ -133,7 +133,7 @@ base16384_err_t base16384_encode_fd(int input, int output, char* encbuf, char* d if(output < 0) { return base16384_err_fopen_output_file; } - off_t inputsize = BASE16384_ENCBUFSZ/8*8; + off_t inputsize = BASE16384_ENCBUFSZ-7; size_t cnt = 0; write(output, "\xfe\xff", 2); while((cnt = read(input, encbuf, inputsize)) > 0) {