Commit graph

62 commits

Author SHA1 Message Date
143a4e4e6f nsc: Rename nstr_exec_val() to nstr_eval() and tighten contract
nstr_exec_val() can produce three different error values: NSC_NOTYPE
on invalid category, invalid type with zero val_as.lng on invalid type
(this is a bug), and the wanted type with zero val_s when it can't
coerce.  None of these should ever happen.

Fix it to always produce an NSC_NOTYPE error value.  Fix up callers to
check for it.

Specify the result's type is promoted on success.  Ensure it is even
when the argument is NSC_VAL with an unpromoted type, which is
invalid.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +01:00
bb467c335d Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01:00
22d39b9afa ef_verify: Cover sector coordinates in game state verification
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
df4925d696 Update copyright notice 2013-01-12 17:45:01 +01:00
1118f1c0ca Update copyright notice 2012-06-10 10:52:22 +02:00
6104d534e9 Plug memory leak in verify_row()
Leak introduced in commit b30c83cd, v4.3.28.
2011-12-29 11:47:04 +01:00
d63b0e1a7b Split ef_verify() into ef_verify_config(), ef_verify_state() 2011-07-10 21:17:01 +02:00
c4a32b2fda Factor verify_table() out of ef_verify() 2011-07-10 21:16:41 +02:00
bea98f32c4 Fix return value of ef_verify() to match function comment
Comment added in commit 6eec0010.  Callers don't actually care.
2011-07-10 21:11:04 +02:00
3403cb2ecb Factor product code out of ef_verify() into verify_products() 2011-06-25 17:12:39 +02:00
ca4312061e Fold pln_zap_transient_flags() into verify_planes() 2011-06-25 17:12:37 +02:00
6f6d76fcc9 Verify carrier references are sane
Catch bad references here, before unit_cargo_init() chokes on them.
2011-06-25 17:10:29 +02:00
b991ddf8de Drop pln_zap_transient_flags()'s work-around for unusable putplane()
I believe putplane() became usable here in commit 3cf29456, v4.3.17.
The work-around was pretty wasteful (not that it mattered).
2011-06-25 17:06:48 +02:00
6eec001050 Fix empdump not to touch plane file when import fails
pln_zap_transient_flags() fixes up planes stuck in the air (commit
7ca4f412, v4.3.12).  Since commit 4e9e58bf (v4.3.14), it writes back
the fixed planes.  This is wrong for empdump.

empdump should touch data only on successful import.  When it fails
because ef_verify() fails, and any planes are found stuck in the air,
the plane file gets rewritten.

Make parameter ef_verify() take parameter may_put to let empdump
suppress the plane write-back.  The plane file still get written out
on successful import, along with the other imported game state.
2011-06-25 17:05:12 +02:00
7da9aab5a1 Verify game state and configuration reference sanity
Table elements reference other table elements.  Bad things happen when
references dangle.  ef_verify() already checks whether the referenced
table elements exist.  This commit makes it check whether the elements
are "in use".  This catches stuff like living planes on dead carriers.
2011-06-25 16:54:29 +02:00
b30c83cd64 Verify table uid sanity more tightly
verify_row() refrains from rejecting zero uids, because some tables
may contain blank entries, with zero uid.

Change it to check only header sanity for entries that are not in use.
This filters out all legitimately blank entries.  Tighten up the uid
check.

For computing "in use", factor empobj_in_use() out of xdvisible().
Note that xdvisible()'s case EF_COUNTRY doesn't bother to check
nat_stat, because that's implied by what it does check.  It's not
implied in empobj_in_use(), so add it there.
2011-06-25 16:54:29 +02:00
fbf5b78129 Factor verify_tabref() out of verify_row() 2011-06-25 16:54:29 +02:00
84d88442b3 Don't misinterpret blank configuration entries as sentinels
Configuration table entries not defined by builtin and custom
configuration files remain blank.  They get misinterpreted as sentinel
in tables that use one.  Affected are tables product, ship-chr,
plane-chr, land-chr and nuke-chr.  Tables item, sect-chr and
infrastructure are immune despite using a sentinel, because omitting
entries is not permitted there.

Code relying on the sentinel fails to pick up entries after the first
blank one.  They don't get set up correctly, they're invisible to
build and show, and not recognized as symbolic selector values (the
frg in ship ?type=frg).  xdump is fine, because it doesn't rely on
sentinels.  It dumps blank entries normally.

The bugs don't bite in the stock game, because the builtin
configuration files are all dense.

The sentinels are all null strings.  Set them to "" in the affected
tables' oninit callback.  Fix up code iterating over the tables to
ignore such entries.  This is precisely the code relying on sentinels,
plus xdump's xdvisible().
2011-06-25 16:51:56 +02:00
44f97c3297 Clean up how a view's base table is defined
New struct empfile member base replaces ef_open_view() parameter base.
Cleaner, because the base table is a property of the view, not of how
it's used.

Use it to clean up verify_fail()'s base table access, and for extra
sanity checks in ef_open() and ef_open_view().
2011-06-25 16:50:06 +02:00
97f475b6c1 Oops in verify_row() when non-integral selector references a table 2011-06-06 19:24:13 +02:00
e1caa11733 Don't ignore non-virtual NSC_EXTRA columns in ef_verify.c
These are commonly timestamps (no verification implemented), or
aliases for a non-extra column (which gets verified).  Commit 49780e2c
(v4.3.12) added the exception: EF_SECTOR's uid.  Proof by example that
ignoring these columns is wrong.  Fix: ignore only virtual columns.
2011-06-06 19:24:13 +02:00
98cd2a3a70 Update known contributors comments 2011-04-14 20:21:23 +02:00
7e2008e7f4 License upgrade to GPL version 3 or later
Why upgrade?  I'm not a lawyer, but here's my take on the differences
to version 2:

* Software patents: better protection against abuse of patents to
  prevent users from exercising the rights under the GPL.  I doubt
  we'll get hit with a patent suit, but it's a good move just on
  general principles.

* License compatibility: compatible with more free licenses, i.e. can
  "steal" more free software for use in Empire.  I don't expect to steal
  much, but it's nice to have the option.

* Definition of "source code": modernization of some details for today's
  networked world, to make it easier to distribute the software.  Not
  really relevant to us now, as we normally distribute full source code.

* Tivoization: this is about putting GPL-licensed software in hardware,
  then make the hardware refuse to run modified software.  "Neat" trick
  to effectively deny its users their rights under the GPL.  Abuse was
  "pioneered" by TiVo (popular digital video recorders).  GPLv3 forbids
  it.  Unlikely to become a problem for us.

* Internationalization: more careful wording, to harden the license
  outside the US.  The lawyers tell us it better be done that way.

* License violations: friendlier way to deal with license violations.
  This has come out of past experience enforcing the GPL.

* Additional permissions: Probably not relevant to us.

Also include myself in the list of principal authors.
2011-04-12 21:20:58 +02:00
243a15052f Convert spaces to tabs 2010-06-20 18:36:44 +02:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
c528fcbe3e Update known contributors comments 2009-12-13 17:34:28 +01:00
696dea759c Clean up non-ANSI definition of ef_verify()
Harmless, because declaration is fine.
2009-03-22 18:02:57 +01:00
35ef345ecb Update copyright notice 2009-02-08 09:33:18 +01:00
d702068457 Fix trailing whitespace 2008-09-17 21:31:40 -04:00
7a06a58bec Don't fix up dead planes stuck in the air
Missile interdiction leaves behind used up missiles with the
PLN_LAUNCHED flag set.  This can lead to a bogus warning from
pln_zap_transient_flags() on server restart.

Change pln_zap_transient_flags() to ignore dead planes.
2008-07-12 10:43:03 -04:00
238b9afc3b Catch selectors that make xundump oops early
Oops in new verify_ca(), which runs during initialization.
2008-05-12 12:39:38 +02:00
4e9e58bf6a Write planes fixed on game start to disk properly
When fixing planes stuck in the air, we fixed them only in memory, so
when a fixed plane wasn't written to disk for other reasons before the
next game start, it had to be fixed again.

Change pln_zap_transient_flags() to write them out.
2008-04-29 20:38:10 +02:00
7ca4f412b1 Fix tracking of planes flying a sortie
Planes normally sit in their base (sector or carrier), where they can
be spied, damaged, captured, loaded, unloaded, upgraded and so forth.
All this must not be possible while they fly.  There are two kinds of
flying planes: satellites in orbit, and planes flying a sortie.

Satellites in orbit have always been marked with flag PLN_LAUNCHED.
Works.  What didn't work was tracking planes flying a sortie.

If you look at one sortie in isolation, up to three groups of planes
can be flying at any point of time: the primary group, which carries
out the sortie's mission (bomb, transport, ...), their escorts, and a
group of hostile planes flying interception or air defense.

The old code attempted to track these planes by passing those groups
to the places that need to know whether a plane is flying.  This was
complex and incomplete, and broke down completely for the pin-bombing
command.

It was complex, because the plane code needs to keep track of all the
call chains that can lead to a place that needs to know whether a
plane flies, and pass the groups down the call chains.  This leads to
a rather ugly passing of plane groups all over the place.

It was incomplete, because it generally failed to pass the escorts.

And the whole scheme broke down for the pin-bombing command.  That's
because pin-bombing asks the player for targets while his planes are
loitering above the target sector.  This yields the processor and lets
other code run.  Which does not get the flying planes passed.

The new code marks planes and SAMs (but not other missiles) flying a
sortie with flag PLN_LAUNCHED (the previous commit laid the groundwork
for that), and does away with passing around groups of flying planes.

This fixes the following bugs:

* Many commands could interact with foreign planes flying for a
  pin-bombing command as if they were sitting in their base.  This
  includes spying, damaging, capturing, loading, or upgrading them,
  and even getting intercepted by them.  Any changes to those planes
  were wiped out when they landed.  Abusable.

* The bomb command could bomb its own escorts, directly (pin-bomb
  planes) or through collateral damage, strategic sector damage,
  collapsing bridges or nuke damage.  The damage to the escorts was
  wiped out when they landed.

* If you asked for a plane to fly both in the primary group and the
  escort group, you got charged fuel for two sorties instead of one.

* pln_put1() and pln_put() now recognize planes that didn't take off,
  and refrain from making them land.  Intercept (since commit
  c64e2149) and air defense can do that.  Making them land had no
  ill-effects, but it was still wrong.

There's one new problem: if PLN_LAUNCHED doesn't get reset properly,
due to game crash during flight or some other bug, the plane gets
stuck in the air.  Catch and fix that on game start in ef_verify().
2008-03-26 22:10:13 +01:00
0dd6702df1 Update known contributors comments 2008-03-14 20:25:44 +01:00
d1a193ff07 New nstr_mksymval() to create symbolic values 2008-03-14 20:25:41 +01:00
da8a1daeef Virtual selectors
Where ordinary selectors specify a value stored in some object,
virtual selectors specify a function to call to compute a value
associated with some object.

Use them to replace the special case xdump ver by new table
EF_VERSION.

Move configkeys[] to lib/common because nsc_init() needs it to
initialize empfile[EF_VERSION].cadef.
2008-03-14 20:25:41 +01:00
9b8683736b Make ef_verify() check ef_type and uid 2008-03-14 20:25:09 +01:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
454c6df5ef (verify_fail): Print index as it looks in input. 2007-08-24 17:23:26 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
e42053d928 Break inclusion cycle: prototypes.h and commands.h included each
other.  Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special).  New header types.h to
help avoid inclusion cycles.  Sort include directives.  Remove some
superflous includes.
2006-07-10 06:37:23 +00:00
5e66e5bdee (ef_verify): Check pchr[].p_level matches pchr[].p_type. 2006-06-08 20:22:58 +00:00
c432e3107d Symbolic names for table entries in conditionals, closes #928376:
(ef_elt_byname): New.
(nstr_match_val): Use it to generalize to arbitrary table with
uniquely named elements.  Use ca_type to find table, remove parameter
type.  Callers changed.
(nstr_mkselval): Adapt sanity check accordingly.
(NSC_TYPEID): No longer needed, remove, users changed to use
appropriate integer type instead.  This fixes signedness of sector
selectors des and newdes.
(meta_type): Remove entry for NSC_TYPEID.
(nstr_coerce_val): Can't detect typeid - integer mismatch anymore.
Was nice to have; perhaps revive it later.
2006-06-01 18:48:42 +00:00
cc1df4e88a (verify_fail): New parameter idx. Use it to print array index when
applicable.  Callers changed.
2006-05-24 18:32:13 +00:00
f576dd6694 (verify_row): uid check was too strict. 2006-04-05 18:47:02 +00:00
9559abb506 (verify_fail): New.
(verify_row): Use it.
2006-02-19 17:08:35 +00:00
8b97f10ea3 (verify_row): Passed uninitialized val->val_as.sym.len to nstr_exec_val(),
which broke NSC_STRINGY.
2006-02-14 19:54:08 +00:00
973da267eb (verify_row): Check all values against symbol tables, not just
non-negative ones.

(verify_row): Fix off by one in non-symbol table index check.
2006-02-06 07:57:04 +00:00
8ae71216d4 (verify_row): Check table references regardless of target table. Also
fixes the previous revision.
2006-02-06 07:53:42 +00:00
e71509b32f (verify_row): Check uid. 2006-02-05 19:59:08 +00:00