Tcl Source Code

Changes On Branch bug-35a8f1c04a
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch bug-35a8f1c04a Excluding Merge-Ins

This is equivalent to a diff from 0ef0b36b31 to 94ad0517c5

2018-11-09
16:00
[35a8f1c04a] Fix bad lengths when creating string rep of some lists. check-in: b2575c74bc user: dgp tags: core-8-5-branch
15:47
Additional test Closed-Leaf check-in: 94ad0517c5 user: dgp tags: bug-35a8f1c04a
15:39
Revise bug fix to support (length == 0) correctly. Added comments and improved safety in caller. check-in: 3b0bc7a6e1 user: dgp tags: bug-35a8f1c04a
14:13
test case to cover bug [35a8f1c04a] check-in: d76fb9091b user: sebres tags: bug-35a8f1c04a
2018-11-08
17:07
merge mark check-in: 8ce43103f1 user: dgp tags: core-8-6-branch
17:05
[86d249bcba] Make sure that tcltest::runAllTests actually returns 1 on failure. Repairs TIP 525 Impl... check-in: 0ef0b36b31 user: dgp tags: core-8-5-branch
2018-11-07
18:56
[86d249bcba] Make sure that tcltest::runAllTests actually returns 1 on failure check-in: c09518b7e2 user: dkf tags: core-8-6-branch
2018-10-31
21:02
Make MacOSX compile work (hopefully) and cross-compile on mingw-w64 (compile only, no unit-test yet) check-in: cb351dea6a user: jan.nijtmans tags: core-8-5-branch

Changes to generic/tclListObj.c.

1868
1869
1870
1871
1872
1873
1874











1875



1876
1877
1878
1879
1880
1881
1882
1883



1884
1885
1886
1887
1888
1889
1890
1891
    }
    bytesNeeded += numElems;

    /*
     * Pass 2: copy into string rep buffer.
     */












    listPtr->length = bytesNeeded - 1;



    listPtr->bytes = ckalloc((unsigned) bytesNeeded);
    dst = listPtr->bytes;
    for (i = 0; i < numElems; i++) {
	flagPtr[i] |= ( i ? TCL_DONT_QUOTE_HASH : 0 );
	elem = TclGetStringFromObj(elemPtrs[i], &length);
	dst += TclConvertElement(elem, length, dst, flagPtr[i]);
	*dst++ = ' ';
    }



    listPtr->bytes[listPtr->length] = '\0';

    if (flagPtr != localFlags) {
	ckfree((char *) flagPtr);
    }
}

/*







>
>
>
>
>
>
>
>
>
>
>

>
>
>








>
>
>
|







1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
    }
    bytesNeeded += numElems;

    /*
     * Pass 2: copy into string rep buffer.
     */

    /*
     * We used to set the string length here, relying on a presumed
     * guarantee that the number of bytes TclScanElement() calls reported
     * to be needed was a precise count and not an over-estimate, so long
     * as the same flag values were passed to TclConvertElement().
     *
     * Then we saw [35a8f1c04a], where a bug in TclScanElement() caused
     * that guarantee to fail. Rather than trust there are no more bugs,
     * we set the length after the loop based on what was actually written,
     * an not on what was predicted.
     *
    listPtr->length = bytesNeeded - 1;
     *
     */

    listPtr->bytes = ckalloc((unsigned) bytesNeeded);
    dst = listPtr->bytes;
    for (i = 0; i < numElems; i++) {
	flagPtr[i] |= ( i ? TCL_DONT_QUOTE_HASH : 0 );
	elem = TclGetStringFromObj(elemPtrs[i], &length);
	dst += TclConvertElement(elem, length, dst, flagPtr[i]);
	*dst++ = ' ';
    }
    dst[-1] = '\0';

    /* Here is the safe setting of the string length. */
    listPtr->length = dst - 1 - listPtr->bytes;

    if (flagPtr != localFlags) {
	ckfree((char *) flagPtr);
    }
}

/*

Changes to generic/tclUtil.c.

947
948
949
950
951
952
953

















954
955
956
957
958
959
960
#endif

    if ((p == NULL) || (length == 0) || ((*p == '\0') && (length == -1))) {
	/* Empty string element must be brace quoted. */
	*flagPtr = CONVERT_BRACE;
	return 2;
    }


















    if ((*p == '{') || (*p == '"')) {
	/*
	 * Must escape or protect so leading character of value is not
	 * misinterpreted as list element delimiting syntax.
	 */
	forbidNone = 1;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
#endif

    if ((p == NULL) || (length == 0) || ((*p == '\0') && (length == -1))) {
	/* Empty string element must be brace quoted. */
	*flagPtr = CONVERT_BRACE;
	return 2;
    }

#if COMPAT
    /*
     * We have an established history in TclConvertElement() when quoting
     * because of a leading hash character to force what would be the
     * CONVERT_MASK mode into the CONVERT_BRACE mode. That is, we format
     * the element #{a"b} like this:
     *			{#{a"b}}
     * and not like this:
     *			\#{a\"b}
     * This is inconsistent with [list x{a"b}], but we will not change that now.
     * Set that preference here so that we compute a tight size requirement.
     */
    if ((*src == '#') && !(*flagPtr & TCL_DONT_QUOTE_HASH)) {
	preferBrace = 1;
    }
#endif

    if ((*p == '{') || (*p == '"')) {
	/*
	 * Must escape or protect so leading character of value is not
	 * misinterpreted as list element delimiting syntax.
	 */
	forbidNone = 1;

Changes to tests/list.test.

104
105
106
107
108
109
110


















111
112
113
114
test list-3.1 {SetListFromAny and lrange/concat results} {
    slowsort {fred julie alex carol bill annie}
} {alex annie bill carol fred julie}

test list-4.1 {Bug 3173086} {
    string is list "{[list \\\\\}]}"
} 1



















# cleanup
::tcltest::cleanupTests
return







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
test list-3.1 {SetListFromAny and lrange/concat results} {
    slowsort {fred julie alex carol bill annie}
} {alex annie bill carol fred julie}

test list-4.1 {Bug 3173086} {
    string is list "{[list \\\\\}]}"
} 1
test list-4.2 {Bug 35a8f1c04a, check correct str-rep} {
    set result {}
    foreach i {
	{#"} {#"""} {#"""""""""""""""}
	"#\"{" "#\"\"\"{" "#\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\{"
	"#\"}" "#\"\"\"}" "#\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\}"
    } {
	set list [list $i]
	set list [string trim " $list "]
	if {[llength $list] > 1 || $i ne [lindex $list 0]} {
	    lappend result "wrong string-representation of list by '$i', length: [llength $list], list: '$list'"
	}
    }
    set result [join $result \n]
} {}
test list-4.3 {Bug 35a8f1c04a, check correct string length} {
    string length [list #""]
} 5

# cleanup
::tcltest::cleanupTests
return