handle zero-length arrays in truncate functions

This commit is contained in:
Joel Dice 2012-03-17 12:57:59 -06:00
parent 333b6c59d4
commit 8cb6446bec

View File

@ -6216,8 +6216,10 @@ truncateIntArray(Thread* t, object array, unsigned length)
PROTECT(t, array); PROTECT(t, array);
object newArray = makeIntArray(t, length); object newArray = makeIntArray(t, length);
memcpy(&intArrayBody(t, newArray, 0), &intArrayBody(t, array, 0), if (length) {
length * 4); memcpy(&intArrayBody(t, newArray, 0), &intArrayBody(t, array, 0),
length * 4);
}
return newArray; return newArray;
} }
@ -6230,8 +6232,10 @@ truncateArray(Thread* t, object array, unsigned length)
PROTECT(t, array); PROTECT(t, array);
object newArray = makeArray(t, length); object newArray = makeArray(t, length);
memcpy(&arrayBody(t, newArray, 0), &arrayBody(t, array, 0), if (length) {
length * BytesPerWord); memcpy(&arrayBody(t, newArray, 0), &arrayBody(t, array, 0),
length * BytesPerWord);
}
return newArray; return newArray;
} }
@ -6244,9 +6248,11 @@ truncateLineNumberTable(Thread* t, object table, unsigned length)
PROTECT(t, table); PROTECT(t, table);
object newTable = makeLineNumberTable(t, length); object newTable = makeLineNumberTable(t, length);
memcpy(&lineNumberTableBody(t, newTable, 0), if (length) {
&lineNumberTableBody(t, table, 0), memcpy(&lineNumberTableBody(t, newTable, 0),
length * sizeof(uint64_t)); &lineNumberTableBody(t, table, 0),
length * sizeof(uint64_t));
}
return newTable; return newTable;
} }