aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@debian.org>2021-04-05 13:37:33 +0000
committerTatsuya Kinoshita <tats@debian.org>2021-04-05 13:37:33 +0000
commit99d11d347ced2a1757f6362a46755c3126772295 (patch)
tree754f580382b24a7c04fed2e35e856a30235106bf
parentNew macro Strcatc and Strnulterm (diff)
downloadw3m-99d11d347ced2a1757f6362a46755c3126772295.tar.gz
w3m-99d11d347ced2a1757f6362a46755c3126772295.zip
Use Strcatc and Strnulterm in base64_encode
-rw-r--r--etc.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/etc.c b/etc.c
index 70735db..7cdd220 100644
--- a/etc.c
+++ b/etc.c
@@ -2026,6 +2026,10 @@ base64_encode(const unsigned char *src, size_t len)
return Strnew();
dest = Strnew_size(k);
+ if (dest->area_size <= k) {
+ Strfree(dest);
+ return Strnew();
+ }
in = src;
@@ -2036,10 +2040,10 @@ base64_encode(const unsigned char *src, size_t len)
j = j << 8 | *in++;
j = j << 8 | *in++;
- 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]);
+ Strcatc(dest, Base64Table[(j >> 18) & 0x3f]);
+ Strcatc(dest, Base64Table[(j >> 12) & 0x3f]);
+ Strcatc(dest, Base64Table[(j >> 6) & 0x3f]);
+ Strcatc(dest, Base64Table[j & 0x3f]);
}
if (src + len - in) {
@@ -2047,17 +2051,18 @@ base64_encode(const unsigned char *src, size_t len)
if (src + len - in) {
j = j << 8 | *in++;
j = j << 8;
- Strcat_char(dest, Base64Table[(j >> 18) & 0x3f]);
- Strcat_char(dest, Base64Table[(j >> 12) & 0x3f]);
- Strcat_char(dest, Base64Table[(j >> 6) & 0x3f]);
+ Strcatc(dest, Base64Table[(j >> 18) & 0x3f]);
+ Strcatc(dest, Base64Table[(j >> 12) & 0x3f]);
+ Strcatc(dest, Base64Table[(j >> 6) & 0x3f]);
} else {
j = j << 8;
j = j << 8;
- Strcat_char(dest, Base64Table[(j >> 18) & 0x3f]);
- Strcat_char(dest, Base64Table[(j >> 12) & 0x3f]);
- Strcat_char(dest, '=');
+ Strcatc(dest, Base64Table[(j >> 18) & 0x3f]);
+ Strcatc(dest, Base64Table[(j >> 12) & 0x3f]);
+ Strcatc(dest, '=');
}
- Strcat_char(dest, '=');
+ Strcatc(dest, '=');
}
+ Strnulterm(dest);
return dest;
}