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:2
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
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
22 + 18 = ?
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.
 [2020-12-02 11:05 UTC] infostanfordonlineclasses at gmail dot com
On the off chance that you ordered to some unacceptable objective? No certifications. Improving compilers are permitted to take easy routes that depend on knowing subtleties of the objective stage. Executing a program gathered like that on an inconsistent stage can bring about unclear conduct. https://stanfordonlineclasses.com/
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Feb 28 22:01:23 2021 UTC