[PATCH] Fix 2 Show-stopping Compile Errors

EQ2Emulator Development forum.

Moderator: Team Members

Post Reply
jaxl
Posts: 8
Joined: Tue Dec 23, 2008 8:54 pm

[PATCH] Fix 2 Show-stopping Compile Errors

Post by jaxl » Fri Dec 26, 2008 12:42 pm

Using:
Linux fargle 2.6.24-19-xen #1 SMP Sat Jul 12 00:15:59 UTC 2008 x86_64 GNU/Linux
gcc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)

The code will not compile at all without these two changes - both fatal compile errors dealing with loss of precision when casting.

------------- snip ----------------

Index: common/CRC16.cpp
===================================================================
--- common/CRC16.cpp (revision 180)
+++ common/CRC16.cpp (working copy)
@@ -308,7 +308,7 @@
ecx ^= eax; //xor ecx, eax
ecx &= 0xFF; //and ecx, 0FFh
esi = IntArray[ecx]; //mov esi, dword_0_10115D38[ecx*4]
- ecx = (int) buf; //mov ecx, [esp+4+arg_0]
+ ecx = (unsigned long) buf; //mov ecx, [esp+4+arg_0]
eax = eax >> 8; //sar eax, 8
eax &= 0x00FFFFFF; //and eax, 0FFFFFFh
eax ^= esi; //xor eax, esi



Index: client.cpp
===================================================================
--- client.cpp (revision 180)
+++ client.cpp (working copy)
@@ -1336,7 +1336,7 @@
MClients.lock();
for(client_iter=client_list.begin(); client_list.size() > 0 && client_iter!=client_list.end(); client_iter++){
client = *client_iter;
- LogFile->write(EQEMuLog::Debug, "World: ClientList[0x%08x]::FindByAccountID(0x%08x) client[0x%08x]", (int32) this, account_id, client);
+ LogFile->write(EQEMuLog::Debug, "World: ClientList[0x%08x]::FindByAccountID(0x%08x) client[0x%08x]", (ClientList *) this, account_id, client);
if (client->GetAccountID() == account_id) {
ret = client;
break;

link2009
Retired
Posts: 390
Joined: Fri Aug 10, 2007 5:59 pm
Location: POrTal
Contact:

Re: [PATCH] Fix 2 Show-stopping Compile Errors

Post by link2009 » Fri Dec 26, 2008 6:48 pm

Is this an assembly fix?
Image
-Vecinu de la Patru

jaxl
Posts: 8
Joined: Tue Dec 23, 2008 8:54 pm

Re: [PATCH] Fix 2 Show-stopping Compile Errors

Post by jaxl » Sat Dec 27, 2008 12:06 am

Nothing is different in the assembly - its just the variable casting.. The reason GCC is pissy about it is the signed int can store less information than the unsigned long despite both being 32bit; one makes room for the 2's complement. The variable ecx is defined in C prior to the assembly block as unsigned long so it thinks that you could loose a significant bit in the translation when you smush "buf" into it.

So all I did was fix the casting to match:

- ecx = (int) buf; //mov ecx, [esp+4+arg_0]
+ ecx = (unsigned long) buf; //mov ecx, [esp+4+arg_0]


Specifically, this is the error that GCC spits out:

Code: Select all

root@fargle:/home/sblackstone/SVN/Source/World# make
gcc -c -Wall -Wuninitialized -Wwrite-strings -Wcast-qual  -Wcomment -Wcast-align -Wno-deprecated -O -pthread -pipe -DEQ2 -DWORLD -DFX -D_GNU_SOURCE -DINVERSEXY -I/usr/include -I/usr/include/mysql -I//usr/mysql/include -I./LUA/include -L/usr/lib/mysql -lmysqlclient ../common/CRC16.cpp -o ../common/CRC16.o
../common/CRC16.cpp: In function 'long unsigned int CRC16(const unsigned char*, int, int)':
../common/CRC16.cpp:311: error: cast from 'const unsigned char*' to 'int' loses precision
make: *** [../common/CRC16.o] Error 1

link2009
Retired
Posts: 390
Joined: Fri Aug 10, 2007 5:59 pm
Location: POrTal
Contact:

Re: [PATCH] Fix 2 Show-stopping Compile Errors

Post by link2009 » Sat Dec 27, 2008 9:24 am

Okay I see, you changed the casting from a signed int to an unsigned long to fix the compiler's complaint.

Could you tell me what distribution you're running?
Image
-Vecinu de la Patru

jaxl
Posts: 8
Joined: Tue Dec 23, 2008 8:54 pm

Re: [PATCH] Fix 2 Show-stopping Compile Errors

Post by jaxl » Sat Dec 27, 2008 1:29 pm

Ubuntu Hardy Heron
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
GNU ld (GNU Binutils for Ubuntu) 2.18.0.20080103
Linux fargle 2.6.24-19-xen

jaxl
Posts: 8
Joined: Tue Dec 23, 2008 8:54 pm

Re: [PATCH] Fix 2 Show-stopping Compile Errors

Post by jaxl » Sat Dec 27, 2008 1:33 pm

And the other error is basically the same thing in client.cpp...

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests