looking at how this code is used, when possibly-invalid values for part are passed in, the caller checks for a NULL return.  However, this function does not behave that way, and instead just accesses invalid array indices.  Fixed so behaviour corresponds to usage.  gcc found this error from its usage in Pathfinding.cpp