From 9f899669b56f9542f3c5e6b536125f4f5270b1d0 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 28 Apr 2009 01:15:09 +0000 Subject: handle bogus programs --- Makefile | 1 + bf.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 82f2073..91662fe 100644 --- a/Makefile +++ b/Makefile @@ -2,5 +2,6 @@ PROG= bf NOMAN= +CFLAGS+= -Wall -ggdb .include diff --git a/bf.c b/bf.c index 5ef01c0..ff4f14c 100644 --- a/bf.c +++ b/bf.c @@ -71,7 +71,10 @@ main(int argc, char **argv) data = alloccell(); - for (p = prog; p; p = p->next) + for (p = prog; p; p = p->next) { +#if debug + fprintf(stderr, "\t%c: %d\n", p->value, data->value); +#endif switch (p->value) { case '>': if (!data->next) { @@ -104,15 +107,20 @@ main(int argc, char **argv) if (data->value == 0) while (p && p->value != ']') p = p->next; + if (!p) + goto quit; break; case ']': if (data->value != 0) while (p && p->value != '[') p = p->prev; + if (!p) + goto quit; break; default: break; } - + } +quit: return 0; } -- cgit v1.2.3