From 9fb0a22dcb1ae04a1007316497fe6d11b91d8183 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Wed, 22 Apr 2020 18:25:09 -0700 Subject: fix: moved byte buffer to static storage so you don't read off stale stack --- sys/libbio/io/newick.c | 5 +++-- sys/libn/string.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'sys') diff --git a/sys/libbio/io/newick.c b/sys/libbio/io/newick.c index 5bd2d9a..f3aeb8a 100644 --- a/sys/libbio/io/newick.c +++ b/sys/libbio/io/newick.c @@ -67,8 +67,9 @@ static struct Token lex(Stream *s) { + byte *c; struct Token tok; - byte *c, b[1024]; + static byte b[1024]; c = b; *c = io·getbyte(s); @@ -120,7 +121,7 @@ lex(Stream *s) io·ungetbyte(s, *c); Assert(c - b < 1024); - *c = 0; + *c = '\0'; tok.kind = tok·ident; tok.lit.s = b; return tok; diff --git a/sys/libn/string.c b/sys/libn/string.c index 9bcef90..d5bb7ef 100644 --- a/sys/libn/string.c +++ b/sys/libn/string.c @@ -187,7 +187,7 @@ cleanup: string str·newlen(const byte* s, vlong len) { - vlong sl = (s == nil) ? 0 : strlen(s); + vlong sl = (!s) ? 0 : strlen(s); if (sl < len) panicf("attempted to take a bigger substring than string length"); vlong cap = (len == 0) ? 1 : len; @@ -199,7 +199,7 @@ str·newlen(const byte* s, vlong len) string str·new(const byte* s) { - vlong len = (s == nil) ? 0 : strlen(s); + vlong len = (!s) ? 0 : strlen(s); return str·newlen(s, len); } -- cgit v1.2.1