Tcl Source Code

Check-in [ba9a1d9ddb]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

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

Overview
Comment:3484402 Correct Off-By-One error appending unicode. Thanks to Poor Yorick. Also converted some memcpy() to memmove() to reliably handle overlapping copies, and corrected test for when growth is needed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-3484402
Files: files | file ages | folders
SHA1: ba9a1d9ddb07462fadd9341dfee62228784b9d18
User & Date: dgp 2012-02-07 20:28:56
Context
2012-02-09
14:57
3484402 Correct Off-By-One error appending unicode. Thanks to Poor Yorick. Also corrected test for w... check-in: f57b5ba48d user: dgp tags: core-8-4-branch
2012-02-07
20:28
3484402 Correct Off-By-One error appending unicode. Thanks to Poor Yorick. Also converted some memc... Closed-Leaf check-in: ba9a1d9ddb user: dgp tags: bug-3484402
2012-02-06
17:21
3484621 Invalidate bytecode when exec traces are added/removed from compiled cmd. check-in: 4b0a6f7864 user: dgp tags: core-8-4-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclStringObj.c.

1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
....
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
....
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
     * modest increase.  See the "TCL STRING GROWTH ALGORITHM" comment at
     * the top of this file for an explanation of this growth algorithm.
     */

    numChars = stringPtr->numChars + appendNumChars;
    stringCheckLimits(numChars);

    if (STRING_UALLOC(numChars) >= stringPtr->uallocated) {
	/*
	 * Protect against case where unicode points into the existing
	 * stringPtr->unicode array.  Force it to follow any relocations
	 * due to the reallocs below.
	 */
	int offset = -1;
	if (unicode >= stringPtr->unicode && unicode <= stringPtr->unicode
		+ 1 + stringPtr->uallocated / sizeof(Tcl_UniChar)) {
	    offset = unicode - stringPtr->unicode;
	}

	GrowUnicodeBuffer(objPtr, numChars);
	stringPtr = GET_STRING(objPtr);

	/* Relocate unicode if needed; see above. */
................................................................................
    }

    /*
     * Copy the new string onto the end of the old string, then add the
     * trailing null.
     */

    memcpy((VOID*) (stringPtr->unicode + stringPtr->numChars), unicode,
	    appendNumChars * sizeof(Tcl_UniChar));
    stringPtr->unicode[numChars] = 0;
    stringPtr->numChars = numChars;
    stringPtr->allocated = 0;

    Tcl_InvalidateStringRep(objPtr);
}
................................................................................
    /*
     * Invalidate the unicode data.
     */
    
    stringPtr->numChars = -1;
    stringPtr->hasUnicode = 0;
    
    memcpy((VOID *) (objPtr->bytes + oldLength), (VOID *) bytes,
	    (size_t) numBytes);
    objPtr->bytes[newLength] = 0;
    objPtr->length = newLength;
}
 
/*
 *----------------------------------------------------------------------






|







|







 







|







 







|







1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
....
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
....
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
     * modest increase.  See the "TCL STRING GROWTH ALGORITHM" comment at
     * the top of this file for an explanation of this growth algorithm.
     */

    numChars = stringPtr->numChars + appendNumChars;
    stringCheckLimits(numChars);

    if (STRING_UALLOC(numChars) > stringPtr->uallocated) {
	/*
	 * Protect against case where unicode points into the existing
	 * stringPtr->unicode array.  Force it to follow any relocations
	 * due to the reallocs below.
	 */
	int offset = -1;
	if (unicode >= stringPtr->unicode && unicode <= stringPtr->unicode
		+ stringPtr->uallocated / sizeof(Tcl_UniChar)) {
	    offset = unicode - stringPtr->unicode;
	}

	GrowUnicodeBuffer(objPtr, numChars);
	stringPtr = GET_STRING(objPtr);

	/* Relocate unicode if needed; see above. */
................................................................................
    }

    /*
     * Copy the new string onto the end of the old string, then add the
     * trailing null.
     */

    memmove((VOID*) (stringPtr->unicode + stringPtr->numChars), unicode,
	    appendNumChars * sizeof(Tcl_UniChar));
    stringPtr->unicode[numChars] = 0;
    stringPtr->numChars = numChars;
    stringPtr->allocated = 0;

    Tcl_InvalidateStringRep(objPtr);
}
................................................................................
    /*
     * Invalidate the unicode data.
     */
    
    stringPtr->numChars = -1;
    stringPtr->hasUnicode = 0;
    
    memmove((VOID *) (objPtr->bytes + oldLength), (VOID *) bytes,
	    (size_t) numBytes);
    objPtr->bytes[newLength] = 0;
    objPtr->length = newLength;
}
 
/*
 *----------------------------------------------------------------------