diff options
author | Tatsuya Kinoshita <tats@debian.org> | 2021-04-05 13:35:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-05 13:35:47 +0000 |
commit | 068e2c278432ee1a6cee1d53f538a43961c3dfa4 (patch) | |
tree | 4d31ab3b12b8e8f04a2538a5a082ed51fbe0a373 /etc.c | |
parent | Update ChangeLog (diff) | |
parent | Return Str from base64_encode, fix extraction of first gif frame for animatio... (diff) | |
download | w3m-068e2c278432ee1a6cee1d53f538a43961c3dfa4.tar.gz w3m-068e2c278432ee1a6cee1d53f538a43961c3dfa4.zip |
Merge pull request #177 from bptato/inlineimages
Kitty inline image & base64 encoding fixes
Diffstat (limited to 'etc.c')
-rw-r--r-- | etc.c | 57 |
1 files changed, 24 insertions, 33 deletions
@@ -2008,32 +2008,25 @@ void (*mySignal(int signal_number, void (*action) (int))) (int) { static char Base64Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -char * +Str base64_encode(const unsigned char *src, size_t len) { - unsigned char *w, *at; + Str dest; const unsigned char *in, *endw; unsigned long j; size_t k; - - if (!len) - return NULL; - k = len; if (k % 3) - k += 3 - (k % 3); + k += 3 - (k % 3); + k = k / 3 * 4; - if (k + 1 < len) - return NULL; + if (!len || k + 1 < len) + return Strnew(); - w = GC_MALLOC_ATOMIC(k + 1); - if (!w) - return NULL; - w[k] = 0; + dest = Strnew_size(k); - at = w; in = src; endw = src + len - 2; @@ -2043,30 +2036,28 @@ base64_encode(const unsigned char *src, size_t len) j = j << 8 | *in++; j = j << 8 | *in++; - *at++ = Base64Table[(j >> 18) & 0x3f]; - *at++ = Base64Table[(j >> 12) & 0x3f]; - *at++ = Base64Table[(j >> 6) & 0x3f]; - *at++ = Base64Table[j & 0x3f]; + Strcat_char(dest, Base64Table[(j >> 18) & 0x3f]); + Strcat_char(dest, Base64Table[(j >> 12) & 0x3f]); + Strcat_char(dest, Base64Table[(j >> 6) & 0x3f]); + Strcat_char(dest, Base64Table[j & 0x3f]); } - if (in - src - len) { - if (in - src - len == 1) { - j = *in++; - j = j << 8; + if (src + len - in) { + j = *in++; + if (src + len - in) { + j = j << 8 | *in++; j = j << 8; - *at++ = Base64Table[(j >> 18) & 0x3f]; - *at++ = Base64Table[(j >> 12) & 0x3f]; - *at++ = '='; - *at++ = '='; + Strcat_char(dest, Base64Table[(j >> 18) & 0x3f]); + Strcat_char(dest, Base64Table[(j >> 12) & 0x3f]); + Strcat_char(dest, Base64Table[(j >> 6) & 0x3f]); } else { - j = *in++; - j = j << 8 | *in++; j = j << 8; - *at++ = Base64Table[(j >> 18) & 0x3f]; - *at++ = Base64Table[(j >> 12) & 0x3f]; - *at++ = Base64Table[(j >> 6) & 0x3f]; - *at++ = '='; + j = j << 8; + Strcat_char(dest, Base64Table[(j >> 18) & 0x3f]); + Strcat_char(dest, Base64Table[(j >> 12) & 0x3f]); + Strcat_char(dest, '='); } + Strcat_char(dest, '='); } - return (char *)w; + return dest; } |