summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2014-05-19 06:52:24 -0400
committerSteffen Mueller <smueller@cpan.org>2014-05-28 15:20:52 +0200
commitc3caa5c3bdbd0ad0bc7ce5e7cd1a8eb5b7ca6a69 (patch)
tree6dc141509d7e032a24af49a9ad0ba9892c7b893c /sv.c
parent40b5a549d4793cde8b4d93ccdd03c16e039440c9 (diff)
downloadperl-c3caa5c3bdbd0ad0bc7ce5e7cd1a8eb5b7ca6a69.tar.gz
Use the C_ARRAY_LENGTH.
Use the C_ARRAY_LENGTH instead of sizeof(c_array)/sizeof(c_array[0]) or sizeof(c_array)/sizeof(type_of_element_in_c_array), and C_ARRAY_END for c_array + C_ARRAY_LENGTH(c_array). While doing this found potential off-by-one error in sv.c:Perl_sv_magic: how > C_ARRAY_LENGTH(PL_magic_data) should probably have been how >= C_ARRAY_LENGTH(PL_magic_data) No tests fail, but this seems to be more of an internal sanity check.
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/sv.c b/sv.c
index 1dbd3fed7f..060a4cc00c 100644
--- a/sv.c
+++ b/sv.c
@@ -5574,7 +5574,7 @@ Perl_sv_magic(pTHX_ SV *const sv, SV *const obj, const int how,
PERL_ARGS_ASSERT_SV_MAGIC;
- if (how < 0 || (unsigned)how > C_ARRAY_LENGTH(PL_magic_data)
+ if (how < 0 || (unsigned)how >= C_ARRAY_LENGTH(PL_magic_data)
|| ((flags = PL_magic_data[how]),
(vtable_index = flags & PERL_MAGIC_VTABLE_MASK)
> magic_vtable_max))
@@ -12248,8 +12248,7 @@ Perl_ptr_table_store(pTHX_ PTR_TBL_t *const tbl, const void *const oldsv, void *
new_arena->next = tbl->tbl_arena;
tbl->tbl_arena = new_arena;
tbl->tbl_arena_next = new_arena->array;
- tbl->tbl_arena_end = new_arena->array
- + sizeof(new_arena->array) / sizeof(new_arena->array[0]);
+ tbl->tbl_arena_end = C_ARRAY_END(new_arena->array);
}
tblent = tbl->tbl_arena_next++;