diff options
author | Adrian Thurston <thurston@colm.net> | 2021-01-18 11:25:45 -0800 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2021-01-18 11:28:04 -0800 |
commit | 472a89059b9bec9f40f54d7ed5c312786c69198c (patch) | |
tree | eeab104d5781a7a774f8f274a2f1c5a8b97f0e73 /src | |
parent | 3a5823247def2a3638c2fb91fc761be0396e5303 (diff) | |
download | colm-472a89059b9bec9f40f54d7ed5c312786c69198c.tar.gz |
fix vm_pop_type for big-endian systems
Change the pop to cast the pointer and take the value using a pointer to the
requested type, then return that tmp.
Previously we were taking the value using the tree type, then casting the
value. During the cast of the value the high bits are dropped, and that's where
the value actually lives, when on a big-endian system. Didn't notice the
problem on little-endian systems because it happens to work fine there.
Fixes #126.
Diffstat (limited to 'src')
-rw-r--r-- | src/bytecode.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/bytecode.h b/src/bytecode.h index 9d443fe5..ff626bba 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -518,7 +518,7 @@ enum LEL_ID { ( ( (sp-(n)) < prg->sb_beg ? (sp = vm_bs_add(prg, sp, n)) : 0 ), (sp -= (n)) ) #define vm_pop_type(type) \ - ({ SW r = *sp; (sp+1) >= prg->sb_end ? (sp = vm_bs_pop(prg, sp, 1)) : (sp += 1); (type)r; }) + ({ type r = *((type*)sp); (sp+1) >= prg->sb_end ? (sp = vm_bs_pop(prg, sp, 1)) : (sp += 1); r; }) #define vm_push_tree(i) vm_push_type(tree_t*, i) #define vm_push_input(i) vm_push_type(input_t*, i) |