-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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 ;-)