Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-05-05
06:55 • Closed ticket [9899c273ab]: Tcl_InitStringRep design issues plus 5 other cha... artifact: abf812b74a user: jan.nijtmans
2025-05-02
12:09 • Ticket [9899c273ab]: 3 changes artifact: f54d95232f user: jan.nijtmans
11:59 • Ticket [9899c273ab]: 4 changes artifact: b66748ef88 user: oehhar
10:49 • Ticket [9899c273ab]: 4 changes artifact: 577c42bc63 user: oehhar
10:37 • Ticket [9899c273ab]: 3 changes artifact: 032363e771 user: jan.nijtmans
10:36
Proposed fix for [9899c2]: Tcl_InitStringRep design issues. Since this introduces a new Tcl_Attempt... closed check-in: e9231a4d4b user: jan.nijtmans tags: mistake
09:53 • Open ticket [9899c273ab]: Tcl_InitStringRep design issues plus 4 other chang... artifact: 3a679273e4 user: jan.nijtmans
2021-11-08
00:13 • Closed ticket [9899c273ab]. artifact: 1a875e99ba user: dgp
00:06
[9899c273ab] Rewrite Tcl_InitStringRep to account for all encounters with the non-allocated empty st... check-in: e7511df3a1 user: dgp tags: core-8-branch
2021-10-28
15:20 • New ticket [9899c273ab] Tcl_InitStringRep design issues. artifact: c3c6cedc50 user: dgp

Tcl_InitStringRep design issues

Closed / Fixed9899c273abcb1830ec7d217f577765b1db336f83Created 5 years agoUpdated 2 years ago
Descriptionplain2021-10-28 15:20:04
This can lead to an invalid ckrealloc call:

Tcl_InitStringRep(objPtr, NULL, 0);
Tcl_InitStringRep(objPtr, NULL, 0);

Also, there's nothing in place to detect when a truncation
call does not actually truncate, and to deal with possible
memory allocation failure in that circumstance.
Referenced by1
  • e7511df3a1[9899c273ab] Rewrite Tcl_InitStringRep to account for all encounters with the non-allocated empty string rep. check-in2021-11-08 00:06:27
dgpplain2021-11-08 00:13:58
Fix committed.
jan.nijtmanswiki2025-05-02 09:53:40

It looks like this 'redesign' is only partially done.

Yes, Tcl_InitStringRep can now handle allocation failures by returning NULL, but many callers of this function don't check for the NULL value. In other words: Tcl_InitStringRep() behaves like Tcl_AttemptInitStringRep(). This is OK, but callers should translate this NULL to either a panic or a proper error-handling.

I'll have a look.

jan.nijtmanswiki2025-05-02 10:37:19

Proposed further fix [here]

Needs a TIP

oehharwiki2025-05-02 10:49:01

I think, the new "Attempt" series is a good idea. It is backward compatible and cleans-up a big drawback, that a library may not act on a memory issue.

In the idea of a library, a panic should never happen, but always, an error should be reported...

I can understand that cleaning this up in TCL and friends is a big task, as the error path is just often not there.

It is a bit like "encoding now throws an error". New error path - many hidden issues.

Thanks for going this way, Harald

oehharwiki2025-05-02 11:59:07

See ticket [78f44214]. This command is undocumented in the docs. But the introducing TIP documented the NULL return on memory error.

It might be ok to do so and not to add an Attempt version of it.

Harald

jan.nijtmansplain2025-05-02 12:09:47
> It might be ok to do so and not to add an Attempt version of it

Yeah, better fix the callers then.

Thanks!
         Jan Nijtmans
jan.nijtmanswiki2025-05-05 06:55:21

I think [this] fixes all callers.

Closing

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