(SCT_MAXDEF): Make it equal the maximum sector type, not the maximum

plus one.  Users changed.  This indirectly fixes off-by-one loop
bounds in budg(), show_sect_build(), show_sect_stats() and
show_sect_capab().  The show bugs were harmless: the loops ran into
the sentinel, which they ignore.  The budg bug was serious: the loop
ran into the entries for SCT_EFFIC.  This lead to a bogus line in the
budget, printing of a null pointer, and doubled sector build cost.
Budget priorities masked this bug until rev. 1.25.
This commit is contained in:
Markus Armbruster 2006-06-22 17:10:26 +00:00
parent f9588063ff
commit 2d99971a7f
4 changed files with 6 additions and 6 deletions

View file

@ -151,9 +151,9 @@ struct dchrstr {
#define SCT_ENLIST 31 /* enlistment center */ #define SCT_ENLIST 31 /* enlistment center */
#define SCT_PLAINS 32 /* plains sector */ #define SCT_PLAINS 32 /* plains sector */
#define SCT_BTOWER 33 /* Bridge tower */ #define SCT_BTOWER 33 /* Bridge tower */
#define SCT_MAXDEF 33 /* highest sector type in header files */
#define SCT_EFFIC 34 /* used in update & budget */ #define SCT_EFFIC 34 /* used in update & budget */
#define SCT_MAXDEF 34 /* highest sector type in header files */
#define getsect(x, y, p) ef_read(EF_SECTOR, sctoff((x), (y)), (p)) #define getsect(x, y, p) ef_read(EF_SECTOR, sctoff((x), (y)), (p))
#define putsect(p) ef_write(EF_SECTOR, sctoff((p)->sct_x, (p)->sct_y), (p)) #define putsect(p) ef_write(EF_SECTOR, sctoff((p)->sct_x, (p)->sct_y), (p))
@ -163,7 +163,7 @@ struct dchrstr {
/* things relating to sectors */ /* things relating to sectors */
extern int sctoff(coord x, coord y); extern int sctoff(coord x, coord y);
extern struct dchrstr dchr[SCT_MAXDEF + 1]; extern struct dchrstr dchr[SCT_MAXDEF + 2];
extern struct dchrstr bigcity_dchr; extern struct dchrstr bigcity_dchr;
#define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG) #define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG)

View file

@ -64,7 +64,7 @@ int
budg(void) budg(void)
{ {
int i; int i;
long p_sect[SCT_MAXDEF+1][2]; long p_sect[SCT_MAXDEF+2][2];
int taxes, Ncivs, Nuws, bars, Nbars, mil; int taxes, Ncivs, Nuws, bars, Nbars, mil;
int ships, sbuild, nsbuild, smaint; int ships, sbuild, nsbuild, smaint;
int units, lbuild, nlbuild, lmaint; int units, lbuild, nlbuild, lmaint;
@ -198,7 +198,7 @@ calc_all(long p_sect[][2],
int etu = etu_per_update; int etu = etu_per_update;
mil_dbl_pay = 0; mil_dbl_pay = 0;
memset(p_sect, 0, sizeof(**p_sect) * (SCT_MAXDEF+1) * 2); memset(p_sect, 0, sizeof(**p_sect) * (SCT_MAXDEF+2) * 2);
*taxes = *Ncivs = *Nuws = *bars = *Nbars = *mil = 0; *taxes = *Ncivs = *Nuws = *bars = *Nbars = *mil = 0;
*ships = *sbuild = *nsbuild = *smaint = 0; *ships = *sbuild = *nsbuild = *smaint = 0;
*units = *lbuild = *nlbuild = *lmaint = 0; *units = *lbuild = *nlbuild = *lmaint = 0;

View file

@ -44,7 +44,7 @@
* Table of sector designations * Table of sector designations
* Initialized on startup from sect.config and deity custom config (if any). * Initialized on startup from sect.config and deity custom config (if any).
*/ */
struct dchrstr dchr[SCT_MAXDEF + 1]; struct dchrstr dchr[SCT_MAXDEF + 2];
/* /*
* Table of infrastructure types * Table of infrastructure types

View file

@ -112,7 +112,7 @@ update_main(void *unused)
logerror("done preparing sectors."); logerror("done preparing sectors.");
logerror("producing for countries..."); logerror("producing for countries...");
for (x = 0; x < MAXNOC; x++) { for (x = 0; x < MAXNOC; x++) {
long p_sect[SCT_MAXDEF+1][2]; long p_sect[SCT_MAXDEF+2][2];
memset(p_sect, 0, sizeof(p_sect)); memset(p_sect, 0, sizeof(p_sect));
mil_dbl_pay = 0; mil_dbl_pay = 0;