aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Croteau <jcroteau@gmail.com>2014-02-19 00:45:51 -0800
committerJoel Croteau <jcroteau@gmail.com>2014-02-19 01:17:17 -0800
commitc84c6eda17a6ac5e9c56bbc76839c472238a97c4 (patch)
tree96567bfc014aee477f6fa0cd995cce46d6464233
parentd1c09ebd46b35ed2b343ebab9afdd1dfc99c63b6 (diff)
Provide better implementation of localeconv and fix logic error in allocate
This allocates more space to the structure returned by localeconv. This fixes an error caused by some locale functions (specifically moneypunct_byname::init trying to access members of the lconv struct beyond the first and dereferencing invalid pointers. This also fixes a bug in allocate() which occurred when allocating a single-typed array of data of type size greater than one byte. The function had been incrementing its index into the array by the byte size, causing it to skip elements in arrays of larger type sizes. Fixes issue #2134.
-rw-r--r--src/library.js2
-rw-r--r--src/preamble.js16
2 files changed, 10 insertions, 8 deletions
diff --git a/src/library.js b/src/library.js
index c1eb2219..698763b6 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6443,7 +6443,7 @@ LibraryManager.library = {
// var indexes = Runtime.calculateStructAlignment({ fields: ['i32', 'i32'] });
var me = _localeconv;
if (!me.ret) {
- me.ret = allocate([allocate(intArrayFromString('.'), 'i8', ALLOC_NORMAL)], 'i8*', ALLOC_NORMAL); // just decimal point, for now
+ me.ret = allocate([allocate(intArrayFromString('.'), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL),allocate(intArrayFromString(''), 'i8', ALLOC_NORMAL)], 'i8*', ALLOC_NORMAL); // Allocate strings in lconv, still don't allocate chars
}
return me.ret;
},
diff --git a/src/preamble.js b/src/preamble.js
index 1c9de066..0be5b4de 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -529,17 +529,18 @@ function allocate(slab, types, allocator, ptr) {
}
#endif
- var i = 0, type, typeSize, previousType;
- while (i < size) {
- var curr = slab[i];
+ var index = 0, byteIndex = 0, type, typeSize, previousType;
+ while ((singleType ? index : byteIndex) < size) {
+ var curr = slab[index];
if (typeof curr === 'function') {
curr = Runtime.getFunctionIndex(curr);
}
- type = singleType || types[i];
+ type = singleType || types[byteIndex];
if (type === 0) {
- i++;
+ index++;
+ byteIndex++;
continue;
}
#if ASSERTIONS
@@ -550,14 +551,15 @@ function allocate(slab, types, allocator, ptr) {
if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later
#endif
- setValue(ret+i, curr, type);
+ setValue(ret+byteIndex, curr, type);
// no need to look up size unless type changes, so cache it
if (previousType !== type) {
typeSize = Runtime.getNativeTypeSize(type);
previousType = type;
}
- i += typeSize;
+ index++;
+ byteIndex += typeSize;
}
return ret;