Skip to content

Commit

Permalink
threads::shared "$#shared = N" off-by-one error
Browse files Browse the repository at this point in the history
RT #122950

    my @A : shared;
    $#a = 3;  # actually set it to 4

There was a simple off-by-one error in the XS code that handled the
STORESIZE tie method (confusing the array size and fill, which differ
by 1).

Amazingly, there was no test for it, and no-one had noticed up until now.

Note that this commit causes three tests in object2.t to fail: this
is because fixing the $#shared bug exposed another bug that was being
masked by this one. They will be fixed in the next commit
  • Loading branch information
iabyn committed Oct 14, 2014
1 parent 0561e60 commit 399547d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dist/threads-shared/lib/threads/shared.pm
Expand Up @@ -7,7 +7,7 @@ use warnings;

use Scalar::Util qw(reftype refaddr blessed);

our $VERSION = '1.46'; # Please update the pod, too.
our $VERSION = '1.47'; # Please update the pod, too.
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;

Expand Down Expand Up @@ -195,7 +195,7 @@ threads::shared - Perl extension for sharing data structures between threads
=head1 VERSION
This document describes threads::shared version 1.46
This document describes threads::shared version 1.47
=head1 SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion dist/threads-shared/shared.xs
Expand Up @@ -1373,7 +1373,7 @@ STORESIZE(SV *obj,IV count)
dTHXc;
SV *sobj = SHAREDSV_FROM_OBJ(obj);
SHARED_EDIT;
av_fill((AV*) sobj, count);
av_fill((AV*) sobj, count - 1);
SHARED_RELEASE;


Expand Down
12 changes: 11 additions & 1 deletion dist/threads-shared/t/av_simple.t
Expand Up @@ -27,7 +27,7 @@ sub ok {

BEGIN {
$| = 1;
print("1..44\n"); ### Number of tests that will be run ###
print("1..47\n"); ### Number of tests that will be run ###
};

use threads;
Expand Down Expand Up @@ -130,6 +130,16 @@ ok(37, !defined delete($foo[0]), "Check that delete works from a thread");

ok(44, is_shared(@foo), "Check for sharing");

# RT #122950

@foo = ('a'..'z');
$#foo = 2;

ok(45, $#foo == 2, "\$#foo assignment: \$#");
ok(46, @foo == 3, "\$#foo assignment: scalar");
ok(47, "@foo" eq "a b c", "\$#foo assignment: array interpolation");


exit(0);

# EOF

0 comments on commit 399547d

Please sign in to comment.