Skip to content

This value is already assigned to the 'proxy1' variable #2

@mokalux

Description

@mokalux

I came accross this website and you may find it useful.

https://pvs-studio.com/en/blog/posts/java/1113/

Looking for errors jMonkeyEngine, one example:

@OverRide
public BroadphasePair findPair(BroadphaseProxy proxy0, BroadphaseProxy proxy1) {
BulletStats.gFindPairs++;
if (proxy0.getUid() > proxy1.getUid()) {
BroadphaseProxy tmp = proxy0;
proxy0 = proxy1;
proxy1 = proxy0; // <=
}
....
}

It seems like the developer has messed something up here. Even the analyzer issued the following:

After looking at the original library source code, I learned that the current error was made only in the Java port. In the original code, a function called b3Swap is used for elements. Let's take a look at it:

template
B3_FORCE_INLINE void b3Swap(T &a, T &b)
{
T tmp = a;
a = b;
b = tmp;
}

Given the C++ implementation we've already seen, we can easily find a way to fix the error:

@OverRide
public BroadphasePair findPair(BroadphaseProxy proxy0, BroadphaseProxy proxy1) {
BulletStats.gFindPairs++;
if (proxy0.getUid() > proxy1.getUid()) {
BroadphaseProxy tmp = proxy0;
proxy0 = proxy1;
proxy1 = tmp;
}
....
}

Hope this helps ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions