summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-06-21 02:12:59 +0200
committerLouis Burda <quent.burda@gmail.com>2023-06-21 02:12:59 +0200
commit668a02b190517cb347d3dab167f2d2449043efa7 (patch)
treebc358160a9942d7f5987719cba5c6b9551a3b5a6
parent839d8742c8fe85d6cffd60c4d39853779c5a1e16 (diff)
downloadtmpl-668a02b190517cb347d3dab167f2d2449043efa7.tar.gz
tmpl-668a02b190517cb347d3dab167f2d2449043efa7.zip
Fix ifeq with undefined variables
-rw-r--r--Makefile6
-rw-r--r--main.c10
2 files changed, 12 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 96e5141..c419a9a 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,12 @@ BINDIR ?= /bin
CFLAGS = -std=c99 -Wunused-variable -Wunused-function -Wconversion
+ifeq ($(DEBUG),1)
+CFLAGS += -Og -g
+else
+CFLAGS += -O2
+endif
+
all: tmpl
clean:
diff --git a/main.c b/main.c
index b5121ab..f8d2ab0 100644
--- a/main.c
+++ b/main.c
@@ -107,10 +107,12 @@ template(char *line)
stack[stack_top].type = IFEQ;
if (!stack_top || stack[stack_top-1].active) {
value = getvar(line + 6);
- sep = strchr(line + 6, ' ');
- if (!sep) die("invalid #ifeq\n%lu: %s", lineno, line);
- if (!strcmp(value, sep + 1)) {
- stack[stack_top].active = 1;
+ if (value) {
+ sep = strchr(line + 6, ' ');
+ if (!sep) die("invalid #ifeq\n%lu: %s",
+ lineno, line);
+ if (!strcmp(value, sep + 1))
+ stack[stack_top].active = 1;
}
}
stack_top++;