diff options
Diffstat (limited to '')
-rw-r--r-- | src/url.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1,5 +1,5 @@ -int urlencode (char * o, char * i /* o must have at least strlen(i)*3+1 bytes of memory allocated */) { - size_t written = 0; +int urlencode (char * o, const char * i /* o must have at least strlen(i)*3+1 bytes of memory allocated */) { + size_t written = 0; /* o CANNOT be equal to i, unlike in urldecode */ for (; *i; i++) { if (isalnum(*i) || *i == '.' || *i == '_' || *i == '-' || *i == '~') { o[written++] = *i; @@ -8,10 +8,11 @@ int urlencode (char * o, char * i /* o must have at least strlen(i)*3+1 bytes of written += 3; } } + o[written++] = '\0'; return 1; } -int urldecode (char * o, char * i /* o must have at least strlen(i)+1 bytes memory allocated */) { - size_t written = 0; +int urldecode (char * o, const char * i /* o must have at least strlen(i)+1 bytes memory allocated */) { + size_t written = 0; /* o can be equal to i for decoding in-place */ char buf[] = "00"; for (; *i; i++) { if (*i == '%') { @@ -26,5 +27,6 @@ int urldecode (char * o, char * i /* o must have at least strlen(i)+1 bytes memo o[written++] = *i; } } + o[written++] = '\0'; return 1; } |