shithub: scc

Download patch

ref: 7c2da37ac070b9555af78aec088958a2664c65d7
parent: 72ff9501d14892e97a95cbf5c0a384ddc333b1dd
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Feb 23 05:06:58 EST 2017

[cc1] Fix pointer substraction with void*

At this moment the code was strictly checking if the two
pointers involved in a substraction had the same type,
but this was an error because substracting any pointer
with a null pointer should be allowed.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -304,7 +304,7 @@
 	size = sizeofnode(tp->type);
 
 	if (op == OSUB && BTYPE(rp) == PTR) {
-		if (!eqtype(tp, rp->type, 0))
+		if ((rp = convert(rp, lp->type, 0)) == NULL)
 			goto incorrect;
 		lp = node(OSUB, pdifftype, lp, rp);
 		return node(ODIV, inttype, lp, size);