Skip to content

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

Description

@shannona

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions