Tcl Source Code

View Ticket
Login
Ticket UUID: 3496014
Title: Unecessary memset() in Tcl_SetByteArrayObj()
Type: Bug Created on: 2012-03-01 16:13:52
Submitter: stwo Assigned to: nijtmans
Subsystem: 12. ByteArray Object Severity:
Priority: 2 Last modified: 2012-08-23 19:12:45
Status: Closed Closed by: nijtmans
Resolution: Fixed Closed on: 2012-08-23 12:12:45
Version: None
Description:
I don't think that the memset() in Tcl_SetByteArrayObj() (tclBinary.c, line 308) is necessary.
The man page says nothing about clearing the memory and the memset() makes the function a tad slower.
User Comments:
sebres added on 2012-03-01 23:56:34:
Trunk? or wisch version did You mean exactly?  
For example it's not in core-8-5-brunch.
Apart from that I'm entirely agree with You.

I found it under Art. 17ece9b7b9bc918f31f1987ede4eb7857c8d5abf :
- part of checkin [ce65d5a8de] on branch trunk - patch #2215022: clean up the binary ensemble initialization code Applied a patch from Duoas which extends the TclMakeEnsemble command to handle sub-ensembles from tables. Cleaned up the original patch a bit. (user: patthoyts ) [annotate] 

I think it was really not good idea.

dkf added on 2012-03-02 17:08:04:

allow_comments - 1

dkf added on 2012-03-02 17:11:04:
memset is now only done when the bytes argument is NULL; ensuring memory is in a known state is a reasonable approach, but there's no reason to write it twice.

sebres added on 2012-03-02 18:15:35:

allow_comments - 0

Why should you do it in the other case?
IMO, memory is in unknown state is not a reason for this

sebres added on 2012-03-02 18:34:06:
for example the function Tcl_SetByteArrayLength does it not and it is as well.

stwo added on 2012-03-02 21:15:45:
I'm with sebres.
Remove the memset!
Let's keep things simple.

stwo added on 2012-07-17 01:09:22:
Is this going to be fixed, or what?

nijtmans added on 2012-07-17 03:34:31:
The documentation contains (ByteArrObj.3):
> If \fIbytes\fR is NULL then the new byte array contains
> arbitrary values.
I would say, null bytes are not arbibrary values ;-)

Suggestion committed to branch bug-3496014,
for anyone interested to try. I tried it and
all tests pass. So, either adapt the
implementation, as suggested by stwo,
or adapt the documentation. I
would prefer to keep the
documentation as is.

nijtmans added on 2012-08-23 19:12:45:

allow_comments - 1

Fixed on trunk. Same protection backported to Tcl 8.5 as well.