Fix bogus trap on remote_owner check

Some call sites pass a uint8_t to objnum_remote_to_local, which is
zero-extended up to an int.  The check for owner==-1 then fails, causing
the sanity check to trap to the debugger, even though the situation is
normal and harmless.  Switch the type to int8_t to ensure that the value
is not sign/zero-extended.
This commit is contained in:
Kp 2015-03-22 22:48:47 +00:00
parent b4eaa591c8
commit d63be36fb3
3 changed files with 16 additions and 14 deletions

View file

@ -230,8 +230,8 @@ struct owned_remote_objnum
extern int GetMyNetRanking();
extern void ClipRank (ubyte *rank);
objnum_t objnum_remote_to_local(int remote_obj, int owner);
short objnum_local_to_remote(objnum_t local_obj, sbyte *owner);
objnum_t objnum_remote_to_local(uint16_t remote_obj, int8_t owner);
uint16_t objnum_local_to_remote(objnum_t local_obj, int8_t *owner);
owned_remote_objnum objnum_local_to_remote(objnum_t local);
void map_objnum_local_to_remote(int local, int remote, int owner);
void map_objnum_local_to_local(objnum_t objnum);

View file

@ -83,6 +83,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "partial_range.h"
#include "highest_valid.h"
constexpr tt::integral_constant<int8_t, -1> owner_none{};
static void multi_reset_object_texture(const vobjptr_t objp);
static void multi_add_lifetime_killed();
static void multi_send_heartbeat();
@ -257,9 +259,9 @@ void ClipRank (ubyte *rank)
// Functions that replace what used to be macros
//
objnum_t objnum_remote_to_local(int remote_objnum, int owner)
objnum_t objnum_remote_to_local(uint16_t remote_objnum, int8_t owner)
{
if (owner == -1)
if (owner == owner_none)
return(remote_objnum);
// Map a remote object number from owner to a local object number
if ((owner >= N_players) || (owner < -1)) {
@ -267,7 +269,7 @@ objnum_t objnum_remote_to_local(int remote_objnum, int owner)
return(remote_objnum);
}
if ((remote_objnum < 0) || (remote_objnum >= MAX_OBJECTS))
if (remote_objnum >= MAX_OBJECTS)
return(object_none);
auto result = remote_to_local[owner][remote_objnum];
@ -278,10 +280,10 @@ owned_remote_objnum objnum_local_to_remote(objnum_t local_objnum)
{
// Map a local object number to a remote + owner
if ((local_objnum < 0) || (local_objnum > Highest_object_index)) {
return {-1, -1};
return {owner_none, -1};
}
auto owner = object_owner[local_objnum];
if (owner == -1)
if (owner == owner_none)
return {owner, local_objnum};
if (owner >= N_players || owner < -1)
throw std::runtime_error("illegal object owner");
@ -291,7 +293,7 @@ owned_remote_objnum objnum_local_to_remote(objnum_t local_objnum)
return {owner, result};
}
short objnum_local_to_remote(objnum_t local_objnum, sbyte *owner)
uint16_t objnum_local_to_remote(objnum_t local_objnum, int8_t *owner)
{
auto r = objnum_local_to_remote(local_objnum);
*owner = r.owner;
@ -1733,7 +1735,7 @@ static void multi_do_kill(const playernum_t pnum, const ubyte *buf)
count += 1;
killer = GET_INTEL_SHORT(buf + count);
if (killer > 0)
killer = objnum_remote_to_local(killer, (sbyte)buf[count+2]);
killer = objnum_remote_to_local(killer, buf[count+2]);
if (!multi_i_am_master())
{
Netgame.team_vector = buf[5];
@ -1805,10 +1807,10 @@ void
static multi_do_remobj(const ubyte *buf)
{
short objnum; // which object to remove
sbyte obj_owner; // which remote list is it entered in
objnum = GET_INTEL_SHORT(buf + 1);
obj_owner = buf[3];
// which remote list is it entered in
auto obj_owner = buf[3];
Assert(objnum >= 0);

View file

@ -673,7 +673,7 @@ void multi_do_release_robot(const playernum_t pnum, const ubyte *buf)
short remote_botnum;
remote_botnum = GET_INTEL_SHORT(buf + 2);
auto botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[4]);
auto botnum = objnum_remote_to_local(remote_botnum, buf[4]);
if ((botnum < 0) || (botnum > Highest_object_index)) {
return;
@ -707,7 +707,7 @@ void multi_do_robot_position(const playernum_t pnum, const ubyte *buf)
; loc += 1;
remote_botnum = GET_INTEL_SHORT(buf + loc);
auto botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3;
auto botnum = objnum_remote_to_local(remote_botnum, buf[loc+2]); loc += 3;
if ((botnum < 0) || (botnum > Highest_object_index)) {
return;
@ -767,7 +767,7 @@ multi_do_robot_fire(const ubyte *buf)
loc += 1; // pnum
remote_botnum = GET_INTEL_SHORT(buf + loc);
auto botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3;
auto botnum = objnum_remote_to_local(remote_botnum, buf[loc+2]); loc += 3;
gun_num = (sbyte)buf[loc]; loc += 1;
memcpy(&fire, buf+loc, sizeof(vms_vector));
fire.x = (fix)INTEL_INT((int)fire.x);