Skip to content

Static code analysis _046 (Cast Alters Value - priority1) #70

@PawelModrzejewski

Description

@PawelModrzejewski

Short summary (details in attached file):

GptpIniParser::iniCallBack()
.../common/gptp_cfg.cpp

    if( parseMatch(name, "priority1") )
    {
        errno = 0;
        char *pEnd;
        unsigned char p1 = (unsigned char) strtoul(value, &pEnd, 10);
        if( *pEnd == '\0' && errno == 0) {
            valOK = true;
            parser->_config.priority1 = p1;
        }
    }

strtoul(value, &pEnd, 10) could be 256 or higher.
Values 256 or higher cannot be stored as unsigned char.  Casting them to unsigned char can cause data loss or sign change.

gptp_046.txt

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