summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2012-03-02 10:05:57 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2012-03-02 10:05:57 (GMT)
commit714ba439a2a5271a913fede2596c072cb2564516 (patch)
tree30dfc48f60bab6290e1e11d4c98c287f61b3ffa4 /generic
parentc6d76efcfbaa9d03aeaecec19843a745556dcb18 (diff)
downloadtcl-714ba439a2a5271a913fede2596c072cb2564516.zip
tcl-714ba439a2a5271a913fede2596c072cb2564516.tar.gz
tcl-714ba439a2a5271a913fede2596c072cb2564516.tar.bz2
(Tcl_SetByteArrayObj): Only zero out the memory block if it is not being
immediately overwritten. Thanks to Stuart Cassoff for spotting.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclBinary.c9
1 files changed, 6 insertions, 3 deletions
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;