Skip to content

Commit

Permalink
In Tcl_GetNumberFromObj() change the dictionary length check from > 1…
Browse files Browse the repository at this point in the history
… to > 0 to

determine whether the value can be parsed as a number, and make corresponding
changes in tclObj.c and expr.test.
  • Loading branch information
pooryorick committed Oct 7, 2024
1 parent 96477e3 commit aa4357d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion generic/tclExecute.c
Original file line number Diff line number Diff line change
Expand Up @@ -9112,7 +9112,7 @@ IllegalExprOperandType(
Tcl_Size length;
if (TclHasInternalRep(opndPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, opndPtr, &length);
if (length > 1) {
if (length > 0) {
listRep:
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"cannot use a list as %soperand of \"%s\"", ord, op));
Expand Down
2 changes: 1 addition & 1 deletion generic/tclObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@ Tcl_GetNumberFromObj(
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 1) {
if (length > 0) {
listRep:
if (interp) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("expected number but got a list", -1));
Expand Down
2 changes: 1 addition & 1 deletion tests/expr.test
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ test expr-11.15 {CompileAddExpr: runtime error} {
} {1 {cannot use non-numeric string "1 2 3" as left operand of "+"}}
test expr-11.16 {CompileAddExpr: runtime error} {
list [catch {expr {~[dict create foo bar]}} msg] $msg
} {1 {cannot use non-numeric string "foo bar" as operand of "~"}}
} {1 {cannot use a list as operand of "~"}}

test expr-12.1 {CompileMultiplyExpr: just unary expr} {expr ~4} -5
test expr-12.2 {CompileMultiplyExpr: just unary expr} {expr --5} 5
Expand Down

0 comments on commit aa4357d

Please sign in to comment.