[Serdev] xlog color patch / cosmetic bug fixed
Andrei Pelinescu-Onciul
andrei at iptel.org
Mon Jun 13 17:37:05 UTC 2005
On Jun 13, 2005 at 18:51, Ingo Wolfsberger <iwolfsberger at gmx.net> wrote:
> I have fixed a small bug with the default background color.
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
More information about the Serdev
mailing list