On Sat, 27 Jun 1998, James Turner wrote: > > c += snprintf(write + c, len - c, "...", ...); > Won't quite do it. A given verify function is called multiple times. > If you called it as > > verify_function(rnum, buf, MAX_STRING_LENGTH); > > ten times in a row, you might overflow. You'd have to use: > > verify_function(rnum, buf + strlen(buf), MAX_STRING_LENGTH - strlen(buf)); > > That or keep track of the over-all length. It gets messy... that's > why a dropin replacement for sprintf would be nice. Very useful in > all the cases like the above, as well as getting rid of Borland C++'s > problem (though using the c like above does so as well). You could also use something like : http://www.abandoned.org/drylock/ftp/buffer-1.tar.gz which is a dynamically allocated buffer that expand itself as more data is stuffed into it. You can put data into it via a buffer_strcat and a bprintf - the latter prints to a small local buffer first, using snprintf, so it will never overflow. It looks BTW, damn much better in C++, if you'd rather like that version :) Buffer b; b.printf("Blah blah. %d %d %s %d %x\n", ...); b.printf("...."); // This now appends to previous data ch->print(b); // operator const char* converts to what Character::print // wants // and you don't have to buffer_free(buffer) when done in C++ :) Oh, it's quite fast too, since it keeps the last-used position in the buffer. I remember replacing some code on a MUD that would do lots of strcats() to show your skill list - for something like 500 skills, I think it took up several CPU seconds to do a 'practice'! It was quite much faster with the dynamic buffer :) ============================================================================= <erwin@andreasen.com> Herlev, Denmark UNIX System Programmer <URL:http://www.abandoned.org/drylock/> <*> (not speaking for) DDE ============================================================================= +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST