summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2018-10-22 17:09:15 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-10-22 17:09:15 +0200
commitb613092de8b4b4625c8a2e8b29d64c5a8e49287e (patch)
treee2d1255475a9000b2675dca18aef54ba1c3ff972 /compiler
parent9c88df220a3fb871a9d3fecf7623e27c0fa35667 (diff)
downloadNim-b613092de8b4b4625c8a2e8b29d64c5a8e49287e.tar.gz
Don't crash if GC_{un,}ref is called on nil (#9445)
Fixes #9442
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index d73dac82f..44967961e 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2008,8 +2008,8 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
       frmt = "$1 = $2->len;$n"
     lineCg(p, cpsStmts, frmt, tmp.r, rdLoc(a))
     putIntoDest(p, d, e, tmp.r)
-  of mGCref: unaryStmt(p, e, d, "#nimGCref($1);$n")
-  of mGCunref: unaryStmt(p, e, d, "#nimGCunref($1);$n")
+  of mGCref: unaryStmt(p, e, d, "if ($1) { #nimGCref($1); }$n")
+  of mGCunref: unaryStmt(p, e, d, "if ($1) { #nimGCunref($1); }$n")
   of mSetLengthStr: genSetLengthStr(p, e, d)
   of mSetLengthSeq: genSetLengthSeq(p, e, d)
   of mIncl, mExcl, mCard, mLtSet, mLeSet, mEqSet, mMulSet, mPlusSet, mMinusSet,