[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]
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
- [Freeciv-Dev] Re: [FreeCiv-Cvs] jdorje: Avoid a math error and failed assertion when...,
Jason Short <=
|
|