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: 2021-03-25 16:46 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bquinlan at google dot com Assigned: cmb (profile)
Status: Closed Package: memcache (PECL)
PHP Version: 5.4.21 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bquinlan at google dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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.
 [2021-03-25 16:46 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-03-25 16:46 UTC] cmb@php.net
The official bug tracker for PECL/memcache is now at
<https://github.com/websupport-sk/pecl-memcache/issues>.

So, if this is still an issue with either of the current memcache
versions (4 or 8), please file an issue there.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 19:01:35 2025 UTC