Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Changes to Tcl_GetByteArrayFromObj not correct?

Closed / Fixed14680527328fdcadb5e558c998621d28eb607db4Created 3 years agoUpdated 3 years ago
Descriptionplain2023-09-25 17:34:13
Checkin b680b1f0b3 changes stub entry 33 from

unsigned char *TclGetByteArrayFromObj(Tcl_Obj *objPtr, void *numBytesPtr)

to

unsigned char *Tcl_GetByteArrayFromObj(Tcl_Obj *objPtr, int *numBytesPtr)

It also removes the previous declaration of Tcl_GetByteArrayFromObj: 
declare 653 {
    unsigned char *Tcl_GetByteArrayFromObj(Tcl_Obj *objPtr, Tcl_Size *numBytesPtr)
}

Shouldn't parameter numBytesPtr in entry 33 be a Tcl_Size* instead of int* ?

Regards,
Paul
Referenced by4
  • c3520a6df6Merge [a62b8faa1ff43efe]. Prevent TclGetByteArrayFromObj() et al being called directly through the stub table. See (hijacked) ticket [1468052732]. check-in2024-08-22 15:03:22
  • 4c35b89a32merge [35a5f655f5b9e16e]: Make last argument of Tcl_GetByteArrayFromObj() "Tcl_Size *" in stead of "int". Is exactly the same in 8.7, and reduces confusion in 9.0. See [1468052732] check-in2024-08-22 14:55:30
  • a62b8faa1fPrevent TclGetByteArrayFromObj() et al being called directly through the stub table. See (hijacked) ticket [1468052732] check-in2023-09-25 20:01:16
  • 50791c1b1dMake last argument of Tcl_GetByteArrayFromObj() "Tcl_Size *" in stead of "int". Is exactly the same in 8.7, and reduces confusion in 9.0. See [1468052732] check-in2023-09-25 18:24:52
apnadkarniplain2023-09-25 18:06:30
Along the same lines (but not part of same commit), in Tcl 9 the current definition of Stub 41 is 

```
declare 41 {
    char *TclGetStringFromObj(Tcl_Obj *objPtr, void *lengthPtr)
}
```

However, TclGetStringFromObj **always** treats lengthPtr as an `int *`. Thus following a "conflict-free" merge from core-8-branch, the following fragment caused a crash.

```
Tcl_Size len;
const char *path = TclGetStringFromObj(normPathPtr, &len);
...
path[len-1] = '\0';
```

because only the low four bytes of `len` were updated by the TGSFO call.

Either Stub 41 should be removed, or defined as taking an `int*` so that compiler will catch these errors. The way it is currently defined serves no utility afaict but I'm wary of changing it myself in case there is some use I don't see.

Alternately, define it as taking an `Tcl_Size *` and name it as `Tcl_GetStringFromObj` replacing stub 651.
jan.nijtmanswiki2023-09-25 18:42:12

> Either Stub 41 should be removed, or defined as taking an `int*` so that compiler will catch these errors. The way it is currently defined serves no utility afaict but I'm wary of changing it myself in case there is some use I don't see.

The use for this function is here. It isn't meant to be called directly by extensions.

I would prefer your example code snippet to produce a compiler error, I'll think about it how to do that.

Anyway, I don't like it when you hijack an unrelated ticket .....

Closing (since changing "int *" to "Tcl_Size *" was a good idea, reduces confusion

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