flaing / jnibwapi

Automatically exported from code.google.com/p/jnibwapi
0 stars 0 forks source link

Checking for BWAPI types in ***typeMap maps in the jni code will incorrectly fail if a type is zero #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Call to train:

JNIEXPORT void JNICALL Java_eisbot_proxy_JNIBWAPI_train(JNIEnv *env, jobject 
jObj, jint unitID, jint typeID){ 
    Unit* unit = Broodwar->getUnit(unitID);
    if (unit != NULL) {
        if (unitTypeMap[typeID] == NULL)
        {
            unit->train(unitTypeMap[typeID]);
        }
    }
}

What is the expected output? What do you see instead?
unit->train(unitTypeMap[typeID]) should be called if typeID is in unitTypeMap's 
keys.

Instead it will fail if the typeID is zero, as the BWAPI::UnitType returned 
from the map is being implicitly converted to an integer type (giving its 
typeID as an integer) to compare with NULL.

Fix:
JNIEXPORT void JNICALL Java_eisbot_proxy_JNIBWAPI_train(JNIEnv *env, jobject 
jObj, jint unitID, jint typeID){ 
    Unit* unit = Broodwar->getUnit(unitID);
    if (unit != NULL) {
        if (unitTypeMap.count(typeID) > 0)
        {
            unit->train(unitTypeMap[typeID]);
        }
    }
}

This bug is found in many places throughout the jni bridge wherever typeIDs are 
checked as being present in the respective type map, and will fail with a type 
ID of zero in the same way.

Original issue reported on code.google.com by Fobbah on 25 Oct 2011 at 5:14

GoogleCodeExporter commented 9 years ago
Issue 19 has been merged into this issue.

Original comment by Fobbah on 25 Oct 2011 at 5:15

GoogleCodeExporter commented 9 years ago
This issue has been fixed, pending verification.

Original comment by Fobbah on 25 Oct 2011 at 5:52