From 9989c5b3ec8898aee7a486ec883de51d8b6a7a2d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 5 Mar 2004 07:56:50 +0000 Subject: [PATCH] (sctstr, shpstr, lndstr): Use `short' instead of `unsigned short' for item storage. Rationale: Permitted values are 0..M, where M depends on the container. The largest M is ITEM_MAX (9999). Benign overflow/underflow occurs at those limits. Catastrophic overflow/underflow occurs at the limits of the underlying data type. For `unsigned short', any underflow is catastrophic. For `short', benign undeflow happens long before catastrophic underflow. Moreover, unsigned arithmetic tends to trip up unwary programmers. --- include/land.h | 2 +- include/sect.h | 6 +++--- include/ship.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/land.h b/include/land.h index 10fb3fe0..7ee2e258 100644 --- a/include/land.h +++ b/include/land.h @@ -71,7 +71,7 @@ struct lndstr { s_char lnd_rpath[RET_LEN]; /* retreat path */ u_char lnd_rad_max; /* max radius for this unit */ u_char lnd_scar; /* how experienced the unit is (not used) */ - u_short lnd_item[I_MAX+1]; /* amount of items on board */ + short lnd_item[I_MAX+1]; /* amount of items on board */ u_short lnd_pstage; /* plague stage */ u_short lnd_ptime; /* how many etus remain in this stage */ short lnd_land; /* pointer to transporting unit */ diff --git a/include/sect.h b/include/sect.h index 5750796d..6daa05ae 100644 --- a/include/sect.h +++ b/include/sect.h @@ -71,9 +71,9 @@ struct sctstr { natid sct_oldown; /* old owner of sector (for liberation) */ u_char sct_updated; /* Has this sect been updated? */ u_char sct_off; /* Should this sector produce? */ - u_short sct_item[I_MAX+1]; /* amount of items stored here */ - u_short sct_del[I_MAX+1]; /* delivieries */ - u_short sct_dist[I_MAX+1]; /* distribution thresholds */ + short sct_item[I_MAX+1]; /* amount of items stored here */ + short sct_del[I_MAX+1]; /* delivieries */ + short sct_dist[I_MAX+1]; /* distribution thresholds */ u_short sct_mines; /* number of mines */ u_short sct_pstage; /* plague stage */ u_short sct_ptime; /* how many etus remain in this stage */ diff --git a/include/ship.h b/include/ship.h index 4a5c9703..1ccb8ee1 100644 --- a/include/ship.h +++ b/include/ship.h @@ -93,7 +93,7 @@ struct shpstr { short shp_lstart[TMAX]; /* How much do we pick up at the start */ short shp_lend[TMAX]; /* How much do we pick up at the end */ u_char shp_autonav; /* autonavigation flags */ - u_short shp_item[I_MAX+1]; /* amount of items on board */ + short shp_item[I_MAX+1]; /* amount of items on board */ u_short shp_pstage; /* plague stage */ u_short shp_ptime; /* how many etus remain in this stage */ time_t shp_access; /* Last time mob was updated (MOB_ACCESS) */