summaryrefslogtreecommitdiffstats
path: root/src/url.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/url.c')
-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 {