Fix classic off-by-one error - the answer is strlen() + 1, not just strlen()
Nicholas Clark [Fri, 22 Apr 2011 16:30:03 +0000 (17:30 +0100)]
This has been in the code since year dot, and no-one has spotted that the
returned sizes have been under-reporting.

CHANGES
Size.xs

diff --git a/CHANGES b/CHANGES
index 542e843..c9eae16 100644 (file)
--- 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 (file)
--- 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