shithub: mc

Download patch

ref: 6fb3068098ac00cf2ebe8c5ec6b463a145662f92
parent: b4230c2187e0aa9a298cdebbcc6af769d3284cac
author: Ori Bernstein <ori@markovcorp.com>
date: Mon Feb 13 12:17:21 EST 2017

Pad tuples and arrays correctly.

--- a/6/blob.c
+++ b/6/blob.c
@@ -259,7 +259,7 @@
 
 static size_t blobrec(Blob *b, Htab *globls, Htab *strtab, Node *n)
 {
-	size_t i, sz;
+	size_t i, sz, end;
 
 	switch(exprop(n)) {
 	case Oucon:	sz = blobucon(b, globls, strtab, n);	break;
@@ -269,9 +269,17 @@
 	case Otup:
 	case Oarr:
 		/* Assumption: We sorted this while folding */
+		if (!n->expr.args)
+			break;
 		sz = 0;
-		for (i = 0; i < n->expr.nargs; i++)
+		for (i = 0; i < n->expr.nargs; i++) {
+			end = alignto(sz, exprtype(n->expr.args[i]));
+			sz += blobpad(b, end - sz);
 			sz += blobrec(b, globls, strtab, n->expr.args[i]);
+		}
+		/* if we need padding at the end.. */
+		end = alignto(sz, exprtype(n));
+		sz += blobpad(b, end - sz);
 		break;
 	default:
 		dump(n, stdout);