fix off-by-one when restoring hashes [perl #73972]
authorJesse Luehrs <doy@tozt.net>
Tue, 26 Jun 2012 21:47:51 +0000 (16:47 -0500)
committerJesse Luehrs <doy@tozt.net>
Tue, 26 Jun 2012 22:12:23 +0000 (17:12 -0500)
commit11b24ae76382137a580b9b75114adee14ec7afd2
tree72e8213d5dd688cd3c9b9ff8cf767e16a51a222a
parent885b4b39ea6a6ada4a5e7ecc4a47d4c4abdb64ab
fix off-by-one when restoring hashes [perl #73972]

Storable tries to preallocate enough space for all of the elements it's
going to receive, both for efficiency reasons and because reallocation
triggers throwing away all of the placeholders in the hash (which are
used for restricted hashes) if the hash isn't already READONLY, and
since Storable rebuilds restricted hashes by first populating all of the
placeholders and then setting it READONLY at the end, this would break
things.

Unfortunately, it was allocating just slightly less than enough space -
hashes reallocate when they hit their limit, not when they exceed it,
and so if you tried to store a restricted hash with a number of keys
right on the boundary, it would trigger a reallocation and lose all of
the allowed keys that it had just stored. This fixes the issue by
allocating the correct amount of space to ensure that reallocation
doesn't happen.
dist/Storable/Storable.pm
dist/Storable/Storable.xs
dist/Storable/t/restrict.t