Skip to content

Fix a narrowing conversion#964

Merged
OmniBlade merged 1 commit into
TheAssemblyArmada:vanillafrom
th-otto:PR-16
Jul 14, 2026
Merged

Fix a narrowing conversion#964
OmniBlade merged 1 commit into
TheAssemblyArmada:vanillafrom
th-otto:PR-16

Conversation

@th-otto

@th-otto th-otto commented Mar 20, 2024

Copy link
Copy Markdown
Contributor

No description provided.

@OmniBlade OmniBlade left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments apply to both games code, seems like a lot of changes to just silence a warning?

Comment thread redalert/defines.h Outdated
*/
#ifdef VIRGIN_CHEAT_KEYS
#define PARM_PLAYTEST 0xF7DDC227 // "PLAYTEST"
#define PARM_PLAYTEST 0xF7DDC227UL // "PLAYTEST"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint32_t is not unsigned long on all platforms.

Comment thread redalert/target.h Outdated
{
Target.Sub.Exponent = RTTI_NONE;
Target.Sub.Mantissa = -1;
Target.Sub.Mantissa = (1UL << TARGET_MANTISSA) - 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is equivalent?

Comment thread tiberiandawn/init.cpp Outdated
* 08/19/1995 JLB : Created. *
*=============================================================================================*/
long Obfuscate(char const* string)
uint32_t Obfuscate(char const* string)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long type needs to go as its width varies between platforms but it should just change to int to match the ra code?

@th-otto

th-otto commented Apr 15, 2024

Copy link
Copy Markdown
Contributor Author

It's not only to get rid of the warning. Obfuscate() currently operates on an int, but in TD returns a long (unlike RA, which currently returns an int). Comparing that to a constant like 0xF7DDC227 may fail if the function actually returned 0xFFFFFFFFF7DDC227 because it was sign-extended to long. The only safe way is to declare them to return unsigned int (or uint32_t in this case), since this is what they actually calculate.

@OmniBlade

Copy link
Copy Markdown
Contributor

I'd be happy to see it changed to unsigned int in both cases.

@OmniBlade OmniBlade left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the change made in this PR have been merged as part of other work, the remaining fixes for target mantissa still look useful however.

@OmniBlade
OmniBlade merged commit 110d13a into TheAssemblyArmada:vanilla Jul 14, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants