summaryrefslogtreecommitdiffstats
path: root/gl/base64.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/base64.c')
-rw-r--r--gl/base64.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/gl/base64.c b/gl/base64.c
index d99e175..8da969c 100644
--- a/gl/base64.c
+++ b/gl/base64.c
@@ -1,6 +1,5 @@
1/* base64.c -- Encode binary data using printable characters. 1/* base64.c -- Encode binary data using printable characters.
2 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2009, 2010 Free Software 2 Copyright (C) 1999-2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
3 Foundation, Inc.
4 3
5 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -13,14 +12,13 @@
13 GNU General Public License for more details. 12 GNU General Public License for more details.
14 13
15 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation, 15 along with this program; if not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 16
19/* Written by Simon Josefsson. Partially adapted from GNU MailUtils 17/* Written by Simon Josefsson. Partially adapted from GNU MailUtils
20 * (mailbox/filter_trans.c, as of 2004-11-28). Improved by review 18 * (mailbox/filter_trans.c, as of 2004-11-28). Improved by review
21 * from Paul Eggert, Bruno Haible, and Stepan Kasal. 19 * from Paul Eggert, Bruno Haible, and Stepan Kasal.
22 * 20 *
23 * See also RFC 3548 <http://www.ietf.org/rfc/rfc3548.txt>. 21 * See also RFC 4648 <http://www.ietf.org/rfc/rfc4648.txt>.
24 * 22 *
25 * Be careful with error checking. Here is how you would typically 23 * Be careful with error checking. Here is how you would typically
26 * use these functions: 24 * use these functions:
@@ -55,7 +53,7 @@
55#include <string.h> 53#include <string.h>
56 54
57/* C89 compliant way to cast 'char' to 'unsigned char'. */ 55/* C89 compliant way to cast 'char' to 'unsigned char'. */
58static inline unsigned char 56static unsigned char
59to_uchar (char ch) 57to_uchar (char ch)
60{ 58{
61 return ch; 59 return ch;
@@ -316,7 +314,7 @@ base64_decode_ctx_init (struct base64_decode_context *ctx)
316 and return CTX->buf. In either case, advance *IN to point to the byte 314 and return CTX->buf. In either case, advance *IN to point to the byte
317 after the last one processed, and set *N_NON_NEWLINE to the number of 315 after the last one processed, and set *N_NON_NEWLINE to the number of
318 verified non-newline bytes accessible through the returned pointer. */ 316 verified non-newline bytes accessible through the returned pointer. */
319static inline char * 317static char *
320get_4 (struct base64_decode_context *ctx, 318get_4 (struct base64_decode_context *ctx,
321 char const *restrict *in, char const *restrict in_end, 319 char const *restrict *in, char const *restrict in_end,
322 size_t *n_non_newline) 320 size_t *n_non_newline)
@@ -370,7 +368,7 @@ get_4 (struct base64_decode_context *ctx,
370 as many bytes as possible are written to *OUT. On return, advance 368 as many bytes as possible are written to *OUT. On return, advance
371 *OUT to point to the byte after the last one written, and decrement 369 *OUT to point to the byte after the last one written, and decrement
372 *OUTLEN to reflect the number of bytes remaining in *OUT. */ 370 *OUTLEN to reflect the number of bytes remaining in *OUT. */
373static inline bool 371static bool
374decode_4 (char const *restrict in, size_t inlen, 372decode_4 (char const *restrict in, size_t inlen,
375 char *restrict *outp, size_t *outleft) 373 char *restrict *outp, size_t *outleft)
376{ 374{
@@ -553,10 +551,10 @@ base64_decode_alloc_ctx (struct base64_decode_context *ctx,
553{ 551{
554 /* This may allocate a few bytes too many, depending on input, 552 /* This may allocate a few bytes too many, depending on input,
555 but it's not worth the extra CPU time to compute the exact size. 553 but it's not worth the extra CPU time to compute the exact size.
556 The exact size is 3 * inlen / 4, minus 1 if the input ends 554 The exact size is 3 * (inlen + (ctx ? ctx->i : 0)) / 4, minus 1 if the
557 with "=" and minus another 1 if the input ends with "==". 555 input ends with "=" and minus another 1 if the input ends with "==".
558 Dividing before multiplying avoids the possibility of overflow. */ 556 Dividing before multiplying avoids the possibility of overflow. */
559 size_t needlen = 3 * (inlen / 4) + 2; 557 size_t needlen = 3 * (inlen / 4) + 3;
560 558
561 *out = malloc (needlen); 559 *out = malloc (needlen);
562 if (!*out) 560 if (!*out)