Re: Patch 21 & Strings

From: George Greer (
Date: 04/26/02

On Mon, 22 Apr 2002, David Endre wrote:

>1. Change instances of str_dup to strdup. The only time you should use
>str_dup is xxxxxxx. Strdup is better to use because it xxxxxxxx.

str_dup (the macro) gets automatically converted to the platform strdup(),
if available, or uses the CircleMUD str_dup().

str_dup() (the function) is better if you ever hit an Out-of-Memory
condition because it'll print a message and exit instead of giving a
segmentation fault on a NULL pointer like strdup().

strdup() is better when you're doing memory profiling because it doesn't
obscure the tracking of who allocates what memory and who leaks it.

I chose memory profiling over OOM but you're free to #undef HAVE_STRDUP if
you expect to run out of memory more often than you memory trace.

>2. Adjust instances of sprintf to send_to_char or write_to_output, except
>for xxxxx, or when xxxxxx. Sprintf is no longer needed because xxxxxx. It
>is ok to use Sprintf if xxxxxx.

There's no reason to use sprintf() unless a message you're printing is
sent, with no changes, in a loop to multiple people.

>P.S. Maybe there should be a note on the ftp site saying that none of
>these patches will work in patchlevel 21, unless specifically
>noted...since this was such a major change?

We've had major changes before.  The patches on the FTP site have always
been under such guidelines.  Most of them are trivial changes (add buffers,
change send_to_char argument order).

George Greer

(Whee! 8 days later and my DSL works again. Stupid lightning.)

   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT