@@ -2185,7 +2185,7 @@ static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by
2185
2185
static void php_memc_incdec_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key , zend_bool incr )
2186
2186
{
2187
2187
zend_string * key , * server_key = NULL ;
2188
- long offset = 1 ;
2188
+ zend_long offset = 1 ;
2189
2189
uint64_t value = UINT64_MAX , initial = 0 ;
2190
2190
time_t expiry = 0 ;
2191
2191
memcached_return status ;
@@ -2208,22 +2208,27 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key,
2208
2208
MEMC_CHECK_KEY (intern , key );
2209
2209
2210
2210
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 " );
2212
2212
RETURN_FALSE ;
2213
2213
}
2214
2214
2215
2215
if ((!by_key && n_args < 3 ) || (by_key && n_args < 4 )) {
2216
2216
if (by_key ) {
2217
2217
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 );
2219
2219
} 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 );
2221
2221
}
2222
2222
} 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
+ */
2223
2228
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 );
2225
2230
} 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 );
2227
2232
}
2228
2233
}
2229
2234
@@ -2237,15 +2242,15 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key,
2237
2242
}
2238
2243
if (by_key ) {
2239
2244
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 );
2241
2246
} 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 );
2243
2248
}
2244
2249
} else {
2245
2250
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 );
2247
2252
} 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 );
2249
2254
}
2250
2255
}
2251
2256
if (s_should_retry_write (intern , status ) && retries -- > 0 ) {
0 commit comments