summaryrefslogtreecommitdiff
path: root/handy.h
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 /handy.h
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 'handy.h')
-rw-r--r--handy.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/handy.h b/handy.h
index 3f84eff9af..9332f8de97 100644
--- a/handy.h
+++ b/handy.h
@@ -1936,8 +1936,13 @@ void Perl_mem_log_del_sv(const SV *sv, const char *filename, const int linenumbe
#define StructCopy(s,d,t) Copy(s,d,1,t)
#endif
+/* C_ARRAY_LENGTH is the number of elements in the C array (so you
+ * want your zero-based indices to be less than but not equal to).
+ *
+ * C_ARRAY_END is one past the last: half-open/half-closed range,
+ * not last-inclusive range. */
#define C_ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0]))
-#define C_ARRAY_END(a) (a) + (sizeof(a)/sizeof((a)[0]))
+#define C_ARRAY_END(a) ((a) + C_ARRAY_LENGTH(a))
#ifdef NEED_VA_COPY
# ifdef va_copy