George <greerga@CIRCLEMUD.ORG> writes:
> On Fri, 26 Jun 1998, James Turner wrote:
>
> >(Note: I wrote the above about an hour ago. I changed it to use a
> >static pointer now. Makes the functions more self-contained and
> >easier to use IMO, since if you wanted to call them from elsewhere
> >there wouldn't be any need to worry about freeing the string and
> >such).
>
> void verify_function(int (vnum/rnum), char * write, int len)
> {
> int c = 0;
> *write = '\0';
>
> if (...)
> c += snprintf(write + c, len - c, "...", ...);
> if (,,,)
> c += snprintf(write + c, len - c, ",,,", ,,,);
>
> ...etc...
> }
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).
Chip
--
James Turner turnerjh@xtn.net UIN: 1102038
http://www.vuse.vanderbilt.edu/~turnerjh/
+------------------------------------------------------------+
| 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