question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--removedeadswitchcases

See original GitHub issue

Imagine a switch like this:

      switch (1) {
      default: {
        return false;
      }
      case 1:
        return true;
      }

or

    switch (boolean) { //illegal in java, legal in bytecode
    case 0:
      return false;
    case 1:
      return true;
    case 2:
    case 3:
    case 4:
    ...
      //never executed, remove it from the graph
      //an obfuscator could convert ifeq / ifne to switch and then add redundant extra cases
      //imagine a goto random label for each extra case
    default:
      //also not executed if both cases are handled
    }

I think there can be done a lot of optimization / obfuscation removal. Also not bad for a second pass.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
leibnitz27commented, May 11, 2020

The former I can see as realistic, though I doubt anyone’s going to bother with an obfuscation so trivial. (Unless it’s @Marcono1234 generating psychotic switch expression examples)

The latter I’m really not keen on. We simply dont know at the bytecode level if something is a bool or not - you could declare it a bool parameter then assign 3 - while I try to infer the type/domain, it’s very possible to get it wrong.

(As an aside, abused booleans can lead to different results in different jvms, I have some tests somewhere I believe)

0reactions
leibnitz27commented, May 12, 2020

Ok - I’m going to close this for now. There’s potentially some value in trying to add a last gasp recovery pass to do this, but it’s certainly not the sort of thing you’d want to be doing normally.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dead code removal from switch cases in JavaScript
Nothing is going to definitively give you a list of dead case statements. If it says it can there is either no possibility...
Read more >
Removing duplicate cases in switch - Exakat
Duplicate cases are pure dead code (only one of them is actually used), or a bug (some of the case is misspelled, and...
Read more >
MSC07-C. Detect and remove dead code - Confluence
This noncompliant code example demonstrates how dead code can be introduced into a program [Fortify 2006]. The second conditional statement, if ...
Read more >
Bitter about how rubber switch cases stress out the joycons.
Do yourself a favor, get a clip on case so there's no stress on your joycons, otherwise you'll end up with joycon wiggling...
Read more >
Switch Statements - Refactoring.Guru
You have a complex switch operator or sequence of if statements. Reasons for the Problem. Relatively rare use of switch and case operators...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found