From b2ef0ff49de457a6e48751e7eedd8131cdca5f98 Mon Sep 17 00:00:00 2001 From: Humm Date: Wed, 21 Apr 2021 08:28:32 +0200 Subject: [PATCH] plumber: fix substrings in match rules Unmatched substrings are nil, so we can't rely on nil terminating the array of substrings. --- sys/src/cmd/plumb/match.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/src/cmd/plumb/match.c b/sys/src/cmd/plumb/match.c index 22fb36b16..3a00c16b7 100644 --- a/sys/src/cmd/plumb/match.c +++ b/sys/src/cmd/plumb/match.c @@ -36,12 +36,13 @@ setvar(Resub rs[10], char *match[10]) free(match[i]); match[i] = nil; } - for(i=0; i<10 && rs[i].sp!=nil; i++){ - n = rs[i].ep-rs[i].sp; - match[i] = emalloc(n+1); - memmove(match[i], rs[i].sp, n); - match[i][n] = '\0'; - } + for(i=0; i<10; i++) + if(rs[i].sp!=nil){ + n = rs[i].ep-rs[i].sp; + match[i] = emalloc(n+1); + memmove(match[i], rs[i].sp, n); + match[i][n] = '\0'; + } } int