Skip to content

Commit

Permalink
add lint and fuzz to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyx committed Oct 14, 2023
1 parent 6048cba commit 99856de
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/shsub
/shsub.1
.DS_Store
/fuzz
/lint
*.tmp
*.dSYM
*.swp
30 changes: 28 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all install test clean
.PHONY: all install test clean lint fuzz

name = shsub
prefix = /usr/local
Expand All @@ -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'
13 changes: 7 additions & 6 deletions shsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#include <getopt.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -327,7 +328,7 @@ void rmscr(void)
void version(void)
{
fputs(
"Shsub 2.0.1\n"
"Shsub 2.1.0\n"
"Project Homepage: <https://github.com/dongyx/shsub>\n"
"Copyright (c) 2022 DONG Yuxuan <https://www.dyx.name>\n"
, stdout);
Expand Down Expand Up @@ -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, ...)
Expand All @@ -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);
}

0 comments on commit 99856de

Please sign in to comment.