summaryrefslogtreecommitdiffstats
path: root/generic/tclBinary.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclBinary.c')
-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;