Hi,
Manuel Badzong --> dwm (2006-11-26 21:40:09 +0000):
> stext is declared as global and therefore aligned in the programs bss
> segment, which will be zeroed at startup. As whether read nor strncpy
> use its full length (strlen/sizeof - 1) the string will be 0 terminated
> in any case.
You're right. So that line should probably be removed.
> But I agree that it would be safer in case someone ever
> moves it down into main (this time I'm not sure if necessary/wasted).
Then that line should be added again ;-)
> >- saves 1020 bytes from being zeroed unnecessarily (performance! ;-))
> Ok, never thought about that. Yet I didn't read much about the
> implementation of the ANSI stdio functions (I presumed to understand
> them). Is strncpy really zeroing up to the specified n bytes? I thought
> it just copies until '\0' or n, whatever comes first (leaving dest
> unterminated in the latter case).
No, the destination is padded with '\0's, at least according to [1]K&R,
section B3.
Cheers, Jukka
[1] http://cm.bell-labs.com/cm/cs/cbook/
-- bashian roulette: $ ((RANDOM%6)) || rm -rf ~Received on Mon Nov 27 2006 - 18:22:31 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:32:52 UTC