@@ -2185,7 +2185,7 @@ static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by
21852185static void php_memc_incdec_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key , zend_bool incr )
21862186{
21872187 zend_string * key , * server_key = NULL ;
2188- long offset = 1 ;
2188+ zend_long offset = 1 ;
21892189 uint64_t value = UINT64_MAX , initial = 0 ;
21902190 time_t expiry = 0 ;
21912191 memcached_return status ;
@@ -2208,22 +2208,27 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key,
22082208 MEMC_CHECK_KEY (intern , key );
22092209
22102210 if (offset < 0 ) {
2211- php_error_docref (NULL , E_WARNING , "offset has to be > 0 " );
2211+ php_error_docref (NULL , E_WARNING , "offset cannot be a negative value " );
22122212 RETURN_FALSE ;
22132213 }
22142214
22152215 if ((!by_key && n_args < 3 ) || (by_key && n_args < 4 )) {
22162216 if (by_key ) {
22172217 if (incr ) {
2218- status = memcached_increment_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , & value );
2218+ status = memcached_increment_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), offset , & value );
22192219 } else {
2220- status = memcached_decrement_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , & value );
2220+ status = memcached_decrement_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), offset , & value );
22212221 }
22222222 } else {
2223+ /* The libmemcached API has a quirk that memcached_increment() takes only a 32-bit
2224+ * offset, but memcached_increment_by_key() and all other increment and decrement
2225+ * functions take a 64-bit offset. The memcached protocol allows increment/decrement
2226+ * greater than UINT_MAX, so we just work around memcached_increment() here.
2227+ */
22232228 if (incr ) {
2224- status = memcached_increment (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , & value );
2229+ status = memcached_increment_by_key (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), ZSTR_VAL ( key ), ZSTR_LEN ( key ), offset , & value );
22252230 } else {
2226- status = memcached_decrement (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , & value );
2231+ status = memcached_decrement_by_key (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), ZSTR_VAL ( key ), ZSTR_LEN ( key ), offset , & value );
22272232 }
22282233 }
22292234
@@ -2237,15 +2242,15 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key,
22372242 }
22382243 if (by_key ) {
22392244 if (incr ) {
2240- status = memcached_increment_with_initial_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , initial , expiry , & value );
2245+ status = memcached_increment_with_initial_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), offset , initial , expiry , & value );
22412246 } else {
2242- status = memcached_decrement_with_initial_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , initial , expiry , & value );
2247+ status = memcached_decrement_with_initial_by_key (intern -> memc , ZSTR_VAL (server_key ), ZSTR_LEN (server_key ), ZSTR_VAL (key ), ZSTR_LEN (key ), offset , initial , expiry , & value );
22432248 }
22442249 } else {
22452250 if (incr ) {
2246- status = memcached_increment_with_initial (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , initial , expiry , & value );
2251+ status = memcached_increment_with_initial (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), offset , initial , expiry , & value );
22472252 } else {
2248- status = memcached_decrement_with_initial (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), ( unsigned int ) offset , initial , expiry , & value );
2253+ status = memcached_decrement_with_initial (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ), offset , initial , expiry , & value );
22492254 }
22502255 }
22512256 if (s_should_retry_write (intern , status ) && retries -- > 0 ) {
0 commit comments