Open shannona opened 7 years ago
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
txtest1xyv2xzyqqqm5tyketyke txtest1xyv2xzyqqqmqqmqetyke
The encode code produces different results depending on whether it's been compiled with an optimized flag or not.
Optimized:
Non-Optimized:
The optimized results are the correct ones.
The non-optimized bug occurs in the hyphenation memcopy codes, starting with this line:
The problem seems to occur due to the overlapping copy.
Here's the results of that line:
Optimized
Non-Optimized: