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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
1 + 34 = ?
Subscribe to this entry?

 
 [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.
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC