Skip to content
Tcl Source Code View Ticket
Login

View Ticket

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.