xditem() needs a buffer that can hold entries of any xdumpable table.
It's been 2048 bytes and marked FIXME since day one. Clean it up so
that if anyone ever goes crazy with entry sizes, we fail an assertion
during startup instead of overrunning the buffer during play.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
* file.h: Describes Empire tables (`files' for historical reasons)
*
* Known contributors to this file:
- * Markus Armbruster, 2005-2012
+ * Markus Armbruster, 2005-2014
*/
#ifndef FILE_H
/* Create table file, clobbering any existing file */
#define EFF_CREATE bit(16)
+/*
+ * A value larger than any struct empfile member size where member
+ * cadef is not null.
+ */
+#define EF_WITH_CADEF_MAX_ENTRY_SIZE 1024
+
/*
* Empire `file types'
* These are really table IDs. Some tables are backed by files, some
* xdump.c: Extended dump
*
* Known contributors to this file:
- * Markus Armbruster, 2004-2011
+ * Markus Armbruster, 2004-2014
*/
#include <config.h>
struct castr *ca;
struct nstr_item ni;
int n;
- char buf[2048]; /* FIXME buffer size? */
+ unsigned char buf[EF_WITH_CADEF_MAX_ENTRY_SIZE];
ca = ef_cadef(type);
if (!ca)
* filetable.c: Empire game data file descriptions.
*
* Known contributors to this file:
- * Markus Armbruster, 2005-2013
+ * Markus Armbruster, 2005-2014
*/
#include <config.h>
+#include <assert.h>
#include <stddef.h>
#include "commodity.h"
#include "file.h"
void
empfile_fixup(void)
{
+ struct empfile *ep;
+
empfile[EF_SECTOR].nent = WORLD_SZ();
empfile[EF_MAP].size = empfile[EF_BMAP].size = WORLD_SZ();
+
+ for (ep = empfile; ep->uid >= 0; ep++)
+ assert(!ep->cadef || ep->size <= EF_WITH_CADEF_MAX_ENTRY_SIZE);
}