From: Nicholas Clark Date: Fri, 22 Apr 2011 16:30:03 +0000 (+0100) Subject: Fix classic off-by-one error - the answer is strlen() + 1, not just strlen() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6ec51ae0066a3ae0165701ef644f20b01af516f3;p=p5sagit%2FDevel-Size.git Fix classic off-by-one error - the answer is strlen() + 1, not just strlen() This has been in the code since year dot, and no-one has spotted that the returned sizes have been under-reporting. --- diff --git a/CHANGES b/CHANGES index 542e843..c9eae16 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,10 @@ Revision history for Perl extension Devel::Size. -0.74_51 2011-04-20 nicholas +0.74_51 2011-04-22 nicholas * Don't count PL_sv_{undef,no,yes} in the size returned * total_size() was double-counting entries in typeglobs * sv_size() was double-counting the PVGV size if GvEGV() looped back + * fix classic off-by-one error - the answer is strlen() + 1, not just strlen() 0.74_50 2011-04-19 nicholas * Ensure that size() doesn't add the referent's size for non SVt_RV references diff --git a/Size.xs b/Size.xs index 1c8a0f3..654ff39 100644 --- a/Size.xs +++ b/Size.xs @@ -333,7 +333,7 @@ magic_size(const SV * const thing, struct state *st) { static void check_new_and_strlen(struct state *st, const char *const p) { if(check_new(st, p)) - st->total_size += strlen(p); + st->total_size += 1 + strlen(p); } static void