Home » MODDING HQ 1.13 » v1.13 Bug Reports » possible Item Flag overflow
possible Item Flag overflow[message #315201] Tue, 05 February 2013 21:52 Go to next message
Flugente

 
Messages:3462
Registered:April 2009
Location: Germany
Hi,

upon adding new flags to items I stumbled upon a small error. As you know, we have a few ItemFlags, where we can set up to 32 different flags, which denote item properties. Like this:

ItemTypes.h:
UINT32	wh40kflags;								// flag mask with wh40k specific flags (for power armor, plasma guns...)

#define WH40K_TIMEBUBBLE_EXPLOSION		0x80000000	//2147483648	// time bubble explosion item

Xml_Items.cpp:
pData->curItem.wh40kflags   = (UINT32) atol(pData->szCharData);

XML:
128


However, something weird happened when I used the last flag, as seen above. Basically in XML_Items.cpp, pData->szCharData was 2147483648, but pData->curItem.wh40kflags was returned as 2147483647. This might very well be the result of atol (which returns a long, which is propably signed by convention) and the (UINT32)-cast not behaving so well together. Even weirder, both the xml entries 2147483648 and 2147483647 returned 2147483647 afterwards.

I am not sure who to fix this (I always understood our code in the way that an UINT32 gives us 32 flags and not 31). I'm happy to learn if someone has a solution (or, better, can explain the error in my thoughts).

So far, I'd advise any modder using flagmasks to carefully observe item behaviour for the last flag, and I will personally leave the last one unused till further notice.


Re: possible Item Flag overflow[message #315211] Wed, 06 February 2013 00:37 Go to previous messageGo to next message
Sam Hotte

 
Messages:2012
Registered:March 2009
Location: Middle of Germany
I'm no coder but if the long is indeed signed then 2,147,483,647 is the maximum value a signed 32bit integer can be.
So if you operate the signed 32bit integer on the unsigned one with a value greater than 2,147,483,647 integer/binary overflow turns this into signed minimum which is
-2,147,483,648.

"Reverting" this results in the signed maximum, hence the 2,147,483,647 again.

In other words, if you also operate with signed 32bit integer, the maximum value to be used in unsigned should infact be ([2^31]-1).

Re: possible Item Flag overflow[message #315212] Wed, 06 February 2013 01:10 Go to previous messageGo to next message
tais

 
Messages:808
Registered:February 2008
Location: NL
it could be the urge to just say something but he's kinda asking for a solution and you're just writing down what he already knows...

like this

[21:09]

[Updated on: Wed, 06 February 2013 01:15] by Moderator



Re: possible Item Flag overflow[message #315213] Wed, 06 February 2013 01:22 Go to previous messageGo to next message
Sam Hotte

 
Messages:2012
Registered:March 2009
Location: Middle of Germany
Very well possible that i misunderstood the post but i thought he was wondering why the atol returned the "weird" value.
So never mind, just ignore my posting then .. Smile
Re: possible Item Flag overflow[message #315214] Wed, 06 February 2013 01:29 Go to previous messageGo to next message
DepressivesBrot

 
Messages:3806
Registered:July 2009
He was wondering, but telling him that casting unsigned->signed->unsigned might mess things up is about as helpful as just writing 'postcount++' without disguise.


Re: possible Item Flag overflow[message #315261] Thu, 07 February 2013 22:55 Go to previous messageGo to next message
Flugente

 
Messages:3462
Registered:April 2009
Location: Germany
Thanks to glorious Tais, this problem is now solved (I'll commit a fix). Refer cookies to him.

:shake: :party:

[Updated on: Thu, 07 February 2013 22:55] by Moderator



Re: possible Item Flag overflow[message #315265] Fri, 08 February 2013 09:34 Go to previous message
JMich

 
Messages:569
Registered:January 2011
Location: Greece
Flugente
Refer cookies to him.
:shake: :party:

He's the Dutch, he should be sending cookies to us.
Previous Topic: Enemy hear knockdown
Next Topic: Build SVN5862 Grenaded Enemy Bug
Goto Forum:
  


Current Time: Sat Apr 20 19:28:49 EEST 2019

Total time taken to generate the page: 0.01702 seconds