]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - base64.c
base64: Trivial whitespace fixes.
[paraslash.git] / base64.c
index 4809a2f285f63dd83132f693be23f68945fce21d..d9fa483b23b4e33983382b2f6a4142e8016d8d89 100644 (file)
--- a/base64.c
+++ b/base64.c
 
 static const char Base64[] =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char Pad64 = '=';
 
 /** Maximal possible size of the decoded data. */
 #define BASE64_MAX_DECODED_SIZE(_encoded_size) ((_encoded_size) / 4 * 3)
 
+#define PAD64 '='
 /**
  * base64-decode a buffer.
  *
@@ -46,12 +46,10 @@ int base64_decode(char const *src, size_t encoded_size, char **result,
        char *pos;
        const char *end = src + encoded_size;
        unsigned char *target;
-       size_t targsize;
 
        if (encoded_size == (size_t)-1)
                encoded_size = strlen(src);
-       targsize = BASE64_MAX_DECODED_SIZE(encoded_size);
-       target = para_malloc(targsize + 1);
+       target = para_malloc(BASE64_MAX_DECODED_SIZE(encoded_size) + 1);
 
        state = 0;
        tarindex = 0;
@@ -61,7 +59,7 @@ int base64_decode(char const *src, size_t encoded_size, char **result,
                if (para_isspace(ch)) /* Skip whitespace anywhere. */
                        continue;
 
-               if (ch == Pad64)
+               if (ch == PAD64)
                        break;
 
                pos = strchr(Base64, ch);
@@ -70,62 +68,51 @@ int base64_decode(char const *src, size_t encoded_size, char **result,
 
                switch (state) {
                case 0:
-                       if (tarindex >= targsize)
-                               goto fail;
                        target[tarindex] = (pos - Base64) << 2;
                        state = 1;
                        break;
                case 1:
-                       if (tarindex + 1 >= targsize)
-                               goto fail;
                        target[tarindex] |= (pos - Base64) >> 4;
                        target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4;
                        tarindex++;
                        state = 2;
                        break;
                case 2:
-                       if (tarindex + 1 >= targsize)
-                               goto fail;
                        target[tarindex] |= (pos - Base64) >> 2;
                        target[tarindex + 1] = ((pos - Base64) & 0x03) << 6;
                        tarindex++;
                        state = 3;
                        break;
                case 3:
-                       if (tarindex >= targsize)
-                               goto fail;
                        target[tarindex] |= pos - Base64;
                        tarindex++;
                        state = 0;
                        break;
                }
        }
-
        /*
         * We are done decoding Base-64 chars.  Let's see if we ended
         * on a byte boundary, and/or with erroneous trailing characters.
         */
-
-       if (*src == Pad64) {            /* We got a pad char. */
-               ch = *src++;            /* Skip it, get next. */
+       if (*src == PAD64) { /* We got a pad char. */
+               ch = *src++; /* Skip it, get next. */
                switch (state) {
-               case 0:         /* Invalid = in first position */
-               case 1:         /* Invalid = in second position */
+               case 0: /* Invalid = in first position */
+               case 1: /* Invalid = in second position */
                        goto fail;
 
-               case 2:         /* Valid, means one byte of info */
+               case 2: /* Valid, means one byte of info */
                        /* Skip any number of spaces. */
                        for (; ch != '\0'; ch = *src++)
                                if (!isspace(ch))
                                        break;
                        /* Make sure there is another trailing = sign. */
-                       if (ch != Pad64)
+                       if (ch != PAD64)
                                goto fail;
                        ch = *src++;            /* Skip the = */
                        /* Fall through to "single trailing =" case. */
-                       /* FALLTHROUGH */
 
-               case 3:         /* Valid, means two bytes of info */
+               case 3: /* Valid, means two bytes of info */
                        /*
                         * We know this char is an =.  Is there anything but
                         * whitespace after it?
@@ -133,7 +120,6 @@ int base64_decode(char const *src, size_t encoded_size, char **result,
                        for (; ch != '\0'; ch = *src++)
                                if (!isspace(ch))
                                        goto fail;
-
                        /*
                         * Now make sure for cases 2 and 3 that the "extra"
                         * bits that slopped past the last full byte were