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.

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));

I also prefer strncpy over memcpy because we're not copy plain data,
but strings.

regards
Gottox

2008/6/1, Anselm R. Garbe <[EMAIL PROTECTED]>:
> On Sun, Jun 01, 2008 at 01:21:03PM +0200, Premysl Hruby wrote:
>  > Not much readable (because it firstly looks like it's error (buf maybe
>  > not ended with \0)). I am against using strncpy in case that dest string
>  > is not C string, but char[] + length.
>  >
>  > Maybe:
>  >
>  > memcpy(&buf[MAX(0, len - 3)], "...", 3);
>  >
>  > would be somewhat better ;)
>  >
>  >
>  > >     XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
>  > >     if(dc.font.set)
>  > >             XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, 
> buf, len);
>
>
> I though a while about this, and I think the memcpy() idea is
>  best.
>
>  Kind regards,
>
> --
>   Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
>
>


-- 
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)

Reply via email to