shithub: scc

Download patch

ref: a5f2c1a41746a077bbb34b127e23240d1f38c2b3
parent: 38670978b7243e0b2093c553a4c3df03178d9d0a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Nov 5 17:50:21 EDT 2021

cc2: Improve prnode()

Checking for invalid pointer makes more robust the code
because the root of the tree can be NULL too.

--- a/src/cmd/cc/cc2/node.c
+++ b/src/cmd/cc/cc2/node.c
@@ -33,10 +33,11 @@
 static void
 prnode(Node *np)
 {
-	if (np->left)
-		prnode(np->left);
-	if (np->right)
-		prnode(np->right);
+	if (!np)
+		return;
+	prnode(np->left);
+	prnode(np->right);
+
 	fprintf(stderr, "\t%c%lu", np->op, np->type.size);
 }