Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #574

Open
Mira-Fr opened this issue Oct 23, 2022 · 0 comments
Open

Bug #574

Mira-Fr opened this issue Oct 23, 2022 · 0 comments
Assignees
Labels
bug A bug in the previous version that needs fixing investigating Issue is under investigation

Comments

@Mira-Fr
Copy link
Collaborator

Mira-Fr commented Oct 23, 2022

in this function:

const char* toStringBuildTypeSpecificType(const eBuildType &buildType, const int &specificTypeId) {
    std::cout << "ID " << specificTypeId << std::endl;
    switch (buildType) {
        case eBuildType::SPECIAL:
            std::cout << "SPECIAL"  << std::endl;
            return sSpecialInfo[specificTypeId].description;
        case eBuildType::UNIT:
            return sUnitInfo[specificTypeId].name;
        case eBuildType::STRUCTURE:
            return sStructureInfo[specificTypeId].name;
        case eBuildType::BULLET:
            return sBulletInfo[specificTypeId].description;
        case eBuildType::UPGRADE:
            return sUpgradeInfo[specificTypeId].description;
        case eBuildType::UNKNOWN:
            return std::string("Unknown");
        default:
            assert(false && "Undefined buildType?");
            break;
    }
    return "";
}

You shall not have specificTypeId=-1 and eBuildType::SPECIAL because you read after sSpecialInfo[specificTypeId].description
sSpecialInfo is a tab so -1 is an unauthorised index

but the program do it without crash !!!

I read the debug log:
4409|WARN|NONE|cGameEvent [type=GAME_EVENT_SPICE_BLOOM_SPAWNED], [entityType=SPECIAL], [entityId=-1], [entitySpecificType=-1 =], [isReinforce=false], [atCell=2891], [buildingListItem=nullptr] [originId=-1]|(logbook)

I see [entitySpecificType=-1 =] and the description is passed on trap !

I should read [entitySpecificType=-1 =DESCRIPTION_HERE]

description is a char[64]


On another branch, i changed description to be a std::string and no char[64] and it is a drama:

When specificTypeId=-1 and eBuildType::SPECIAL the program cannot read sSpecialInfo[specificTypeId].description
because -1 is an unauthorised index and the program crash.

It's logical.


Why on master branch, the program doesn't crash when I call a tab with index -1 ?

Who can help me to patch his insoluble problem for me ?
(where is the link about GAME_EVENT_SPICE_BLOOM_SPAWNED and entityType=SPECIAL not Unknown ?

@Mira-Fr Mira-Fr added bug A bug in the previous version that needs fixing investigating Issue is under investigation labels Oct 23, 2022
@Mira-Fr Mira-Fr self-assigned this Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in the previous version that needs fixing investigating Issue is under investigation
Projects
None yet
Development

No branches or pull requests

1 participant