Re: Color str_duping problem

From: Edward Glamkowski (EGlamkowski@MATHEMATICA-MPR.COM)
Date: 11/10/97


>Sent:  Monday, November 10, 1997 3:09 PM
>To:    CIRCLE@post.queensu.ca
>Subject:        Color str_duping problem
>
>Here's what I believe to be the problem I am having, I have a string that
>I sprintf to, like sprintf(buf,"&RHello world&w"); with the color codes
>in, then if I do a str_dup, or manipulate it, I get out of bounds problems
>and all other sorts of fun memory over running problems, I THINK its from,
>When the string is allocated, its allocated for 15 chars, including the &w
>and &R.  Then when its actually printed out, or passed through the
>proc_color, the &R is now replaced with the acutal ansi code for changing
>the color which is quite larger then &R.  So, as you can see, when its
>free and such I get problems, I was wondering if anyone else has
>encountered this problem, and knows how to fix it ?

Um... don't use color :-)

Create a list of #define's which define the length of
each ansi color string (if you need to, write a small
program to figure out lengths), then when you malloc it,
add the appropriate length to the amount allocated.
I don't remember off the top of my head how the allocation
is done - if it's through a macro, just add an extra
argument to the macro and add it the space being allocated.
Ditto for a function.  If you are just mallocing on the
spot, so to speak, then it is even easier, since you
wouldn't need to change any macro calls :)


     +------------------------------------------------------------+
     | 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/08/00 PST