summaryrefslogtreecommitdiff
path: root/src/lj_cdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_cdata.c')
-rw-r--r--src/lj_cdata.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lj_cdata.c b/src/lj_cdata.c
index af78d05e..ae66b4b5 100644
--- a/src/lj_cdata.c
+++ b/src/lj_cdata.c
@@ -88,7 +88,10 @@ collect_attrib:
88 } 88 }
89 lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */ 89 lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */
90 90
91 if (tvisnum(key)) { /* Numeric key. */ 91 if (tvisint(key)) {
92 idx = (ptrdiff_t)intV(key);
93 goto integer_key;
94 } else if (tvisnum(key)) { /* Numeric key. */
92 idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key)); 95 idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key));
93 integer_key: 96 integer_key:
94 if (ctype_ispointer(ct->info)) { 97 if (ctype_ispointer(ct->info)) {
@@ -171,10 +174,10 @@ static void cdata_getconst(CTState *cts, TValue *o, CType *ct)
171 CType *ctt = ctype_child(cts, ct); 174 CType *ctt = ctype_child(cts, ct);
172 lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4); 175 lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4);
173 /* Constants are already zero-extended/sign-extended to 32 bits. */ 176 /* Constants are already zero-extended/sign-extended to 32 bits. */
174 if (!(ctt->info & CTF_UNSIGNED)) 177 if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0)
175 setintV(o, (int32_t)ct->size);
176 else
177 setnumV(o, (lua_Number)(uint32_t)ct->size); 178 setnumV(o, (lua_Number)(uint32_t)ct->size);
179 else
180 setintV(o, (int32_t)ct->size);
178} 181}
179 182
180/* Get C data value and convert to TValue. */ 183/* Get C data value and convert to TValue. */