Skip to content

nullptr cannot be assigned to std::string #19615

@JohnCoconut

Description

@JohnCoconut

cocos2d-x version: master branch

In cocos/editor-support/cocostudio/CCBone.cpp

bool Bone::init()
{
    return Bone::init(nullptr);
}


bool Bone::init(const std::string& name)
{
    ....
}

The first overload calls the second overload with std::string set to nullptr. It's undefined behaviour.

The following program will crash at runtime (https://wandbox.org/permlink/3LOds99d8umEIGHm)

#include <iostream>
#include <string>

int main() {
    std::string s = nullptr;
    std::cout << s << std::endl;
    return 0;
}

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