summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclTest.c19
-rw-r--r--tests/binary.test3
2 files changed, 19 insertions, 3 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 968556b..6db99c9 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -15,6 +15,7 @@
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
+#define TCL_8_API
#undef BUILD_tcl
#undef STATIC_BUILD
#ifndef USE_TCL_STUBS
@@ -5762,7 +5763,14 @@ TestbytestringObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* The argument objects. */
{
- Tcl_Size n;
+ struct {
+#if !defined(TCL_NO_DEPRECATED)
+ int n; /* On purpose, not Tcl_Size, in order to demonstrate what happens */
+#else
+ Tcl_Size n;
+#endif
+ int m; /* This variable should not be overwritten */
+ } x = {0, 1};
const char *p;
if (objc != 2) {
@@ -5770,11 +5778,16 @@ TestbytestringObjCmd(
return TCL_ERROR;
}
- p = (const char *)Tcl_GetBytesFromObj(interp, objv[1], &n);
+ p = (const char *)Tcl_GetBytesFromObj(interp, objv[1], &x.n);
if (p == NULL) {
return TCL_ERROR;
}
- Tcl_SetObjResult(interp, Tcl_NewStringObj(p, n));
+
+ if (x.m != 1) {
+ Tcl_AppendResult(interp, "Tcl_GetBytesFromObj() overwrites variable", (void *)NULL);
+ return TCL_ERROR;
+ }
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(p, x.n));
return TCL_OK;
}
diff --git a/tests/binary.test b/tests/binary.test
index d6a8195..299e1e0 100644
--- a/tests/binary.test
+++ b/tests/binary.test
@@ -3048,6 +3048,9 @@ test binary-80.3 {Tcl_GetBytesFromObj} -constraints testbytestring -returnCodes
test binary-80.4 {Tcl_GetBytesFromObj} -constraints testbytestring -returnCodes 1 -body {
testbytestring [testbytestring "\xC0\x80\xA0\xA0\xA0\xF0\x9F\x98\x81"]
} -result "expected byte sequence but character 4 was '\U01F601' (U+01F601)"
+test binary-80.5 {Tcl_GetBytesFromObj} -constraints {testbytestring pointerIs64bit deprecated} -body {
+ testbytestring [string repeat A [expr 2**31]]
+} -returnCodes 1 -result "byte sequence length exceeds INT_MAX"
# ----------------------------------------------------------------------
# cleanup