Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Produces Different Results Depending on If It's Compiled Optimized #2

Open
shannona opened this issue Jul 14, 2017 · 0 comments
Open

Comments

@shannona
Copy link

The encode code produces different results depending on whether it's been compiled with an optimized flag or not.

Optimized:

$ cc -O2 txid2bech32.c txref_code.c segwit_addr.c -lbitcoinrpc -ljansson -o txid2bech32
$ ./txid2bech32 f8cdaff3ebd9e862ed5885f8975489090595abe1470397f79780ead1c7528107
Txref: txtest1-xyv2-xzyq-qqm5-tyke

Non-Optimized:

$ cc txid2bech32.c txref_code.c segwit_addr.c -lbitcoinrpc -ljansson -o txid2bech32
$ ./txid2bech32 f8cdaff3ebd9e862ed5885f8975489090595abe1470397f79780ead1c7528107
Txref: txtest1-xxyv-xzxz-qqmq-tyke

The optimized results are the correct ones.

The non-optimized bug occurs in the hyphenation memcopy codes, starting with this line:

memcpy(output+olen-5, output+olen-8, 4);

The problem seems to occur due to the overlapping copy.

Here's the results of that line:

Optimized

txtest1xyv2xzyqqqm5tyketyke
txtest1xyv2xzyqqqmqqm5etyke

Non-Optimized:

txtest1xyv2xzyqqqm5tyketyke
txtest1xyv2xzyqqqmqqmqetyke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant