File size: 980 Bytes
b2265c0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | diff --git a/programs/escape.c b/programs/escape.c
index 4d409ea4..0bf9656c 100644
--- a/programs/escape.c
+++ b/programs/escape.c
@@ -113,9 +113,9 @@ htmlwescape (BITCODE_TU wstr)
while ((c = *tmp++))
len++;
len += 16;
- d = dest = malloc (len);
+ d = dest = calloc (len, 1);
- while (*wstr++)
+ while (*wstr)
{
const int off = d - dest;
if (off >= len - 8)
@@ -123,6 +123,7 @@ htmlwescape (BITCODE_TU wstr)
len += 16;
dest = realloc (dest, len);
d = dest + off;
+ *d = 0;
}
switch (*wstr)
{
@@ -139,10 +140,15 @@ htmlwescape (BITCODE_TU wstr)
{
sprintf (d, "&#x%X;", *wstr);
d += strlen (d);
+ *d = 0;
}
else if (*wstr >= 20)
- *d++ = *wstr;
+ {
+ *d++ = *wstr;
+ *d = 0;
+ }
}
+ wstr++;
}
*d = 0;
return dest;
|