Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 parse description bug
Yesterday, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
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
LOP 1.45
Author: Remcon
Submitted by: Remcon
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
Users Online
CommonCrawl, Google, Yandex, Yahoo!

Members: 0
Guests: 10
Stats
Files
Topics
Posts
Members
Newest Member
477
3,706
19,240
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » Const *char crashing everythi...
Forum Rules | Mark all | Recent Posts

Const *char crashing everything!
< Newer Topic :: Older Topic > tiny tiny tiny tiny (tiny) bugfix

Pages:<< prev 1 next >>
Post is unread #1 Feb 2, 2011, 12:11 am   Last edited Feb 2, 2011, 12:12 am by Txzeenath
Go to the top of the page
Go to the bottom of the page

Txzeenath
Apprentice
GroupMembers
Posts86
JoinedJul 24, 2004

No crashes... just a very tiny correction :biggrin:


Latest SmaugFUSS(1.9) in handler.c, around line 907,

bool str_prefix( const char *astr,char *bstr )


should be
bool str_prefix( const char *astr, const char *bstr )


       
Post is unread #2 Feb 2, 2011, 3:40 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Can you explain why this needs to be changed?

I've been running SmaugFUSS 1.9 since it went up for download (maybe even before I can't recall.) and I've never had a crash or any kind of issue from str_prefix. So, I'm going to need a little more than just your say-so to go on as to why this needs changed.
       
Post is unread #3 Feb 3, 2011, 12:00 am
Go to the top of the page
Go to the bottom of the page

Txzeenath
Apprentice
GroupMembers
Posts86
JoinedJul 24, 2004

It doesn't cause issues, it really can't, you're not doing anything with the strings that should cause any. It is a simple yes/no function. It's just consistency and technical correctness. It's one of the only functions in the entire source not using proper 'constness'.

It should be fairly obvious, and the fact that I feel essentially attacked for such a stupid issue such as variable labeling is ridiculous.




Not modifying the input char *, don't want to modify it .... const.
       
Post is unread #4 Feb 3, 2011, 7:18 am
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

You weren't being "attacked", just being asked to explain the correction. Not everyone knows everything about programming--me for instance. Since no one else has said anything, and smaugFUSS 1.9 has been out for quite a while, an explanation as to the problem the bit of code pointed out is needed so that we can decide for ourselves if it's worth the effort to fix, or not. Since it doesn't actually change anything--based on your last explanation--having a topic of "Const *char crashing everything!" is extremely misleading and inaccurate.
       
Post is unread #5 Feb 3, 2011, 3:35 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006


Txzeenath said:

It doesn't cause issues, it really can't, you're not doing anything with the strings that should cause any. It is a simple yes/no function. It's just consistency and technical correctness. It's one of the only functions in the entire source not using proper 'constness'.

I just checked the distro, and the line in question doesn't have this inconsistency.


Txzeenath said:

It should be fairly obvious, and the fact that I feel essentially attacked for such a stupid issue such as variable labeling is ridiculous.

You weren't attacked. You were asked to provide proof of your claim. A claim that appears to have been misleading and partially false.


Txzeenath said:

Not modifying the input char *, don't want to modify it .... const.

Yes, I know this. I'm not a novice.
       
Post is unread #6 Feb 3, 2011, 6:58 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

str_prefix() isn't even in the reported file. Perhaps you're running with an old copy? In the SVN, it's in db.c on line 4037.
       
Post is unread #7 Feb 4, 2011, 4:14 am
Go to the top of the page
Go to the bottom of the page

Txzeenath
Apprentice
GroupMembers
Posts86
JoinedJul 24, 2004

Apologies for that, I was working in both files at the time, edited it, and moved to something else before posting.
It's actually(this is from the .tgz file recently downloaded)

bool is_name_prefix( const char *str, char *namelist )
{
   char name[MAX_INPUT_LENGTH];

   for( ;; )
   {
      namelist = one_argument( namelist, name );
      if( name[0] == '\0' )
         return FALSE;
      if( !str_prefix( str, name ) )
         return TRUE;
   }
}


In handler.c
       
Post is unread #8 Feb 4, 2011, 3:30 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Totally different thing there. It's a relatively minor discrepancy but it's a valid one.
       
Post is unread #9 Feb 4, 2011, 4:37 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Now that we're all looking at the same thing, I feel I really need to point out that changing char *namelist to const char *namelist is not a valid fix, because namelist is in fact being modified within the function.

      namelist = one_argument( namelist, name );
       
Post is unread #10 Feb 4, 2011, 5:36 pm   Last edited Feb 4, 2011, 5:36 pm by GatewaySysop
Go to the top of the page
Go to the bottom of the page

GatewaySysop
Conjurer
GroupMembers
Posts367
JoinedMar 7, 2005

Am I the only person who is now thoroughly confused about what we're talking about here? Are we talking about str_prefix or is_name_prefix? I thought it was the former, not the latter. I understand what Kayle says about the latter, but if we're talking about the former, that's already coded as

bool str_prefix( const char *astr, const char *bstr )
in the FUSS 1.9 distro so... what again are we talking about here? :headbang:
       
Post is unread #11 Feb 4, 2011, 6:24 pm   Last edited Feb 4, 2011, 6:28 pm by Txzeenath
Go to the top of the page
Go to the bottom of the page

Txzeenath
Apprentice
GroupMembers
Posts86
JoinedJul 24, 2004

Kayle said:

Now that we're all looking at the same thing, I feel I really need to point out that changing char *namelist to const char *namelist is not a valid fix, because namelist is in fact being modified within the function.

      namelist = one_argument( namelist, name );


I considered that fact, but as far as consistancy, every other function is stated as const, so should we be changing the other dozen or so to use a char * namelist? Also.. I'd have to look into it, but is the namelist itself being modified, or is the namelist pointer simply being reassigned? Const assumes you are not changing the original string, which reassigning a variable does not do.

Just asking really, I've been out of this for 5-6 years, and you'd know far better I believe.
       
Post is unread #12 Feb 4, 2011, 6:42 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Kayle said:

Now that we're all looking at the same thing, I feel I really need to point out that changing char *namelist to const char *namelist is not a valid fix, because namelist is in fact being modified within the function.


The other similar functions around it that also alter namelist have been marked as const, so either is_name_prefix() also needs to be done the same way, or all of the others need to be changed the other way. I'd lean toward making is_name_prefix() consistent with the others unless there's reason to believe that none of the others are working as they are.
       
Post is unread #13 Feb 4, 2011, 6:55 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

I wouldn't know. I don't use any of them, and don't know anywhere in the code that does use them off the top of my hand. I'll poke around some and maybe get David to have a look at it since he did the const correct fix for the base to begin with. It could have been a simple oversight, or there could be a reason. I'll investigate.
       
Post is unread #14 Feb 4, 2011, 7:03 pm   Last edited Feb 4, 2011, 7:17 pm by Txzeenath
Go to the top of the page
Go to the bottom of the page

Txzeenath
Apprentice
GroupMembers
Posts86
JoinedJul 24, 2004

Kayle said:

I wouldn't know. I don't use any of them, and don't know anywhere in the code that does use them off the top of my hand. I'll poke around some and maybe get David to have a look at it since he did the const correct fix for the base to begin with. It could have been a simple oversight, or there could be a reason. I'll investigate.


Most of the code uses those functions, not that exact one, but a version of it. It's essential to many of the ways things work in magic and commands.

I may be off in my usage, but defining it as const simply states, you're not modifying the input, not that you won't modify the pointer within the function itself.

As an example:
one_argument(arg1,arg2) takes arg1 and arg2, strips an argument from arg1, returns the remainder, and changes the original arg2 argument to the stripped value.

Making arg1 a const char*, and arg2 a char *(in the case of the one_argument function), as the original input is being modified by the function. Modifications limited in scope to the function itself do not qualify against it being a const argument.

But as I said, I could be mistaken, my knowledge is limited on pointers and the such... and my explanation isn't exactly the most elegantly laid out heh.
       
Post is unread #15 Feb 4, 2011, 7:10 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Further probing reveals this as an oversight. The prototype in mud.h lists namelist as const char *namelist, while the actual function is missing the const.

Fixed in my local copy, will get it into the SVN as soon as I get SVN reinstalled locally.
       
Pages:<< prev 1 next >>