Hi,
On Sat, 16 Jun 2001, Matt wrote:
> To exercise code in different/new ways, I ran freesci under purify while
> freesci was "playing" KQ1 enhanced. This was with scaling factor of 1,
> with trilinear filtering (and a bunch of other things) on.
>
> (NOTE TO USERS: KQ1 IS NOT PLAYABLE)
None of the perceived problems you found should be specific to KQ1, BTW.
As far as they can tell, they apply to every game.
> The function graph_map_ega_color() appears to read uninitialized memory
> (at kgraphics.c:223).
Yes. The values it reads there are 'dont-care' values. Colors have a
bitmask determining whether their visual/priority/control values are set;
if the bitmask says "this value is not relevant", then the contents of the
corresponding field entry can be disregarded (see gfx_system.h) and are
not set explicitly (the correct value to set them to would probably be
semi-random numbers, to expose places where these values are being used
regardless).
The places you described acquire complete copies of the data structures
(colors are treated as primitive values and not usually referenced to in
FreeSCI) and (possibly) change portions of them.
[...]
> The last one I think I actually have figured out. There's a complaint
> about an uninitialized memory read @ gfx_pixmap_scale.c:301
> (gfx_apply_delta). I appears that the delta array is not always
> fully initialized:
>
> 1) Line 277 and 282. Only the first 3 ints in the 4 int array would be set
> to 0 by the memset operation.
That's because the fourth value is explicitly set to a different value in
the next line.
> 2) When the case is the last "else if" (transparent) in
> gfx_get_pixel_delta, only the 3rd int the the delta array is initialized.
> All the other ints will be uninitialized. So, when gfx_apply_delta is
> called, uninitialized memory is read.
Yes. The idea behind this is that, if it's completely transparent, we
don't really have to care whether it's transparent blue or transparent
octarine.
> 1) In gfx_get_pixel_delta, if the case is transparent, only the last int
> in the color array is initialized. None of the other ints are. When
> gfx_apply_delta is called, uninitialized memory is read.
I think that's the same as (2) above, please correct me if I'm wrong.
> I don't know what this should be initialized to, as this code is kind of
> over my head (maybe more comments?) so this fix is not included in my
> patch.
I have to admit that the basic ideas behind it are not explicitly
stated anywhere in the code; particularly an explanation of the actual
algorithm is missing. A functional description of the algorithm (though
obviously not of this particular implementation) can be derived from the
official OpenGL specification.
The piece of information you were probably missing (indicated, but never
explicitly stated in lines 348, 352 and 305) is that the four-tuples we're
using all over the place contain red, green, blue, and alpha values at
indices 0, 1, 2, and 3 respectively. All values are stored as 24 bit
values (actually, they should also work OK as 32 bit values, with
appropriate changes, but I can't think of any reason to change this ATM).
llap,
Christoph