Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] Re: (PR#3700) Recall previous focus unit
Home

[Freeciv-Dev] Re: (PR#3700) Recall previous focus unit

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#3700) Recall previous focus unit
From: "a-l@xxxxxxx" <a-l@xxxxxxx>
Date: Sat, 19 Apr 2003 06:49:18 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Sat, 12 Apr 2003 12:21:55 -0700
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:

> > Ok, I changed it to use a unit struct pointer instead, checking for
> > NULL.
> 
> I'm pretty sure that's unsafe.  If the unit is destroyed or reallocated 
> you'll end up with a non-NULL pointer pointing to an arbitrary piece of 
> memory.  The original bug, if it exists at all, can only be solved by 
> something much more complex (and probably not worthwhile).

That's why I used unit id in the first patch. How silly, I wasn't
thinking here. I guess I could have made the storage non-static and
reset it to -1 in client_remove_unit(), if that's the appropriate
place to nest up loose ends. Or, in that case maybe I could use a unit
struct pointer after all, since that function sets punit_focus to NULL.
You mentioned reallocation - That would also apply to punit_focus,
wouldn't it? Let's do it correctly.

> - Is it possible for the previous_focus_id unit to die, and its ID to be
> taken by a different unit?  This would give buggy, but rather unharmful,
> results.  Is there an easy way to prevent this?

At least I changed find_unit_by_id() to player_find_unit_by_id(), so
that, if the bug exists, you don't focus another player's unit.

New patch. This version also avoids setting focus unit to NULL if
the previous unit was destroyed.


Arnstein



Attachment: recall_focus-3.diff.gz
Description: recall_focus-3.diff.gz


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