Skip to content

SvFromTclObj(): unreachable code uses invalid internalRep #47

Closed
@chrstphrchvz

Description

@chrstphrchvz

In this code which appeared in 323f8e1:

tcl.pm/Tcl.xs

Lines 566 to 579 in 4067e75

else if (objPtr->typePtr == tclBooleanTypePtr) {
/*
* Booleans can originate as words (yes/true/...), so if there is a
* string rep, use it instead. We could check if the first byte
* isdigit(). No need to check utf-8 as the all valid boolean words
* are ascii-7.
*/
if (objPtr->typePtr == NULL) {
sv = newSVsv(boolSV(objPtr->internalRep.longValue != 0));
} else {
str = Tcl_GetStringFromObj(objPtr, &len);
sv = newSVpvn(str, len);
}
}

The statement

sv = newSVsv(boolSV(objPtr->internalRep.longValue != 0));

is unreachable (assuming tclBooleanTypePtr != NULL). It also does not make sense for the statement to be using objPtr->internalRep because it is invalid when objPtr->typePtr == NULL.

I am still trying to understand how this code is intended to work. I may propose changes to it anyway in #42 due to various other issues in SvFromTclObj() which I encounter in Tcl 9.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions