russellallen / self

Making the world safe for objects
http://selflanguage.org
698 stars 75 forks source link

Do not abuse `strncpy`(3) as `memcpy`(3) #146

Closed nbuwe closed 8 months ago

nbuwe commented 1 year ago

strncpy(3) is abused to copy char data that are not zero-terminated with the length argument computed based on the source data, not the destination buffer. strncpy(3) is really (ab)used here as memcpy(3) and the code doesn't even take advantage of the zero-filling behavior of strncpy and adds the zero byte manually where it's needed.

Gcc complained about some of these, so fix all of them in a preemptive move. While here, do CSE on the length calculation where applicable.