On (01/06/08 19:30), Enno Gottox Boland wrote:
> To: dynamic window manager <dwm_AT_suckless.org>
> From: Enno Gottox Boland <gottox_AT_gmail.com>
> Subject: Re: [dwm] [patch] simplification to drawtext
> Reply-To: dynamic window manager <dwm_AT_suckless.org>
> List-Id: dynamic window manager <dwm.suckless.org>
>
> beware that it should be
>
> memcpy(&buf[MAX(0, len - 3)], "...", 4);
>
> not
>
> memcpy(&buf[MAX(0, len - 3)], "...", 3);
>
> otherwise it will overwrite the zero-terminator if len < 3.
This is REALLY OK, as that Xlib calls doesn't use zero-terminated
string, but string with length argument!
>
> Furthermore it will change the length of the string if len < 3, which
> has no impact on the output, as XDrawString respects len, but it's
> still ugly.
>
> So I still prefer strncpy as the result doing the same with memcopy
> should look like this to work properly:
> memcpy(&buf[MAX(0, len - 3)], "...", MAX(len, 3));
That MAX is baaad, as if len > 4 it will copy some random data after
string "..." which is really bad.
>
> I also prefer strncpy over memcpy because we're not copy plain data,
> but strings.
No, at that point, we are copying plain data. Not strings[1]
>
> regards
> Gottox
>
[1]: meaned as C string == char[] which ends with zero-terminator
-- Premysl "Anydot" Hruby, http://www.redrum.cz/Received on Sun Jun 01 2008 - 20:13:06 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:46:44 UTC