torrentd

simple torrent daemon
git clone git://git.2f30.org/torrentd
Log | Files | Refs | LICENSE

commit a09d83602538a22301adeee2707b9c7dd7e60a64
parent b13eb6063df000d202ae7568db7f2c0d6c826a77
Author: sin <sin@2f30.org>
Date:   Thu, 17 Dec 2015 16:43:53 +0000

Add len param to urlencode()

Diffstat:
Msbtd.h | 2+-
Mutil.c | 8+++++---
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/sbtd.h b/sbtd.h @@ -48,5 +48,5 @@ uint8_t *hex2bin(const char *, uint8_t *, size_t); char *bin2hex(const uint8_t *, char *, size_t); void sha1sum(uint8_t *, unsigned long, uint8_t *); int readfile(char *, char **, size_t *); -char *urlencode(char *); +char *urlencode(char *, size_t); char *urldecode(char *); diff --git a/util.c b/util.c @@ -148,12 +148,13 @@ readfile(char *file, char **b, size_t *n) } char * -urlencode(char *s) +urlencode(char *s, size_t n) { char *p = s, *buf, *bp; + size_t i = 0; - bp = buf = emalloc(strlen(s) * 3 + 1); - while (*p) { + bp = buf = emalloc(n * 3 + 1); + while (i < n) { if (*p == '-' || *p == '_' || *p == '.' || *p == '~' || isalnum(*p)) { @@ -166,6 +167,7 @@ urlencode(char *s) *bp++ = int2hex(*p); } p++; + i++; } *bp = '\0'; return buf;