php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66006 memcache->increment behavior undefined if value > MAX_INT
Submitted: 2013-10-30 19:28 UTC Modified: 2013-10-30 19:39 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bquinlan at google dot com Assigned:
Status: Open Package: memcache (PECL)
PHP Version: 5.4.21 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-10-30 19:28 UTC] bquinlan at google dot com
Description:
------------
php > $memcache = new Memcached;
php > $memcache->addServer('localhost', 11211) or die ("Could not connect");
php > var_dump($memcache->set('key', 9223372036854775807));
bool(true)
php > var_dump($memcache->increment('key'));
int(-9223372036854775808)

The negative return value is a consequence of memcache->increment's use of atol to parse the results i.e.

  ...
  *number = (long) atol(mmc->inbuf);
  return 1;
}

memcache->increment should return the same thing as memcache->get for the key after increment.

Though I'm not sure if the clipping behavior of memcache->get is correct either:

php > var_dump($memcache->get('key'));
int(9223372036854775807)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-30 19:39 UTC] pajoye@php.net
It is hard to do anything relevant for integers > MAX_INT. Casting them to double won't work well either, while it will at least keep the value (not the integer tho').
 [2013-10-31 17:41 UTC] petermck at google dot com
Wouldn't it be better if the increment() call in the example code returned int(9223372036854775807) ?  At least that'd be consistent with doing a subsequent get() call on the same key.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Oct 20 04:01:27 2019 UTC