[Serdev] xlog color patch / str copy bug fixed
Ingo Wolfsberger
iwolfsberger at gmx.net
Mon Jun 13 18:24:37 UTC 2005
Thanks for the tips.
I have updated the source.
COL_BUF is now only 10 big :).
cvs access would be great.
bye,
Ingo
> You still have some bugs/problems:
> - in xl_get_color all the lines like:
> strncpy(color+strlen(color), "0;", COL_BUF);
> don't do what you expect: in this case it will copy "0;"
> at color +strlen(), but it will also padd with 0s till
> color+strlen()+ COL_BUF => buffer overflow.
> (if the length is less then the src string, it will padd with 0 the
> remainder of dest).
> Moreover doing strlen(color) all the time is a waste of cpu cycles :-)
> Consider something like:
> /* works only for static strings ( e.g. "afada"), for generic char*
> * pointers replace sizeof()-1 with strlen() */
> #define append_sstring(p, end, str) \
> do{ \
> if ((p)+(sizeof(str)-1)<=(end)){
> memcpy((p), str, sizeof(str)-1);
> (p)+=sizeof(str)-1;
> }else{
> /* overflow */
> }
> }while(0);
> char* p;
> char* end;
>
> p=color;
> end=p+COL_BUF;
>
> append_sstring(p, end, "\033[");
> if (islower(hp->s[0])) {
> /* normal font */
> append_sstring( p, end, "0;");
> }
> ... /* a.s.o */
>
> /* end */
> append_sstring( p, end, "m");
>
> res->s=color;
> res->len=p-color;
> return 0;
>
> BTW: setting COL_BUF to 12 should be enough (if you don't write a
> terminating 0).
>
> - in xl_parse_format(char *s, xl_elog_p *el) you add char buf[COL_BUF],
> but you never use it.
> - what do you need ctype.h for?
>
>
>
> Andrei
>
--
Weitersagen: GMX DSL-Flatrates mit Tempo-Garantie!
Ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_xlog_color_v1.1
Type: application/octet-stream
Size: 8005 bytes
Desc: not available
Url : http://lists.iptel.org/pipermail/serdev/attachments/20050613/7bd30faa/patch_xlog_color_v1.obj
More information about the Serdev
mailing list