From edf59e4f73d6efaa686d7c7a3971a812e3fee7e6 Mon Sep 17 00:00:00 2001
From: Dale Weiler <killfieldengine@gmail.com>
Date: Sat, 22 Jun 2013 00:15:25 +0000
Subject: [PATCH] Fixed possible bug in VM. Added coverity rules to makefiles.

---
 BSDmakefile | 6 ++++++
 Makefile    | 7 +++++++
 exec.c      | 4 +++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/BSDmakefile b/BSDmakefile
index 947f383..7614968 100644
--- a/BSDmakefile
+++ b/BSDmakefile
@@ -79,6 +79,12 @@ gource-record:
 depend:
 	@makedepend -Y -f BSDmakefile -w 65536 2> /dev/null ${DEPS:C/\.o/.c/g}
 
+coverity:
+	@cov-build --dir cov-int $(MAKE) -f BSDmakefile
+	@tar czf gm-qcc.tgz cov-int
+	@rm -rf cov-int
+	@echo gm-qcc.tgz generated, submit for analysis
+
 install: install-gmqcc install-qcvm install-gmqpak install-doc
 install-gmqcc: $(GMQCC)
 	install -d -m755              $(DESTDIR)$(BINDIR)
diff --git a/Makefile b/Makefile
index 3ab21a8..4ba2bcd 100644
--- a/Makefile
+++ b/Makefile
@@ -115,6 +115,13 @@ gource-record:
 depend:
 	@ makedepend -Y -w 65536 2> /dev/null $(subst .o,.c,$(DEPS))
 
+
+coverity:
+	@cov-build --dir cov-int $(MAKE)
+	@tar czf gm-qcc.tgz cov-int
+	@rm -rf cov-int
+	@echo gm-qcc.tgz generated, submit for analysis
+
 #install rules
 install: install-gmqcc install-qcvm install-gmqpak install-doc
 install-gmqcc: $(GMQCC)
diff --git a/exec.c b/exec.c
index dccee5e..00f32f1 100644
--- a/exec.c
+++ b/exec.c
@@ -304,7 +304,9 @@ static void trace_print_global(qc_program *prog, unsigned int glob, int vtype) {
     int       len;
 
     if (!glob) {
-        len = printf("<null>,");
+        if ((len = printf("<null>,")) == -1)
+            len = 0;
+
         goto done;
     }
 
-- 
2.39.5