strcat+strcat+strcat == baaad

David Laight david at l8s.co.uk
Sun Dec 1 14:44:25 CST 2002


> I said that due to the wall to wall agreement over the superiority of 
> sprintf/snprintf. If there is a consensus, we should stick to it.

But the performance of it will suck badly.....

Something like:

char *
str_add(char *s, char *lim, const char *a)
{
	int c;

	do {
		if (s >= lim) {
			s = lim - 1;
			c = 0;
		} else
			c = *a++;
		*s++ = c;
	} while (c);

	return s;
}

So you can do:
	lim = buf + len;
	buf = str_add(buf, lim, "abc");
	buf = str_add(buf, lim, "123");
	...
might be safer.

	David

-- 
David Laight: david at l8s.co.uk



More information about the wine-devel mailing list