summaryrefslogtreecommitdiffstats
path: root/src/url.c
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-04-07 23:15:16 +0200
committersijanec <anton@sijanec.eu>2021-04-07 23:15:16 +0200
commita19e3705a228735eacadd713b28d49fe33bb726b (patch)
tree9c5fd6e62a24e7f893686b45da15ecda91b41a58 /src/url.c
parentfuck (diff)
downloadsear.c-a19e3705a228735eacadd713b28d49fe33bb726b.tar
sear.c-a19e3705a228735eacadd713b28d49fe33bb726b.tar.gz
sear.c-a19e3705a228735eacadd713b28d49fe33bb726b.tar.bz2
sear.c-a19e3705a228735eacadd713b28d49fe33bb726b.tar.lz
sear.c-a19e3705a228735eacadd713b28d49fe33bb726b.tar.xz
sear.c-a19e3705a228735eacadd713b28d49fe33bb726b.tar.zst
sear.c-a19e3705a228735eacadd713b28d49fe33bb726b.zip
Diffstat (limited to '')
-rw-r--r--src/url.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/url.c b/src/url.c
index df93138..13081a0 100644
--- a/src/url.c
+++ b/src/url.c
@@ -1,4 +1,6 @@
int urlencode (char * o, const char * i /* o must have at least strlen(i)*3+1 bytes of memory allocated */) {
+ if (!o || !i)
+ return -2;
size_t written = 0; /* o CANNOT be equal to i, unlike in urldecode */
for (; *i; i++) {
if (isalnum(*i) || *i == '.' || *i == '_' || *i == '-' || *i == '~') {
@@ -12,6 +14,8 @@ int urlencode (char * o, const char * i /* o must have at least strlen(i)*3+1 by
return 1;
}
int urldecode (char * o, const char * i /* o must have at least strlen(i)+1 bytes memory allocated */) {
+ if (!o || !i)
+ return -2;
size_t written = 0; /* o can be equal to i for decoding in-place */
char buf[] = "00";
for (; *i; i++) {
@@ -20,7 +24,7 @@ int urldecode (char * o, const char * i /* o must have at least strlen(i)+1 byte
buf[1] = *++i;
if (!buf[0] || !buf[1]) { /* malformed */
o[written++] = '\0';
- return 0;
+ return -1;
}
o[written++] = strtol(buf, NULL, 16);
} else {