From e393e2694c359e49514346cb90569a0d19a43000 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 29 Apr 2023 16:10:56 +0000 Subject: Add experimental testcase for TclGetBytesFromObj() --- generic/tclTest.c | 13 ++++++++++--- tests/binary.test | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 9388110..5f8d1f5 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -5677,7 +5677,10 @@ TestbytestringObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* The argument objects. */ { - Tcl_Size n = 0; + struct { + int n; /* On purpose, not Tcl_Size, in order to demonstrate what happens */ + int m; /* This variable should not be overwritten */ + } x = {0, 1}; const char *p; if (objc != 2) { @@ -5685,11 +5688,15 @@ 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", 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 a947410..940de47 100644 --- a/tests/binary.test +++ b/tests/binary.test @@ -3039,6 +3039,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 -returnCodes 1 -body { + testbytestring [string repeat A [expr 2**31]] +} -result "byte sequence length exceeds INT_MAX" # ---------------------------------------------------------------------- # cleanup -- cgit v0.12 From 251211e7146a1933fbd056fae33d61ec9c3bd327 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 30 Apr 2023 12:02:38 +0000 Subject: Don't test compatibility macro's when TCL_NO_DEPRECATED is defined: this is expected to fail --- generic/tclTest.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generic/tclTest.c b/generic/tclTest.c index 5f8d1f5..d615d8b 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -5678,7 +5678,11 @@ TestbytestringObjCmd( Tcl_Obj *const objv[]) /* The argument objects. */ { 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; -- cgit v0.12