Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2002:
[Freeciv-Dev] Re: [FreeCiv-Cvs] jdorje: Avoid a math error and failed as
Home

[Freeciv-Dev] Re: [FreeCiv-Cvs] jdorje: Avoid a math error and failed as

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [FreeCiv-Cvs] jdorje: Avoid a math error and failed assertion when...
From: Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Sep 2002 13:36:26 -0500

freeciv@xxxxxxxxxxxxxxxxxxx wrote:
This is an automated notification of a change to freeciv cvs, on Mon Sep 30 08:27:46 PDT 2002 = Mon Sep 30 15:27:46 2002 (GMT)
by Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx>

---- Files affected:

freeciv/common dataio.c

---- Log message:

Avoid a math error and failed assertion when dio_put_bit_string is called
with an empty string.  Change the assertion to check the correct value
(the number of bits, not the number of bytes) in any case.

Bug reported by Thomas Strub <ue80@xxxxxxxxxxxxxxxxxxx>.  Patch by me.

I used my fix, not Raimar's.

The fix involves two changes - either of which would prevent the incorrect assertion.

I changed

  size_t bytes = (bits - 1) / 8 + 1;

to

  size_t bytes = (bits + 7) / 8;

to prevent a math error with the unsigned value bits [ (0-1)/8+1 => really large unsigned value]. Note that this changes the intended value of bytes from 1 to 0 if bits is 0 - this is the "correct" value (0 bytes are used, not 1), and the change should not break network compatability.

I also changed

  assert(bytes < 255);

to

  assert(bits < 255);

because it is the latter assertion that is correct. Note, though, that this assertion is more strict and could fail on large bit fields. As I said before, allowing the number of bits to be an unsigned int instead of an unsigned char would pretty much remove this restriction, at the cost of a one-time break in network compatability. Should this be done before the release (network compatability is broken anyway, right?)?

jason



[Prev in Thread] Current Thread [Next in Thread]