summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-04-22 20:17:19 +0000
committerrillig <rillig@NetBSD.org>2023-04-22 20:17:19 +0000
commitda82c080494b6e6b032cf5dd4d520a7441ea0e08 (patch)
tree5dccc0c3fe7a0f177b61dfade460af4396702dfd
parentfc84fcc64b0eed2400c99bad75ea338ccfbfefe3 (diff)
lint: fix missing initialization for cast to union
The left operand of a unary AST node must not be NULL. The previous code crashed lint when run with some query enabled, as is_cast_redundant assumes that a non-null AST node has valid operands. $ cat <<EOF > crash.c double demo(void) { union u { double *num; } u; u = (union u)&((double) { 0.0 }); return *u.num; } EOF $ /usr/libexec/lint1 -w -S -g -q8 crash.c /dev/null
-rw-r--r--usr.bin/xlint/lint1/debug.c8
-rw-r--r--usr.bin/xlint/lint1/tree.c7
2 files changed, 9 insertions, 6 deletions
diff --git a/usr.bin/xlint/lint1/debug.c b/usr.bin/xlint/lint1/debug.c
index 2fc8fa4acad..99ee993094e 100644
--- a/usr.bin/xlint/lint1/debug.c
+++ b/usr.bin/xlint/lint1/debug.c
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.29 2023/04/22 17:49:15 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.30 2023/04/22 20:17:19 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.29 2023/04/22 17:49:15 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.30 2023/04/22 20:17:19 rillig Exp $");
#endif
#include <stdlib.h>
@@ -205,8 +205,10 @@ debug_node(const tnode_t *tn) // NOLINT(misc-no-recursion)
debug_printf("\n");
debug_indent_inc();
+ lint_assert(tn->tn_left != NULL);
debug_node(tn->tn_left);
- if (is_binary(tn) || tn->tn_right != NULL)
+ lint_assert(is_binary(tn) == (tn->tn_right != NULL));
+ if (tn->tn_right != NULL)
debug_node(tn->tn_right);
debug_indent_dec();
}
diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c
index c79def11699..2341543b903 100644
--- a/usr.bin/xlint/lint1/tree.c
+++ b/usr.bin/xlint/lint1/tree.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.517 2023/04/22 17:49:15 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.518 2023/04/22 20:17:19 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.517 2023/04/22 17:49:15 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.518 2023/04/22 20:17:19 rillig Exp $");
#endif
#include <float.h>
@@ -4049,7 +4049,7 @@ build_alignof(const type_t *tp)
}
static tnode_t *
-cast_to_union(const tnode_t *otn, type_t *ntp)
+cast_to_union(tnode_t *otn, type_t *ntp)
{
if (!allow_gcc) {
@@ -4066,6 +4066,7 @@ cast_to_union(const tnode_t *otn, type_t *ntp)
ntn->tn_op = CVT;
ntn->tn_type = ntp;
ntn->tn_cast = true;
+ ntn->tn_left = otn;
ntn->tn_right = NULL;
return ntn;
}