Cache::Memcached - pos() weirdness

Brad Fitzpatrick brad@danga.com
Sat, 17 Jul 2004 18:18:49 -0700 (PDT)


This is still hanging around my inbox, but I feel dirty applying it
without knowing the real problem.  (which I suspect is Perl's fault)

Dave:  can you test this one-liner instead:

From:

my $p = pos($buf{$sock});

To:

my $p = pos($buf{$sock}) || length($&);

That way it shouldn't slow down or otherwise affect anything except on
broken taint systems.

It also probably warrants a comment, which I can commit if the above works
for you.

- Brad

On Thu, 20 May 2004, Dave Evans wrote:

> A few times I've come across some rather odd behaviour in the Perl binding,
> Cache::Memcached.  Typically the following warning is emitted:
>
>   Use of uninitialized value in subtraction (-) at Cache/Memcached.pm line 494.
>
> which is this line:
>
>   my $copy = $len-$p > $state{$sock} ? $state{$sock} : $len-$p;
>
> The cause seems to be that pos() has returned "undef" - this in spite of the
> fact that the last m//g match was successful (just a few lines further up).
> "perldoc -f pos" tells us that undef() is returned if and only if the match
> failed.  So, I'm at a loss to explain what's going on.  I'd love to hear an
> explanation, if anyone has one.
>
> What I /can/ be sure about is that when it does happen, it causes problems,
> because effectively the whole response "VALUE key n n ..." is interpreted as the
> value from the cache.  Ooops.
>
> Because I have no idea why pos() is playing up, I modifed the code not to rely
> on pos() any more, which makes this problem go away (for me).  Patch attached.
>
> Thanks,
>
> --
> Dave Evans
>
> PGP key: http://rudolf.org.uk/pgpkey
>
>