php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57243 Increment/Decrement Trailing Whitespace
Submitted: 2006-09-15 11:21 UTC Modified: 2006-09-18 06:40 UTC
From: chris dot s at idleserv dot net Assigned:
Status: Not a bug Package: memcache (PECL)
PHP Version: 5.1.6 OS: Redhat Ent 4
Private report: No CVE-ID: None
 [2006-09-15 11:21 UTC] chris dot s at idleserv dot net
Description:
------------
Package version 2.0.4.

If the value goes over 10, then back below 10, there is trailing whitespace.

Reproduce code:
---------------
$memcache->set('testkey', 99);
$memcache->increment('testkey');

$key = $memcache->get('testkey');
echo $key . "#\n";

$memcache->decrement('testkey');

$key = $memcache->get('testkey');
echo $key . '#';

Expected result:
----------------
10#
9#

Actual result:
--------------
10#
9 #

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-18 06:40 UTC] mikael at synd dot info
This is a feature of memcached as the telnet trace below shows and the protocol spec (http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt) reads 

"Note also that decrementing a number such that it loses length isn't guaranteed to decrement its returned length.  The number MAY be space-padded at the end, but this is purely an implementation optimization, so you also shouldn't rely on that."

Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
version
VERSION 1.1.12
set testkey 0 0 2
99
STORED
get testkey
VALUE testkey 0 2
99
END
incr testkey 1
100
get testkey
VALUE testkey 0 3
100
END
decr testkey 1
99
get testkey
VALUE testkey 0 3
99 
END

The evidence is the last "get testkey" that show the value length as 3 with an accompanying padding space at the end. I suggest you use "$value = (int)$memcache->get('testkey');" to remove the whitespace.

//Mikael
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 05:01:27 2024 UTC