mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
The mps_args_add_field and mps_args_done now check that the number of arguments is in bounds.
Copied from Perforce Change: 185938 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
a7e224e663
commit
e50f28afeb
4 changed files with 28 additions and 11 deletions
|
|
@ -112,7 +112,6 @@ static void test_main(void *marker, int interior, int stack)
|
|||
MPS_ARGS_ADD(args, MPS_KEY_CHAIN, obj_chain);
|
||||
MPS_ARGS_ADD(args, MPS_KEY_FORMAT, obj_fmt);
|
||||
MPS_ARGS_ADD(args, MPS_KEY_INTERIOR, interior);
|
||||
MPS_ARGS_DONE(args);
|
||||
die(mps_pool_create_k(&obj_pool, scheme_arena, mps_class_amc(), args),
|
||||
"mps_pool_create_k");
|
||||
} MPS_ARGS_END(args);
|
||||
|
|
|
|||
|
|
@ -452,7 +452,6 @@ void scheme_fmt(mps_fmt_t *fmt)
|
|||
MPS_ARGS_ADD(args, MPS_KEY_FMT_FWD, obj_fwd);
|
||||
MPS_ARGS_ADD(args, MPS_KEY_FMT_ISFWD, obj_isfwd);
|
||||
MPS_ARGS_ADD(args, MPS_KEY_FMT_PAD, obj_pad);
|
||||
MPS_ARGS_DONE(args);
|
||||
res = mps_fmt_create_k(fmt, scheme_arena, args);
|
||||
} MPS_ARGS_END(args);
|
||||
if (res != MPS_RES_OK) error("Couldn't create obj format");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* mps.h: RAVENBROOK MEMORY POOL SYSTEM C INTERFACE
|
||||
*
|
||||
* $Id$
|
||||
* Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license.
|
||||
* Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license.
|
||||
* Portions copyright (c) 2002 Global Graphics Software.
|
||||
*
|
||||
* THIS HEADER IS NOT DOCUMENTATION.
|
||||
|
|
@ -227,20 +227,22 @@ extern const struct mps_key_s _mps_key_fmt_class;
|
|||
/* Maximum length of a keyword argument list. */
|
||||
#define MPS_ARGS_MAX 32
|
||||
|
||||
extern void _mps_args_set_key(mps_arg_s args[MPS_ARGS_MAX], unsigned i,
|
||||
mps_key_t key);
|
||||
|
||||
#define MPS_ARGS_BEGIN(_var) \
|
||||
MPS_BEGIN \
|
||||
mps_arg_s _var[MPS_ARGS_MAX]; \
|
||||
unsigned _var##_i = 0; \
|
||||
_var[_var##_i].key = MPS_KEY_ARGS_END; \
|
||||
_mps_args_set_key(_var, _var##_i, MPS_KEY_ARGS_END); \
|
||||
MPS_BEGIN
|
||||
|
||||
#define MPS_ARGS_ADD_FIELD(_var, _key, _field, _val) \
|
||||
MPS_BEGIN \
|
||||
/* TODO: AVER(_var##_i + 1 < MPS_ARGS_MAX); */ \
|
||||
_var[_var##_i].key = (_key); \
|
||||
_mps_args_set_key(_var, _var##_i, _key); \
|
||||
_var[_var##_i].val._field = (_val); \
|
||||
++_var##_i; \
|
||||
_var[_var##_i].key = MPS_KEY_ARGS_END; \
|
||||
_mps_args_set_key(_var, _var##_i, MPS_KEY_ARGS_END); \
|
||||
MPS_END
|
||||
|
||||
#define MPS_ARGS_ADD(_var, _key, _val) \
|
||||
|
|
@ -248,9 +250,8 @@ extern const struct mps_key_s _mps_key_fmt_class;
|
|||
|
||||
#define MPS_ARGS_DONE(_var) \
|
||||
MPS_BEGIN \
|
||||
/* TODO: AVER(_var##_i < MPS_ARGS_MAX); */ \
|
||||
_var[_var##_i].key = MPS_KEY_ARGS_END; \
|
||||
/* TODO: _var##_i = MPS_ARGS_MAX; */ \
|
||||
_mps_args_set_key(_var, _var##_i, MPS_KEY_ARGS_END); \
|
||||
_var##_i = MPS_ARGS_MAX; \
|
||||
MPS_END
|
||||
|
||||
#define MPS_ARGS_END(_var) \
|
||||
|
|
@ -812,7 +813,7 @@ extern mps_res_t _mps_fix2(mps_ss_t, mps_addr_t *);
|
|||
|
||||
/* C. COPYRIGHT AND LICENSE
|
||||
*
|
||||
* Copyright (C) 2001-2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
|
||||
* Copyright (C) 2001-2014 Ravenbrook Limited <http://www.ravenbrook.com/>.
|
||||
* All rights reserved. This is an open source license. Contact
|
||||
* Ravenbrook for commercial licensing options.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1929,6 +1929,24 @@ void mps_chain_destroy(mps_chain_t chain)
|
|||
}
|
||||
|
||||
|
||||
/* _mps_args_set_key -- set the key for a keyword argument
|
||||
*
|
||||
* This sets the key for the i'th keyword argument in the array args,
|
||||
* with bounds checking on i. It is used by the MPS_ARGS_BEGIN,
|
||||
* MPS_ARGS_ADD, and MPS_ARGS_DONE macros in mps.h.
|
||||
*
|
||||
* We implement this in a function here, rather than in a macro in
|
||||
* mps.h, so that we can use AVER to do the bounds checking.
|
||||
*/
|
||||
|
||||
void _mps_args_set_key(mps_arg_s args[MPS_ARGS_MAX], unsigned i,
|
||||
mps_key_t key)
|
||||
{
|
||||
AVER(i < MPS_ARGS_MAX);
|
||||
args[i].key = key;
|
||||
}
|
||||
|
||||
|
||||
/* C. COPYRIGHT AND LICENSE
|
||||
*
|
||||
* Copyright (C) 2001-2014 Ravenbrook Limited <http://www.ravenbrook.com/>.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue