Bug #6239 Compiler Complains of "Result is Always False"

Submitted: 25 Oct 2004 2:49 Modified: 9 Nov 2004 16:41
Reporter: James Barwick Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S1 (Critical)
Version:4.1.6-gamma OS:Linux (SuSE 9.1 (amd64))
Assigned to: Lars Thalmann CPU Architecture:Any

[25 Oct 2004 2:49] James Barwick
Description:
Compiler Complains of "Result is always false do to limited data type"

Application: 

client/mysqlbinlog.cc

Line 222 and Line 787 refer to the CONSTANT DEFINE "packet_error" defined in include/mysql_com.h line 180 as:

#define packet_error (~(unsigned long) 0)

The if statement on lines 222 and 787 complain of "always false" conditions.

How to repeat:
compile the program

Suggested fix:
To remove the error:

in the application client/mysqlbinlog.cc

change line 207 to read:

from

uint packet_len = my_net_read(net);

to

ulong packet_len = my_net_read(net);

change line 750-751 to read:

from

uint len, logname_len;

to

ulong len;
uint logname_len;

Changing the above lines removed the "warning".  Please recommend alternative if the above fixes "break" anything.
[26 Oct 2004 4:58] James Barwick
I realized that the suggested fix is NOT a fix and only removes the compiler warning!!!
However, it will still ALWAYS return false!!!
My Mistake! (Woke up in the middle of the night with cold sweats!)

the function returns a uint?  Right!?  I haven't checked, but I suspect it does.
If the function returns a uint, and the packet_error is defined as a ulong ~0, then 
we have packet_error = 0xFFFFFFFF

The uint return result...if it's ever going to return a -1, will be set to a uint of 0x0000FFFF if it is indeed returning a uint, not a int.  If it was  an int, then I suspect if the function calls return a -1, the compiler would be smart enough to return a 0xFFFFFFFF integer.

But..we need to be sure!

So, if the my_xxx functions are indeed returning a uint, then let's let them return a uint and either
use a packet_error defined as (uint)~0 or cast the packet_error to a (uint) in these if statements...

SORRY GUYS!!!
[26 Oct 2004 6:42] James Barwick
I have fixed the declarations to uint on my source (now back to distrib).
Now...have the compiler warnings...so..

Line 222

From

else if (packet_len == packet_error)

to

else if (packet_len == ((uint)packet_error))

Line 787

From

if (len == packet_error)

To

if (len == ((uint)packet_error))

Now...due to my limitted brain capacity...PLEASE tell me if I'm on the right track now!!!
(well, at least the compiler warnings went away)

Thanks...
[26 Oct 2004 9:06] Lars Thalmann
Thanks for notifying us of this problem, James.

Your first idea was correct.
my_net_read() returns ulong.

Your second idea works if length is always 
smaller than 0xffff, but since packet_error is
ulong, it is better to use the larger types.

I have made a patch.  Thanks again for your
comments.
[9 Nov 2004 16:41] Lars Thalmann
The bug fix for this has now been pushed.  Will be part of 4.1.8 release.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.