From 7717051e3ce062fbdb8415e4befa5205d25e80bb Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 15 May 2016 19:10:37 +0200 Subject: rc: fix inband globbing bugs, cleanup add glob information to the word structure so we wont accidently deglob quoted strings containing the GLOB. we store Globsize(word) in in word->glob which avoids recalculating that values and the check if a word should be globbed quick. globlist() now substitutes the word inplace avoiding the copying when all words are literals and avoids recursion. minor cleanups: use list2str() in execeval(), move octal() to unix.c, remove the (char*) casts to efree(). --- sys/src/cmd/rc/code.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sys/src/cmd/rc/code.c') diff --git a/sys/src/cmd/rc/code.c b/sys/src/cmd/rc/code.c index 7d1abbb3a..8d64500ae 100644 --- a/sys/src/cmd/rc/code.c +++ b/sys/src/cmd/rc/code.c @@ -274,8 +274,19 @@ outcode(tree *t, int eflag) emitf(Xunlocal); break; case WORD: - emitf(Xword); - emits(estrdup(t->str)); + if(t->quoted){ + emitf(Xword); + emits(estrdup(t->str)); + } else { + if((q = Globsize(t->str)) > 0){ + emitf(Xglobs); + emits(estrdup(t->str)); + emiti(q); + } else { + emitf(Xword); + emits(deglob(estrdup(t->str))); + } + } break; case DUP: if(t->rtype==DUPFD){ @@ -473,6 +484,7 @@ codefree(code *cp) || p->f==Xsubshell || p->f==Xtrue) p++; else if(p->f==Xdup || p->f==Xpipefd) p+=2; else if(p->f==Xpipe) p+=4; + else if(p->f==Xglobs) efree(p[1].s), p+=2; else if(p->f==Xword || p->f==Xdelhere) efree((++p)->s); else if(p->f==Xfn){ efree(p[2].s); -- cgit v1.2.3