Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2012-08-23
19:12 • Closed ticket [3496014fff]: Unecessary memset() in Tcl_SetByteArrayObj() plu... artifact: 4193d8fbeb user: nijtmans
2012-07-17
03:34 • Ticket [3496014fff]: 4 changes artifact: b84a1e722e user: nijtmans
01:09 • Ticket [3496014fff]: 4 changes artifact: 1ff4e5201b user: stwo
2012-03-02
21:15 • Ticket [3496014fff]: 4 changes artifact: 4b36f9a075 user: stwo
18:34 • Ticket [3496014fff]: 4 changes artifact: da973169d6 user: sebres
18:15 • Open ticket [3496014fff]. artifact: 671c383475 user: sebres
17:11 • Ticket [3496014fff]: 4 changes artifact: 2d9ec35a76 user: dkf
17:08 • Closed ticket [3496014fff]. artifact: d5b963bf54 user: dkf
2012-03-01
23:56 • Ticket [3496014fff]: 4 changes artifact: e6870f4c64 user: sebres
16:13 • New ticket [3496014fff]. artifact: 2fecefc89e user: stwo

Unecessary memset() in Tcl_SetByteArrayObj()

Closed / Fixed3496014fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 14 years ago
Descriptionplain2012-03-01 16:13:52
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.
sebresplain2012-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.
dkfplain2012-03-02 17:08:04
allow_comments - 1
dkfplain2012-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.
sebresplain2012-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
sebresplain2012-03-02 18:34:06
for example the function Tcl_SetByteArrayLength does it not and it is as well.
stwoplain2012-03-02 21:15:45
I'm with sebres.
Remove the memset!
Let's keep things simple.
stwoplain2012-07-17 01:09:22
Is this going to be fixed, or what?
nijtmansplain2012-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.
nijtmansplain2012-08-23 19:12:45
allow_comments - 1

Fixed on trunk. Same protection backported to Tcl 8.5 as well.
Log in (anonymous is fine) to add a comment.