Skip to content

Commit

Permalink
Don't leak local variables between switch branches
Browse files Browse the repository at this point in the history
Declaring and initializing a local variable in one `switch` branch, then
using that same local variable in a different `switch` branch, is legal
but confusing.  Even more so if the first switch branch returns rather
than falling through.  Let's just not do that.
  • Loading branch information
liblit committed Sep 22, 2024
1 parent a8bde31 commit 38c41b7
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions dalvik/src/main/java/com/ibm/wala/dalvik/classLoader/DexUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,23 @@ static ElementValue getValue(ClassLoaderReference clr, EncodedValue v) {
return new ConstantElementValue(d);

case ENUM:
org.jf.dexlib2.iface.reference.FieldReference o = ((EnumEncodedValue) v).getValue();
return new EnumElementValue(o.getType(), o.getName());
{
org.jf.dexlib2.iface.reference.FieldReference o = ((EnumEncodedValue) v).getValue();
return new EnumElementValue(o.getType(), o.getName());
}

case FIELD:
o =
v.getValueType() == ENUM
? ((EnumEncodedValue) v).getValue()
: ((FieldEncodedValue) v).getValue();
String fieldName = o.getName();
TypeReference ft = getTypeRef(o.getType(), clr);
TypeReference ct = getTypeRef(o.getDefiningClass(), clr);
return new ConstantElementValue(
FieldReference.findOrCreate(ct, Atom.findOrCreateUnicodeAtom(fieldName), ft));
{
org.jf.dexlib2.iface.reference.FieldReference o =
v.getValueType() == ENUM
? ((EnumEncodedValue) v).getValue()
: ((FieldEncodedValue) v).getValue();
String fieldName = o.getName();
TypeReference ft = getTypeRef(o.getType(), clr);
TypeReference ct = getTypeRef(o.getDefiningClass(), clr);
return new ConstantElementValue(
FieldReference.findOrCreate(ct, Atom.findOrCreateUnicodeAtom(fieldName), ft));
}

case FLOAT:
Float f = ((FloatEncodedValue) v).getValue();
Expand All @@ -152,7 +156,7 @@ static ElementValue getValue(ClassLoaderReference clr, EncodedValue v) {

case METHOD:
org.jf.dexlib2.iface.reference.MethodReference m = ((MethodEncodedValue) v).getValue();
ct = getTypeRef(m.getDefiningClass(), clr);
TypeReference ct = getTypeRef(m.getDefiningClass(), clr);
String methodName = m.getName();
String methodSig = getSignature(m);
return new ConstantElementValue(
Expand Down

0 comments on commit 38c41b7

Please sign in to comment.