Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
Bug in do_drag( )
Oct 8, 2017, 12:40 am
By GatewaySysop
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Beastmaster 6D sound files
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Google, DotBot

Members: 0
Guests: 20
Stats
Files
Topics
Posts
Members
Newest Member
476
3,704
19,231
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWFOTE FUSS » Webwho Error
Forum Rules | Mark all | Recent Posts

Webwho Error
< Newer Topic :: Older Topic > Is there already a fix for htmlcolo

Pages:<< prev 1 next >>
Post is unread #1 Mar 22, 2004, 12:48 am   Last edited Mar 22, 2004, 12:49 am by Clouded Seas
Go to the top of the page
Go to the bottom of the page

Clouded Seas
New Member
GroupMembers
Posts2
JoinedMar 21, 2004

Has anyone else running this encountered a problem with htmlcolor in the FUSS version of FotE? (Or any of the functions in functions.c that call strrep repeatedly, actually.) Basically, it's not actually converting the color codes to HTML. I've tracked down the reason.

   newarg = strrep( src, "<", "&lt;" );
   newarg = strrep( src, ">", "&gt;" );
   newarg = strrep( src, "&x", "</font><font color='#333333'>" );
   newarg = strrep( src, "&g", "</font><font color='#006600'>" );
   newarg = strrep( src, "&r", "</font><font color='#660000'>" );
   newarg = strrep( src, "&O", "</font><font color='#666600'>" );
   newarg = strrep( src, "&b", "</font><font color='#000066'>" );
   newarg = strrep( src, "&p", "</font><font color='#660066'>" );
   newarg = strrep( src, "&c", "</font><font color='#666699'>" );
   newarg = strrep( src, "&w", "</font><font color='#FFFFFF'>" );
   newarg = strrep( src, "&z", "</font><font color='#666666'>" );
   newarg = strrep( src, "&R", "</font><font color='#AA0000'>" );
   newarg = strrep( src, "&G", "</font><font color='#00AA00'>" );
   newarg = strrep( src, "&Y", "</font><font color='#999900'>" );
   newarg = strrep( src, "&B", "</font><font color='#0000AA'>" );
   newarg = strrep( src, "&P", "</font><font color='#AA00AA'>" );
   newarg = strrep( src, "&C", "</font><font color='#9999CC'>" );
   newarg = strrep( src, "&W", "</font><font color='#CCCCCC'>" );
   newarg = strrep( src, "\r", "" );


If you look at this part of the function, the calls to strrep have been changed from the stock form to fix memory leaks, but now every time it calls strrep it calls it based on the original src variable, (whereas the changes are put in newarg) thus the changes are being lost every time except for the last one to be run. Is there already a fix for this or is everyone as lost as I am?

Also, isn't returning a pointer to a static character array a bit of a risky business in the first place, leak-free though it is?
       
Post is unread #2 Mar 22, 2004, 4:57 am
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Hrm. Ok. So you're saying the intent is to have it check the string against *ALL* of those possibilities at once? If so then yes, I goofed in fixing that :)

As for returning a static array, it's perfectly safe. You just shouldn't expect it to remain the same past the first use of it. Say you have something like this:

snprintf( buf, MSL, "%s %s", htmlcolor( &x ), htmlcolor( &b ) );

What you'd end up with in this situation is that both %s tags would be converted to whatever &b becomes in HTML. Not the desired results. I think this is what the original authors were attempting to correct by making so much use of str_dup, but as you've noticed doing that leaks like a seive.

I'll take another look at the stuff in functions.c and see what I fubared and fix it.
       
Post is unread #3 Mar 22, 2004, 8:36 am   Last edited Mar 22, 2004, 8:43 am by Clouded Seas
Go to the top of the page
Go to the bottom of the page

Clouded Seas
New Member
GroupMembers
Posts2
JoinedMar 21, 2004

Hmmmm... I guess as long as you're careful how you use it, it does have its advantages. :) No leaks since it's not dynamically allocated and no allocation times, however brief, since it's allocated once for the whole run of the program. I'll just have to keep that in mind next time I'm using a function that returns to me a string so I don't just store the pointer. (Must use STRALLOC like I should anyway. <_<;)

Anyway, thanks for taking a look at this. :) Pointers have never been my strong suit. I've gone nuts trying to figure out an efficient way to do it without leaking on every call to strrep like the old one did.
       
Post is unread #4 Mar 23, 2004, 7:26 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

You don't want to use STRALLOC to do that either. That would also cause leaks, though you'd probably not notice them as quickly since that would begin filling the hash with them. The static array is the only way to fly. You just need to be mindful of the behaviour it results in.
       
Pages:<< prev 1 next >>