Re: [dwm] [patch] simplification to drawtext

From: Enno \ <gottox_AT_gmail.com>
Date: Mon, 2 Jun 2008 09:56:37 +0200

whoops...

memcpy(&buf[MAX(0, len - 3)], "...", MIN(3, len));

2008/6/1, Premysl Hruby <dfenze_AT_gmail.com>:
> 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/
>
>

-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
Received on Mon Jun 02 2008 - 09:56:38 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:46:46 UTC