shithub: mc

Download patch

ref: 5c0705ccfaeef1fbb08762229fb66a7a977baaba
parent: 81faf1634871ae20739df2d5eb6525f47d14da77
author: Ori Bernstein <ori@eigenstate.org>
date: Mon May 9 20:07:02 EDT 2016

Align union tag lookup address correctly.

	Fixes #111

--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -260,6 +260,7 @@
 	var ui8 : int8, ui16: int16, ui32 : int32
 	var ui : int, ui64 : int64
 	var subap, subenc, subname
+	var inf, p
 
 	match typedesc(tyenc)
 	| `Tynone:	/* nothing */
@@ -391,7 +392,10 @@
 		sbfmt(sb, "]")
 		vabytes(ap)
 	| `Tyunion nc:
-		i_val = (ap.args castto(int32#))#
+		inf = typeinfo(tcpeek(&ap.tc))
+		p = ap.args castto(size)
+		p = (p + inf.align - 1) & ~(inf.align - 1)
+		i_val = (p castto(int32#))#
 		subap = vaenterunion(ap, i_val)
 		for var i = 0; i < i_val; i++
 			ncnext(&nc)