diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2012-03-02 10:05:57 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2012-03-02 10:05:57 (GMT) |
commit | 2714fa668e9bd9b9450be693600de1f8bcbfd21a (patch) | |
tree | 30dfc48f60bab6290e1e11d4c98c287f61b3ffa4 | |
parent | 5c275727c1f00f6fa605160950ea20137f2acb5a (diff) | |
download | tcl-2714fa668e9bd9b9450be693600de1f8bcbfd21a.zip tcl-2714fa668e9bd9b9450be693600de1f8bcbfd21a.tar.gz tcl-2714fa668e9bd9b9450be693600de1f8bcbfd21a.tar.bz2 |
(Tcl_SetByteArrayObj): Only zero out the memory block if it is not being
immediately overwritten. Thanks to Stuart Cassoff for spotting.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | generic/tclBinary.c | 9 |
2 files changed, 13 insertions, 4 deletions
@@ -1,6 +1,12 @@ +2012-03-02 Donal K. Fellows <dkf@users.sf.net> + + * generic/tclBinary.c (Tcl_SetByteArrayObj): Only zero out the memory + block if it is not being immediately overwritten. (Caller might still + overwrite, but we should at least avoid known-useless work.) + 2012-02-29 Jan Nijtmans <nijtmans@users.sf.net> - * generic/tclIOUtil.c: [Bug 3466099] BOM in Unicode + * generic/tclIOUtil.c: [Bug 3466099]: BOM in Unicode * generic/tclEncoding.c: * tests/source.test diff --git a/generic/tclBinary.c b/generic/tclBinary.c index 0a340f2..444e7fa 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -305,11 +305,14 @@ Tcl_SetByteArrayObj( length = (length < 0) ? 0 : length; byteArrayPtr = ckalloc(BYTEARRAY_SIZE(length)); - memset(byteArrayPtr, 0, BYTEARRAY_SIZE(length)); byteArrayPtr->used = length; byteArrayPtr->allocated = length; - if (bytes && length) { - memcpy(byteArrayPtr->bytes, bytes, (size_t) length); + if (length) { + if (bytes) { + memcpy(byteArrayPtr->bytes, bytes, (size_t) length); + } else { + memset(byteArrayPtr->bytes, 0, (size_t) length); + } } objPtr->typePtr = &tclByteArrayType; |