diff --git a/.gitignore b/.gitignore index 38f631c..c0a9c7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /shsub /shsub.1 .DS_Store +/fuzz +/lint *.tmp *.dSYM *.swp diff --git a/Makefile b/Makefile index 41d3f16..a31a430 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all install test clean +.PHONY: all install test clean lint fuzz name = shsub prefix = /usr/local @@ -24,4 +24,30 @@ test: all ./test clean: - rm -rf shsub shsub.1 *.dSYM + rm -rf shsub shsub.1 *.dSYM lint fuzz + +lint: + @rm -rf lint + @mkdir -p lint + @cp Makefile *.c lint + @cd lint && make 'CFLAGS= \ + -std=c89 \ + -D_POSIX_C_SOURCE=200809L \ + -pedantic-errors \ + -Wextra \ + -Wno-error' + +fuzz: + @rm -rf fuzz + @mkdir -p fuzz + @cp -r Makefile *.c cases test fuzz + @cd fuzz && make test \ + 'CFLAGS= \ + -std=c89 \ + -D_POSIX_C_SOURCE=200809L \ + -pedantic-errors \ + -Wextra \ + -Wno-error \ + -O3 \ + -fno-sanitize-recover \ + -fsanitize=address,undefined' diff --git a/shsub.c b/shsub.c index b88ed69..de994b4 100644 --- a/shsub.c +++ b/shsub.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -123,7 +124,7 @@ enum token gettoken(FILE *fp) p = literal; while (kw == END) { - while (p - literal < MAXLITR - 1) { + while (p != literal + MAXLITR - 1) { if ((c = cpop(fp)) == EOF || strchr("<%-", c )) break; *p++ = c; @@ -167,7 +168,7 @@ enum token gettoken(FILE *fp) return LITERAL; } /* push back a char if the token is 2-char */ - if (kw == CMDOPEN || kw == CLOSE && !trim) + if (kw == CMDOPEN || (kw == CLOSE && !trim)) cpush(r); if (trim && (c = cpop(fp)) != '\n') cpush(c); @@ -327,7 +328,7 @@ void rmscr(void) void version(void) { fputs( - "Shsub 2.0.1\n" + "Shsub 2.1.0\n" "Project Homepage: \n" "Copyright (c) 2022 DONG Yuxuan \n" , stdout); @@ -363,7 +364,7 @@ void err(char *fmt, ...) vfprintf(stderr, fmt, ap); va_end(ap); fputc('\n', stderr); - exit(-1); + exit(1); } void parserr(char *fmt, ...) @@ -379,11 +380,11 @@ void parserr(char *fmt, ...) vfprintf(stderr, fmt, ap); va_end(ap); fputc('\n', stderr); - exit(-1); + exit(1); } void syserr(void) { perror(progname); - exit(-1); + exit(1); }