diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-04-30 12:32:20 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-04-30 12:32:20 (GMT) |
commit | 75eea66ef7e21fd307cd4a2173b04548f7f8b096 (patch) | |
tree | a6323486420cef359533b0b3f9d83db5a9c01592 | |
parent | e3135827263e4945deb81a0ea513a26b6cab5c67 (diff) | |
parent | 251211e7146a1933fbd056fae33d61ec9c3bd327 (diff) | |
download | tcl-75eea66ef7e21fd307cd4a2173b04548f7f8b096.zip tcl-75eea66ef7e21fd307cd4a2173b04548f7f8b096.tar.gz tcl-75eea66ef7e21fd307cd4a2173b04548f7f8b096.tar.bz2 |
Add testcase for TclGetBytesFromObj()
-rw-r--r-- | generic/tclTest.c | 17 | ||||
-rw-r--r-- | tests/binary.test | 4 |
2 files changed, 18 insertions, 3 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c index 9388110..d615d8b 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -5677,7 +5677,14 @@ TestbytestringObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* The argument objects. */ { - Tcl_Size n = 0; + 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) { @@ -5685,11 +5692,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..2984fec 100644 --- a/tests/binary.test +++ b/tests/binary.test @@ -20,6 +20,7 @@ catch [list package require -exact tcl::test [info patchlevel]] testConstraint bigEndian [expr {$tcl_platform(byteOrder) eq "bigEndian"}] testConstraint littleEndian [expr {$tcl_platform(byteOrder) eq "littleEndian"}] testConstraint testbytestring [llength [info commands testbytestring]] +testConstraint pointerIs64bit [expr {$tcl_platform(pointerSize) >= 8}] # Big test for correct ordering of data in [expr] proc testIEEE {} { @@ -3039,6 +3040,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 -constraints pointerIs64bit -body { + testbytestring [string repeat A [expr 2**31]] +} -returnCodes 1 -result "byte sequence length exceeds INT_MAX" # ---------------------------------------------------------------------- # cleanup |