tmpl

Simple key-value templator
git clone https://git.sinitax.com/sinitax/tmpl
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 668a02b190517cb347d3dab167f2d2449043efa7
parent 839d8742c8fe85d6cffd60c4d39853779c5a1e16
Author: Louis Burda <quent.burda@gmail.com>
Date:   Wed, 21 Jun 2023 02:12:59 +0200

Fix ifeq with undefined variables

Diffstat:
MMakefile | 6++++++
Mmain.c | 10++++++----
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git 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 @@ -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++;