Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[string compare] EIAS violation

Closed / Fixed4c591fa4875b64fe29ff0c65be3902c28424797dCreated 7 years agoUpdated 6 years ago
Descriptionplain2020-04-30 19:30:11
% set one \uFFFF
￿
% set two \U10000
𐀀
% string compare $one $two
-1
% string range $one 0 0
￿
% string range $two 0 0
𐀀
% string compare $one $two
1
Referenced by4
  • ecc384092cClosed ticket [e617e8a71a]: comparing UTF-16 strings doesn't account for surrogates plus 7 other changes ticket2021-04-07 12:49:18
  • 1b0eda88ccRepair Tcl_UniCharNcasecmp() in the same way as Tcl_UniCharNcmp() for fix [4c591fa487]. Also put back minor optimization for big-endian machines removed in the previous commit check-in2021-03-10 16:12:01
  • 6a5a5e21f1Fix [4c591fa487]: [string compare] EIAS violation check-in2021-03-10 15:39:15
  • e8392cb8bdTest for [4c591fa487]. check-in2020-04-30 20:32:38
dgpplain2020-04-30 19:43:19
% set one \uFFFF; tcl::unsupported::representation $one
value is a pure string with a refcount of 4, object pointer at 0xe092870, string representation "￿"
% set two \U10000; tcl::unsupported::representation $two
value is a pure string with a refcount of 4, object pointer at 0xe08e8b0, string representation "𐀀"
% string compare $one $two
-1
% string range $one 0 0; tcl::unsupported::representation $one
value is a string with a refcount of 2, object pointer at 0xe092870, internal representation 0xe0c9090:0x0, string representation "￿"
% string range $two 0 0; tcl::unsupported::representation $two
value is a string with a refcount of 2, object pointer at 0xe08e8b0, internal representation 0xd81a350:0x0, string representation "𐀀"
% string compare $one $two
1

The comparison routines TclpUtfNcmp2() and (deprecated) Tcl_UniCharNcmp()
do not agree.
dgpplain2020-04-30 21:54:19
The simplest approach would be to eliminate the internal calls
to the deprecated routine Tcl_UniCharNcmp().  Then all compares
would route through the same routine and get consistent results.

Two problems with that.

1) The "Unicode" internal rep was invented because performance
of some tasks was impossibly terrible without it. We risk bringing that back.

2) We end up with a [string compare -length ] command that counts
its lengths by characters while things like [string length] still count
by UTF-16 units which make combining these commands correctly
quite tricky.  Once we open this door even a little bit, I think we will
not be happy until all lengths and indexing operate on characters
and not code units.
jan.nijtmanswiki2021-03-10 15:50:08

Fixed in all branches now.

Thanks, Don, for discovering this!

Log in (anonymous is fine) to add a comment.