Skip to content

Commit

Permalink
fix vm_pop_type for big-endian systems
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adrian-thurston committed Jan 18, 2021
1 parent 3a58232 commit 472a890
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 472a890

Please sign in to comment.