Ethereal-dev: Re: [Ethereal-dev] Assigning -1 to unsigned int

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

From: "Ronnie Sahlberg" <sahlberg@xxxxxxxxxxxxxxxx>
Date: Mon, 25 Feb 2002 20:13:50 +1100
Well,
In XDR these values are signed 32 bit quantities.

In theory one could change all these negative values from -1 to 0xffffffff
etc
and make sure everytime we read one of them using tvb_get_ntohl() we store
it in a guint32.

It would be a lot of work and a lot of auditing.

Anyhow, we would still have the same problem in that when we want to print
this unsigned integers
we would have to print them as signed integers.
(Well, I do not want to see "Code: YP_NOMAP (0xffffffff)" when looking at
something where the XDR definition
on ypserv.x states the value is -1.)

Would it not be sufficient to just make sure the integer part in a value
string is exactly a 32bit quantity
(and perhaps not an int?)
i.e. declaring its type as gint32
and then rely on the observations that C requires 2-complement for the
representation of negative integer values
and that (I guess) all popular compilers would just "do the right thing"
even if we do some invalid signed/unsigned
implicit casts.

Well, say in packet-smb.c we assume that we can store an int in a pointer
variable which also violates the C standard
and which would/should actually crash and burn ethereal totally if we would
ever try to run it on a DEC20, (and also on a VAX I suspect).

---
My opinion is that if we just make sure that the integer part of a value
string is always a 32bit integer, even on 64bit platforms,
then it would be OK to keep doing these sign violations we do.
(since any compiler NOT doing what we want/expect would already break on all
other major multiplatform applications there are)
And also place a comment in the definition of value_string that the integer
part can not be just an int but must be a 32bit integer due to us
assuming it is safe to implicitly cast signed/unsigned on these quantities.

----- Original Message -----
From: "Guy Harris"
Sent: Monday, February 25, 2002 7:00 PM
Subject: Re: [Ethereal-dev] Assigning -1 to unsigned int


> On Mon, Feb 25, 2002 at 01:54:21AM -0600, Albert Chin wrote:
> > We also have things like the following in packet-ypserv.c:
> >   static const value_string ypstat[] =
> >   {
> >           {       1,      "YP_TRUE"       },
> >           {       2,      "YP_NOMORE"     },
> >           {       0,      "YP_FALSE"      },
> >           {       -1,     "YP_NOMAP"      },
> >           {       -2,     "YP_NODOM"      },
> >           {       -3,     "YP_NOKEY"      },
> >   ...
>
> Those require more thought, given that I suspect that the NIS protocol
> definition actually says they *are* negative.
>
> We might want to have separate signed and unsigned varsions of
> "value_string" (if we could write Ethereal in C99, you might be able to
> make "value" a union and explicitly initialize the appropriate union
> member - I *think* C99 might finally fix that immensely irritating
> deficiency in C89 - but we can't rely on C99).
>
> _______________________________________________
> Ethereal-dev mailing list
> Ethereal-dev@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-dev