8

Bouncy Castle

 3 years ago
source link: https://hownot2code.com/2020/11/30/bouncy-castle/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How Not To Code

C, C++, C#, Java bad practices: learn how to make a good code by bad example

Skip to content

Search
The Legion of the Bouncy Castle

Unreachable code

public void testSignSHA256CompleteEvenHeight2() {
    ....
    int height = 10;
    ....
    for (int i = 0; i < (1 << height); i++) {
        byte[] signature = xmss.sign(new byte[1024]);
        switch (i) {
            case 0x005b:
                assertEquals(signatures[0], Hex.toHexString(signature));
                break;
            case 0x0822:
                assertEquals(signatures[1], Hex.toHexString(signature));
                break;
            ....
        }
    }
}

V6019 Unreachable code detected. It is possible that an error is present. XMSSTest.java(170)

The value of the height variable in the method does not change, so the icounter in the for loop can’t be greater than 1024 (1 << 10). However, in the switch statement, the second case checks i for the value 0x0822 (2082). Obviously, the signatures[1] byte will never be checked.

Since this is the code of the test method, there is nothing wrong here. Developers just need to pay attention to the fact that one of bytes is never tested.

Please click here to see more bugs from this project.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK