Fix segfault in info backend when invoked with inputs/test.but
[sgt/halibut] / misc.c
diff --git a/misc.c b/misc.c
index 0d488d4..1d407de 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -90,13 +90,16 @@ void rdaddc(rdstringc *rs, char c) {
     rs->text[rs->pos] = 0;
 }
 void rdaddsc(rdstringc *rs, char const *p) {
-    int len = strlen(p);
+    rdaddsn(rs, p, strlen(p));
+}
+void rdaddsn(rdstringc *rs, char const *p, int len) {
     if (rs->pos >= rs->size - len) {
        rs->size = rs->pos + len + 128;
        rs->text = sresize(rs->text, rs->size, char);
     }
-    strcpy(rs->text + rs->pos, p);
+    memcpy(rs->text + rs->pos, p, len);
     rs->pos += len;
+    rs->text[rs->pos] = 0;
 }
 char *rdtrimc(rdstringc *rs) {
     rs->text = sresize(rs->text, rs->pos + 1, char);
@@ -126,7 +129,7 @@ static int compare_wordlists_literally(word *a, word *b) {
        } else {
            wchar_t *ap = a->text, *bp = b->text;
            while (*ap && *bp) {
-               wchar_t ac = utolower(*ap), bc = utolower(*bp);
+               wchar_t ac = *ap, bc = *bp;
                if (ac != bc)
                    return (ac < bc ? -1 : +1);
                if (!*++ap && a->next && a->next->type == t && !a->next->alt)