aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-02-02 22:59:42 +0000
committerbptato <nincsnevem662@gmail.com>2021-02-02 22:59:42 +0000
commitd277e80771a1a5cae19d21bfd895b4e16b3ca959 (patch)
tree75bc8141a757015177d33fbcd2f3758869d6f1f5
parentSupport iTerm2 graphics protocol, replace encodeB with base64_encode (diff)
downloadw3m-d277e80771a1a5cae19d21bfd895b4e16b3ca959.tar.gz
w3m-d277e80771a1a5cae19d21bfd895b4e16b3ca959.zip
Some cleanup for base64_encode
-rw-r--r--etc.c8
-rw-r--r--file.c6
-rw-r--r--proto.h2
3 files changed, 10 insertions, 6 deletions
diff --git a/etc.c b/etc.c
index aa8b61d..7fabd03 100644
--- a/etc.c
+++ b/etc.c
@@ -2008,7 +2008,7 @@ void (*mySignal(int signal_number, void (*action) (int))) (int) {
static char Base64Table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-const char *
+char *
base64_encode(const unsigned char *src, int len)
{
unsigned char *w, *at;
@@ -2021,9 +2021,9 @@ base64_encode(const unsigned char *src, int len)
k = k / 3 * 4;
if (k < len)
- return "";
+ return NULL;
- w = GC_MALLOC_ATOMIC(k);
+ w = GC_MALLOC_ATOMIC(k + 1);
w[k] = 0;
at = w;
@@ -2061,5 +2061,5 @@ base64_encode(const unsigned char *src, int len)
*at++ = '=';
}
}
- return w;
+ return (char *)w;
}
diff --git a/file.c b/file.c
index 0e6a79a..04d7c8f 100644
--- a/file.c
+++ b/file.c
@@ -1175,7 +1175,11 @@ AuthBasicCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu,
Str s = Strdup(uname);
Strcat_char(s, ':');
Strcat(s, pw);
- return Strnew_m_charp("Basic ", base64_encode(s->ptr, s->length), NULL);
+ char *base64 = base64_encode(s->ptr, s->length);
+ if (!base64)
+ return Strnew_charp("Basic ");
+ else
+ return Strnew_m_charp("Basic ", base64, NULL);
}
#ifdef USE_DIGEST_AUTH
diff --git a/proto.h b/proto.h
index 1f8e7d2..6aafbb4 100644
--- a/proto.h
+++ b/proto.h
@@ -829,4 +829,4 @@ void srand48(long);
long lrand48(void);
#endif
-extern const char *base64_encode(const unsigned char *src, int len);
+extern char *base64_encode(const unsigned char *src, int len);