blobmsg: introduce BLOBMSG_CAST_INT64
[project/libubox.git] / base64.c
index b6f8bf37095a5b51e25a73f69101ddca73a4c612..1bf21772fbed448f75e9b5c299c2db5ddf48fcd6 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -65,6 +65,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#include "assert.h"
 #include "utils.h"
 
 static const char Base64[] =
@@ -140,9 +142,11 @@ int b64_encode(const void *_src, size_t srclength,
        const unsigned char *src = _src;
        char *target = dest;
        size_t datalength = 0;
-       u_char input[3];
+       u_char input[3] = {0};
        u_char output[4];
-       int i;
+       size_t i;
+
+       assert(dest && targsize > 0);
 
        while (2 < srclength) {
                input[0] = *src++;
@@ -200,13 +204,16 @@ int b64_decode(const void *_src, void *dest, size_t targsize)
 {
        const char *src = _src;
        unsigned char *target = dest;
-       int tarindex, state, ch;
+       int state, ch;
+       size_t tarindex;
        u_char nextbyte;
        char *pos;
 
        state = 0;
        tarindex = 0;
 
+       assert(dest && targsize > 0);
+
        while ((ch = (unsigned char)*src++) != '\0') {
                if (isspace(ch))        /* Skip whitespace anywhere. */
                        continue;