Ethereal-dev: Re: [Ethereal-dev] smb: comparison between pointer an integer

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxx>
Date: Tue, 29 Jan 2002 13:49:56 -0800 (PST)
> In the current Ethereal CVS, I get this warning:
> 
> packet-smb.c: In function `dissect_read_andx_response':
> packet-smb.c:4793: warning: comparison between pointer and integer
> 
> The code in question takes a pointer, converts it to a guint32,
> and then compares it to NULL.
> 
> Could someone with more knowledge about packet-smb.c fix this?

This is actually just a C issue - the hash table in question maps FIDs
to frame numbers, so the conversion to "guint32" is correct.

What's incorrect is comparing an object of type "guint32" - or any
*other* non-pointer type - with NULL; NULL is, according to C89, a macro
that expands to "an implementation-defined null pointer constant", and a
"null pointer constant" is either "an integral constant expression with
the value 0, or such an expression cast to type 'void *'".

The right answer is to assign the result of "g_hash_table_lookup()" to a
variable of type "gpointer" (that being the return value of
"g_hash_table_lookup()"), comparing *that* with a null pointer constant
and, if it's not equal to a null pointer constant, converting it to a
"guint32".  (This breaks on platforms where the bits of a null pointer
value, converted to an integer, yield a value that's a valid frame
number; however, I've not heard of Ethereal being ported to such a
platform.)

I've checked in a change to do that.