Commit graph

3742 commits

Author SHA1 Message Date
0e3bf4c38a Update change log for 4.3.24 2010-01-19 08:40:43 +01:00
b8f5eaff0b Clean up dead stores
Does not change optimized code (gcc -O).

Spotted by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
3650587dab Fix navigate/march crash on funny path arguments
For an argument consisting of a valid path plus whitespace,
do_unit_move() eventually passed the whitespace suffix to parse(),
then dereferenced player->argp[0].  But that was null.

Broken in commit 0c12d837, v4.3.7.  Trivial for players to trigger.
2010-01-19 08:40:42 +01:00
6c8ba9c3fd Fix player_login() not to print null pointer
When the input line contains only whitespace, player->argp[0] is null
after parse().  This condition was not checked, comtch() returned
M_IGNORE, and code handling that printed the null pointer.  Some
systems (GNU, Windows) deal gracefully with printing null strings,
others crash.  Trivial to trigger remotely.

Before the fix, the value of parse() was assigned, but never used, and
that was spotted by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
8195d5fb88 Clean up useless getnatp() in conv(), nav_map(), tele()
Spotted by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
8ededa44f9 Move -h to the end of the emp_server -h output
This is consistent with the other programs.
2010-01-19 08:40:42 +01:00
390841a40a Make empire, empsched and files catch extra operands
This also avoids a dead increment ap++ in src/client/main.c reported
by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
fe0ef18e2b Make empire and files not print usage on bad option
Point to -h instead.  This is consistent with the other programs.
2010-01-19 08:40:42 +01:00
6386583c1c Fix lwpReschedule()'s assertion "have runnable thread"
If there is no runnable thread, we're deadlocked.  lwpReschedule() has
an assertion to catch this.  But it didn't work, and the code
following it would crash then.  Can't actually happen, because the
EventHandler thread is always runnable.  Spotted by the Clang Static
Analyzer.
2010-01-19 08:40:42 +01:00
43322c1cb7 Declare cant_listen() noreturn
Local analysis can now easily find out what's up.  Before, inter-
procedural analysis was required.  The Clang Static Analyzer
complained about a dereference of res that is actually fine.
2010-01-19 08:40:20 +01:00
9061ae7b9d Make CANT_HAPPEN() more obvious for static analysis
Local analysis can now easily find out what's up.  Before,
whole-program analysis was required.  The Clang Static Analyzer
complained about code that is actually fine.
2010-01-19 08:40:18 +01:00
ad80846283 Fix getpath() not to crash when path exceeds MAX_PATH_LEN
Trivial for players to trigger.  Broken in commit 0b0612ea, v4.3.16.
Spotted by the Clang Static Analyzer.
2010-01-19 08:40:17 +01:00
9b62b35424 Fix oops on escort, recon, and launch of satellite
Broken in commit 528df9ac, v4.3.23.  pln_equip() recovered fine.
2010-01-19 08:40:17 +01:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
6e30ba88a4 Fix trailing whitespace 2010-01-19 08:40:17 +01:00
227854bca2 Stop ship and land unit movement on interdiction with no damage
Movement stops when shp_interdict() or lnd_interdict() report
interdiction.  However, they reported it only when there was
interdiction damage.

Zero interdiction damage commonly happens when interdicting missiles
miss, or all bombers abort.  Stopping regardless of damage makes more
sense there.

Moreover, not stopping is buggy: do_unit_move() needs to take care not
to wipe out updates made by interdiction to the moving ships or land
units.  It does so only when it stops.  Updates made by interdiction
without interdiction damage could get wiped out, triggering a seqno
mismatch oops.

Known ways moving ships and land units can get updated by interdiction
despite there is no interdiction damage:

* Interdicting bombers get intercepted by planes based on a navigating
  carrier, carrier gets charged petrol.  The bug wipes out the petrol
  use.

* Marching land units get interdicted by planes, but all planes miss.
  Sufficiently large collateral damage to the sector can still damage
  the land units.  The bug wipes out the damage to land units.

To make shp_interdict() and lnd_interdict() report interdiction
regardless of damage, change lnd_missile_interdiction(),
lnd_fort_interdiction(), lnd_mission_interdiction(),
shp_missile_interdiction(), shp_fort_interdiction(),
shp_mission_interdiction() to return whether there was interdiction.
Before, they returned whether there was damage.

Change unit_interdict(), perform_mission(), perform_mission_land(),
perform_mission_ship(), perform_mission_msl(), and
perform_mission_bomb() to return -1 for no interdiction, so that
callers can distinguish no interdiction from interdiction with no
damage.
2010-01-19 08:38:18 +01:00
05b56fa942 Clean up poorly chosen loop control variable names
Calling a counting loop's control variable q or z is tasteless
bordering on actively misleading.
2010-01-19 08:38:16 +01:00
3ce3b2e387 Simplify perform_mission() 2010-01-19 08:38:16 +01:00
5e77193cf0 Remove struct genlist member cp 2010-01-19 08:38:16 +01:00
2e69a24402 Remove perform_mission_land(), perform_mission_ship() parameter md 2010-01-19 08:38:16 +01:00
d471d684be Split up perform_mission()
Move code out of perform_mission() into new perform_mission_land(),
perform_mission_ship(), perform_mission_msl(), perform_mission_bomb().
2010-01-19 08:38:16 +01:00
0706836708 Make lnd_mission_interdiction() apply damage
To make lnd_mission_interdiction() work just like
shp_mission_interdiction().
2010-01-19 08:37:07 +01:00
f8e7fb8ca8 New lnd_mission_interdiction()
Factored out of lnd_interdict().  No functional change.
2010-01-19 08:37:05 +01:00
cd8fe31eda New shp_mission_interdiction()
Factored out of shp_interdict().  No functional change.
2010-01-19 08:37:05 +01:00
d4f1e02273 Fix att_reacting_units() to initialize ulist member eff
This left initial eff at zero.  No effect, because its only user
get_land() ignores efficiency increases.
2010-01-19 08:37:05 +01:00
ec75a407c7 Simplify ask_olist and get_dlist() not to re-read land units
getland() is obviously redundant in get_dlist(), because the land unit
can't have changed since the previous read.

What's up with ask_olist() is less obvious.  For each capable land
unit, ask_olist() asks the player whether to attack with it.  If it
attacks, it gets copied into olist.  Since asking the player yields
the processor, these copies can become stale.  However, re-reading
fixes that just for the last one.  Moreover, the code copes with stale
copies just fine: ask_olist() is always directly followed by
att_get_offense() or att_move_in_off(), and both replace the
potentially stale copy in olist.
2010-01-19 08:37:05 +01:00
ba0d4d0036 Remove get_land() parameter uid
For all remaining calls, the uid can be obtained from parameter llp.
2010-01-19 08:37:05 +01:00
b824495bad Inline get_land()'s "first time" case into its callers
ask_olist() and get_dlist() called get_land() with llp->chrp still
null, which made it initialize parts of llp instead of performing its
usual integrity check.  att_reacting_units() had the initialization
inline.  Change the other two to match, and simplify get_land().  No
functional change.
2010-01-19 08:37:05 +01:00
ef7ea8934f Drop last parameter of shp_hit_mine() and lnd_hit_mine() 2010-01-19 08:37:05 +01:00
a90b3e8819 Simplify use of shp_missile_interdiction()
shp_missile_interdiction() does nothing when there are no suitable
targets.  Its users avoid to call it when there are none, probably to
save a few cycles.  Optimize shp_missile_interdiction() for that case,
and simplify the callers.
2010-01-19 08:37:05 +01:00
132b52a475 Make empdump call ef_close() regardless of -n
Avoiding ef_close() with -n is not necessary, so don't.
2010-01-19 08:37:05 +01:00
3a5e23a020 Rearrange struct sctstr slightly to expose commonalities with units
Nice bonus: space needed for sectors shrinks some 4%.  Size of game
state could shrink perhaps 1-2%.
2010-01-19 08:37:05 +01:00
aa659c7754 Narrow struct sctstr member sct_mobil to char
To bring it in line with unit mobility.
2010-01-19 08:37:05 +01:00
ca2dba33f0 Make struct sctstr member sct_effic signed
To bring it in line with unit efficiency.
2010-01-19 08:37:05 +01:00
76575df96b Streamline fortgun()'s efficiency comparison
Use >= 60 instead of > 59, for consistency with similar comparisons
elsewhere.
2010-01-19 08:37:05 +01:00
da48ba6d13 Fix sloppy sanity check for mobility going negative in transport
Assignment to sct_mobil was vulnerable to integer underflow.  Should
not happen, as move_ground() never returns a cost exceeding available
mobility.
2010-01-19 08:37:05 +01:00
2fa5f65257 Generation numbers to catch write back of stale copies
Oops when a stale copy is written back, i.e. the processor was yielded
since the copy was made.  Such bugs are difficult to spot.  Sequence
numbers catch them when they do actual harm (they also catch different
bugs).  Generation numbers catch them even when they don't.

New ef_generation to count generations.  Call new ef_make_stale() to
increment it whenever the processor may be yielded.

New struct emptypedstr member generation.  To conserve space, make it
a bit-field of twelve bits, i.e. generations are only recorded modulo
2^12.  Make sure all members of unit empobj_storage share it.  It is
only used in copies; its value on disk and in the cache is
meaningless.  Copies with generation other than ef_generation are
stale.  Stale copies that are a multiple of 2^12 generations old can't
be detected, but that is sufficiently improbable.

Set generation to ef_generation by calling new ef_mark_fresh() when
making copies in ef_read() and ef_blank().  nav_ship() and
fltp_to_list() make copies without going through ef_read(), and
therefore need to call ef_mark_fresh() as well.  Also call it in
obj_changed() to make check_sect_ok() & friends freshen their argument
when it is unchanged.

New must_be_fresh() oopses when its argument is stale.  Call it in
ef_write() to catch write back of stale copies.
2010-01-19 08:36:01 +01:00
358aee203e Store sequence numbers more compactly
Store them and ef_type in bit-fields.

Allocate eight bits for ef_type.  Values range from 0 to EF_GAME
(currently 16), so this is plenty.

Allocate twelve bits for sequence numbers.  Sequence number mismatches
are now missed when the numbers are equal modulo 2^12.  Still
sufficiently improbable.

Common machines store the bit-fields in a 32 bit word.  There are
twelve bits left in that word for future use.  Total savings 16 bits,
which is exactly what the previous commit spent on wider uids on
common machines.
2010-01-19 08:31:10 +01:00
ba2044be18 Store uids as int to support more sectors and units
Before, they were stored as short.  Wider uids use more space, but the
next commit will recover it by narrowing other members.

The use of short has always limited the number of ships, planes, land
units and nukes to SHRT_MAX (commonly 32768).  Only the most extreme
games ever came close.

Commit 49780e2c (v4.3.12) added struct sctstr member sct_uid to make
struct empobj member uid work for sectors.  This made the limit apply
to sectors as well.  We've had games with more than 32768 sectors.
2010-01-19 08:26:42 +01:00
18148f03fa Fix new_seqno()'s recovery from seqno mismatch
A sequence number mismatch occurs when an invalid copy (with a stale
sequence number) gets written.  To continue after the error, we need
to use the current sequence number.  But new_seqno() used the larger
one of the two, which is correct only as long as sequence numbers do
not overflow.  Overflow is rather unlikely, though.
2010-01-19 08:26:39 +01:00
0ba61f1714 Record news more compactly
Member nws_uid is unused since the commit before previous.  Remove it.

Member nws_seqno is of marginal value, because we write news only
through ncache[], and thus aren't prone to the errors sequence numbers
can catch.  Remove it.

Make timestamp selector virtual, computing nws_when + nws_duration,
and remove member nws_timestamp.  Impact:

* In ncache(), the removed timestamp equals nws_when + nws_duration,
  both for new news and updated news.  No change.

* delete_old_news() becomes invisible.  Before, its move of unexpired
  news to the beginning of the news file touched all the timestamps.
  That was unwanted, because the move does not change news, only their
  storage.  Improvement.

* empdump no longer flags the imported news changed via the timestamp.
  This is somewhat unfortunate.  Document as bug.

With these members removed, struct nwsstr no longer matches struct
emptypedstr, so clear news table flag EFF_TYPED and remove union
empobj_storage member news.  This loses the automatic maintenance of
member ef_type via struct emptypedstr.  Remove ef_type as well.

This shrinks struct nwsstr from 20 to 12 bytes on common 32 bit
machines, and from 32 to 16 bytes on common 64 bit machines.  Since
the server doesn't map the whole news file (EFF_MAP is off), this
reduces I/O, while the table's memory use remains the same.

Historical note: struct nwsstr is now pretty much what it was back in
BSD Empire 1.1.  Members ef_type and nws_uid go back to Empire 3 (for
C_SYNC?).  v4.3.12 added member nws_timestamp, which doubled the size
on common 64 bit machines.  v4.3.15 added nws_seqno.
2010-01-19 08:21:56 +01:00
b719f39c0f New news selector duration
Backed by new struct nwsstr member nws_duration.  Time between first
and last occurence of the news recorded in this item, in seconds.
2010-01-19 08:21:55 +01:00
39114987a9 Revert "Get rid of struct newscache"
This reverts commit 832574b6de.

To prepare for removal of struct nwsstr member nws_uid.

Conflicts:

	src/lib/subs/nreport.c
2010-01-19 08:21:55 +01:00
4e895465df Remove unused members of struct lndstr, lonstr, nukstr, trtstr
struct lndstr member lnd_flags is a leftover from Empire3's C_SYNC,
which was ripped out in 4.0.0.

struct lonstr member l_sel, struct nuk_str members nuk_ship, nuk_land,
and struct trtstr member trt_bond have been there basically forever
without any use.
2010-01-19 08:21:37 +01:00
d8c940ec2c Consistently use int for sector and unit uid parameters 2009-12-31 09:45:56 +01:00
c0ed527311 Consistently use int for file type parameters and locals 2009-12-29 17:23:22 +01:00
60519b3cd0 Consistently use int for mission type parameters 2009-12-29 13:06:35 +01:00
b23c52951f Fix launch not to wipe out target sector updates
Launching ABMs updates their base, in mission_pln_equip().  The update
got wiped out when launch_missile() wrote back the target sector,
triggering a seqno mismatch oops.  Harmless with the stock game's
ABMs, because they use neither shells nor petrol.

Fix by re-reading the target sector.
2009-12-26 14:02:50 +01:00
7dc130b7ac Fix launch not to wipe out target ship updates
Ships can expend shells to defend against missiles, in
shp_missile_defense().  Any shell use by the target ship got wiped out
when launch_missile() wrote back the target ship, triggering a seqno
mismatch oops.

Fix by re-reading the target ship.
2009-12-26 11:28:25 +01:00
de5c0b1c6b Bump version to 4.3.24 2009-12-26 10:20:21 +01:00