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, DotBot

Members: 0
Guests: 21
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 » SWR FUSS » Overflow compile error
Forum Rules | Mark all | Recent Posts

Overflow compile error
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 May 13, 2008, 10:34 am
Go to the top of the page
Go to the bottom of the page

Krylan
Fledgling
GroupMembers
Posts39
JoinedApr 14, 2005

So, I've been slowly (very slowly) taking my time getting my codebase to run under gcc 4. However, this latest bug, has got me confused to say the least.

cc1: warnings being treated as errors
magic.c: In function ‘is_immune’:
magic.c:48: warning: overflow in implicit constant conversion
magic.c:49: warning: overflow in implicit constant conversion


The function (with lines 48 and 48 bold)
bool is_immune( CHAR_DATA *ch, short damtype )
{
   switch( damtype )
   {
      case SD_FIRE:           return( IS_SET( ch->immune, RIS_FIRE ) );
      case SD_COLD:           return( IS_SET( ch->immune, RIS_COLD ) );
      case SD_ELECTRICITY:    return( IS_SET( ch->immune, RIS_ELECTRICITY ) );
      case SD_ENERGY:         return( IS_SET( ch->immune, RIS_ENERGY ) );
      case SD_ACID:           return( IS_SET( ch->immune, RIS_ACID ) );
      case SD_POISON:         return( IS_SET( ch->immune, RIS_POISON ) );
      case SD_DRAIN:          return( IS_SET( ch->immune, RIS_DRAIN ) );
   }
   return FALSE;
}


Any ideas? (UGH, some days I wish I would have learned C the right way instead of picking apart existing programs to figure out how its supposed to look)
       
Post is unread #2 May 13, 2008, 1:52 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

What are the values of SD_POISON and SD_DRAIN? The warning is saying that something is being converted to a type too small to fit it, but I'm not sure if it's the SD_ constants or the RIS_POISON/DRAIN values.
       
Post is unread #3 May 13, 2008, 4:22 pm
Go to the top of the page
Go to the bottom of the page

Krylan
Fledgling
GroupMembers
Posts39
JoinedApr 14, 2005

typedef enum
{ SD_NONE, SD_FIRE, SD_COLD, SD_ELECTRICITY, SD_ENERGY, SD_ACID,
   SD_POISON, SD_DRAIN, SD_SAND, SD_HAIL
} spell_dam_types;
       
Post is unread #4 May 13, 2008, 4:34 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

OK, I guess we need to look at the values of RIS_POISON/DRAIN, the definition of IS_SET, and finally the type of ch->immune.
       
Post is unread #5 May 13, 2008, 4:53 pm
Go to the top of the page
Go to the bottom of the page

Krylan
Fledgling
GroupMembers
Posts39
JoinedApr 14, 2005

Is_set:
#define IS_SET(flag, bit)       ((flag) & (bit))


RIS_POISON/DRAIN
#define RIS_POISON                BV08
#define RIS_DRAIN                 BV09


struct char_data
int immune
       
Post is unread #6 May 13, 2008, 5:24 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

Oh, I think know what's going on. The result of an int and'ed with a number greater than 255 is too large to fit in the char data type, and boolean is typedef'ed to char. I think that C++ would be smart enough to do this automatically because it treats boolean as its own type, but that's neither here nor there.

What you want to do is:

return( IS_SET( ch->immune, RIS_DRAIN ) != 0 );

which means do the binary 'and' operation, and then check if the result is non-zero.

A solution that is "better" in that it is more general, but might affect things that use IS_SET improperly, would be to fix IS_SET's definition:

#define IS_SET(flag, bit) (((flag) & (bit)) != 0)
       
Post is unread #7 May 13, 2008, 5:59 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

SWR FUSS hasn't been converted to compile with g++ yet so this sort of thing hasn't been dealt with. As shipped SWR FUSS is still configured to compile as C.
       
Post is unread #8 May 13, 2008, 7:11 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,857
JoinedJul 26, 2005

That one looks more or less the same as what I use.
/* Is immune to a damage type */
bool is_immune( CHAR_DATA *ch, short damtype )
{
   switch( damtype )
   {
      case SD_FIRE:        return ( xIS_SET( ch->immune, RIS_FIRE ) );
      case SD_WIND:        return ( xIS_SET( ch->immune, RIS_WIND ) );
      case SD_EARTH:       return ( xIS_SET( ch->immune, RIS_EARTH ) );
      case SD_WATER:       return ( xIS_SET( ch->immune, RIS_WATER ) );
      case SD_ICE:         return ( xIS_SET( ch->immune, RIS_ICE ) );
      case SD_COLD:        return ( xIS_SET( ch->immune, RIS_COLD ) );
      case SD_ELECTRICITY: return ( xIS_SET( ch->immune, RIS_ELECTRICITY ) );
      case SD_ENERGY:      return ( xIS_SET( ch->immune, RIS_ENERGY ) );
      case SD_ACID:        return ( xIS_SET( ch->immune, RIS_ACID ) );
      case SD_POISON:      return ( xIS_SET( ch->immune, RIS_POISON ) );
      case SD_DRAIN:       return ( xIS_SET( ch->immune, RIS_DRAIN ) );
      case SD_HOLY:        return ( xIS_SET( ch->immune, RIS_HOLY ) );
      case SD_SHADOW:      return ( xIS_SET( ch->immune, RIS_SHADOW ) );
   }
   return false;
}

Mine compiles in g++ and the server it is on shows this for gcc --v
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)

No complaints about it by the code.

Personally though if I did start getting complaints I would probably break it up more to have it check the data and if it is set then just return true and if it isn't set have it return false.
       
Post is unread #9 May 13, 2008, 9:02 pm   Last edited May 13, 2008, 9:03 pm by David Haley
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

Yes, but that's the thing, g++ treats bool as a proper type, and knows how to convert things to bool: if it's zero, it is false, otherwise it is true. Since bool is really just char for gcc, it is actually doing a conversion to char and in that case overflow becomes possible.

Were you saying that it works fine for gcc 4.1.1? It's possible that newer versions of gcc are also treating bool as a built-in type as an extension to the standard.


EDIT:
You're also using xIS_SET, which might behave differently regarding how it returns its value. IS_SET doesn't return a bool, it returns an integer.
       
Post is unread #10 May 13, 2008, 11:20 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

David. Perhaps you missed it, or ignored my comment, but I just got done saying I compiled SWR FUSS, as shipped, and got no complaints from the code. As a C program, using gcc. SWR FUSS does not come with EXT_BV so xIS_SET doesn't exist.

gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)
       
Post is unread #11 May 14, 2008, 8:35 am
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

I was talking to Remcon, Samson, asking him about what he is compiling with, and he does indeed seem to be using xIS_SET... :wink:

I wonder what the OP is compiling with, because clearly his version of gcc is unhappy with the code. So it doesn't seem to be quite as simple as you say it is...
       
Post is unread #12 May 14, 2008, 10:13 am
Go to the top of the page
Go to the bottom of the page

Krylan
Fledgling
GroupMembers
Posts39
JoinedApr 14, 2005

Well, my AFFECTED flags are using extended. But I've not converted immune or susceptible.
       
Post is unread #13 May 14, 2008, 10:25 am
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

How about your gcc version? Samson and Remcon report that it works with 4.1.2 but clearly it didn't work with your version of gcc 4. Do you have gcc 4.2 perhaps?
       
Post is unread #14 May 14, 2008, 11:16 am
Go to the top of the page
Go to the bottom of the page

Krylan
Fledgling
GroupMembers
Posts39
JoinedApr 14, 2005

Blah yeah, 4.2.3
       
Post is unread #15 May 14, 2008, 6:48 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

The next question then. Do you still have this line:

typedef unsigned char bool;

in your mud.h file or have you removed it in favor of letting g++ handle the bool type?
       
Post is unread #16 May 14, 2008, 8:27 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

But he's using gcc, right? So he probably needs the bool typedef, unless they've added it as an extension to gcc.
       
Post is unread #17 May 14, 2008, 8:43 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

They may well have for 4.2 since they decided to break so much other code. One more broken thing won't matter, right? :P
       
Post is unread #18 May 14, 2008, 10:05 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

Well, this would be fairly significant: it would mean changing the standard, as opposed to actually doing what the standard says you are supposed to do. :wink:
       
Post is unread #19 May 14, 2008, 11:08 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

You mean like IE?! Or even zMUD?! Ohnoes!
       
Pages:<< prev 1 next >>