Skip to content

Commit 10a25ad

Browse files
author
jan.nijtmans
committed
[2a0a834022]: pixel values can report false list lengths
1 parent 3b7468d commit 10a25ad

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

changes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ to the userbase.
3232
- [nanosvg upstream changes: #273, #275: add paint order parsing](https://core.tcl-lang.org/tk/tktview/b43dbc0061)
3333
- [Artifacts in a few themed widgets on x11 and aqua](https://core.tcl-lang.org/tk/tktview/265ff2)
3434
- [Core dump Tk_GetFontFromObj](https://core.tcl-lang.org/tk/tktview/a80e5f)
35-
- [MS-Win canvas arcs with small extent are drawn 360 dregrees](https://core.tcl-lang.org/tk/info/6051a9fc)
35+
- [MS-Win canvas arcs with small extent are drawn 360 dregrees](https://core.tcl-lang.org/tk/info/6051a9)
36+
- [pixel values can report false list lengths](https://core.tcl-lang.org/tk/info/2a0a83)
3637

3738
Release Tk 9.0.2 arises from the check-in with tag `core-9-0-2`.
3839

generic/tkObj.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ static void UpdateStringOfMM(Tcl_Obj *objPtr);
9191
static int SetMMFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
9292
static int SetPixelFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
9393
static int SetWindowFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
94+
static Tcl_Size LengthOneOrTwo(Tcl_Obj *objPtr);
95+
9496

9597
/*
9698
* The following structure defines the implementation of the "pixel" Tcl
@@ -104,7 +106,7 @@ static const TkObjType pixelObjType = {
104106
DupPixelInternalRep, /* dupIntRepProc */
105107
NULL, /* updateStringProc */
106108
NULL, /* setFromAnyProc */
107-
TCL_OBJTYPE_V1(TkLengthOne)},
109+
TCL_OBJTYPE_V1(LengthOneOrTwo)},
108110
0
109111
};
110112

@@ -127,7 +129,7 @@ static const TkObjType mmObjType = {
127129
DupMMInternalRep, /* dupIntRepProc */
128130
UpdateStringOfMM, /* updateStringProc */
129131
NULL, /* setFromAnyProc */
130-
TCL_OBJTYPE_V1(TkLengthOne)},
132+
TCL_OBJTYPE_V1(LengthOneOrTwo)},
131133
0
132134
};
133135

@@ -146,6 +148,35 @@ static const TkObjType windowObjType = {
146148
0
147149
};
148150

151+
/*
152+
*----------------------------------------------------------------------
153+
*
154+
* LengthOneOrTwo --
155+
*
156+
* Determine the length of a "pixel" or "mm". It returns 2 if there is any
157+
* space between the float and the 'c', 'i', 'm' or 'p', 1 otherwise.
158+
*
159+
*----------------------------------------------------------------------
160+
*/
161+
Tcl_Size
162+
LengthOneOrTwo(
163+
Tcl_Obj *objPtr)
164+
{
165+
if (objPtr->bytes) {
166+
const char *p = objPtr->bytes + strlen(objPtr->bytes);
167+
while (strchr(" \f\n\r\t\v", *--p)) {
168+
// skip spacing at end;
169+
}
170+
if (strchr("cimp", *p)) {
171+
// Check whether character is preceded by space
172+
if (strchr(" \f\n\r\t\v", *--p)) {
173+
return 2;
174+
}
175+
}
176+
}
177+
return 1;
178+
}
179+
149180
/*
150181
*----------------------------------------------------------------------
151182
*

0 commit comments

Comments
 (0)