[hackers] [scc] Fix ternary operator and null pointer constants || Roberto E. Vargas Caballero
commit bcb57e195084cc997b8540b032c37c41d994d3b0
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Jan 8 17:47:30 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Jan 8 17:47:30 2016 +0100
Fix ternary operator and null pointer constants
Only null pointer constants are converted, no
void * pointers.
diff --git a/cc1/expr.c b/cc1/expr.c
index 08c1bcd..0dd4da9 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -127,6 +127,14 @@ set_p1_p2:
*p2 = np2;
}
+static int
+isnull(Node *np)
+{
+ if (!np->constant || np->type != pvoidtype)
+ return 0;
+ return cmpnode(np, 0);
+}
+
static Node *
chkternary(Node *yes, Node *no)
{
_AT_@ -146,18 +154,26 @@ chkternary(Node *yes, Node *no)
} else if (yes->type->op != PTR && no->type->op != PTR) {
goto wrong_type;
} else {
+ /* convert integer 0 to NULL */
if (yes->type->integer && cmpnode(yes, 0))
- yes = convert(yes, no->type, 0);
+ yes = convert(yes, pvoidtype, 0);
if (no->type->integer && cmpnode(no, 0))
- no = convert(no, yes->type, 0);
-
+ no = convert(no, pvoidtype, 0);
+ /*
+ * At this point the type of both should be
+ * a pointer to something, or we have don't
+ * compatible types
+ */
if (yes->type->op != PTR || no->type->op != PTR)
goto wrong_type;
-
- if (yes->type == pvoidtype)
+ /*
+ * If we have a null pointer constant then
+ * convert to the another type
+ */
+ if (isnull(yes))
yes = convert(yes, no->type, 0);
- if (no->type == pvoidtype)
- no = convert(no, no->type, 0);
+ if (isnull(no))
+ no = convert(no, yes->type, 0);
if (!eqtype(yes->type, no->type))
goto wrong_type;
Received on Fri Jan 08 2016 - 17:51:14 CET
This archive was generated by hypermail 2.3.0
: Fri Jan 08 2016 - 18:00:23 CET