Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f14a80d

Browse files
committed
Refactor redis_long_response
1 parent b193a6d commit f14a80d

1 file changed

Lines changed: 13 additions & 21 deletions

File tree

library.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,40 +1624,30 @@ PHP_REDIS_API int redis_long_response(INTERNAL_FUNCTION_PARAMETERS,
16241624
char *response;
16251625
int response_len;
16261626

1627-
if ((response = redis_sock_read(redis_sock, &response_len)) == NULL) {
1627+
if ((response = redis_sock_read(redis_sock, &response_len)) == NULL || *response != TYPE_INT) {
16281628
if (IS_ATOMIC(redis_sock)) {
16291629
RETVAL_FALSE;
16301630
} else {
16311631
add_next_index_bool(z_tab, 0);
16321632
}
1633-
1633+
if (response) efree(response);
16341634
return FAILURE;
16351635
}
16361636

1637-
if(response[0] == ':') {
1638-
int64_t ret = phpredis_atoi64(response + 1);
1637+
int64_t ret = phpredis_atoi64(response + 1);
16391638

1640-
if (IS_ATOMIC(redis_sock)) {
1641-
if(ret > LONG_MAX) { /* overflow */
1642-
RETVAL_STRINGL(response + 1, response_len - 1);
1643-
} else {
1644-
RETVAL_LONG((long)ret);
1645-
}
1639+
if (IS_ATOMIC(redis_sock)) {
1640+
if (ret > LONG_MAX) { /* overflow */
1641+
RETVAL_STRINGL(response + 1, response_len - 1);
16461642
} else {
1647-
if(ret > LONG_MAX) { /* overflow */
1648-
add_next_index_stringl(z_tab, response + 1, response_len - 1);
1649-
} else {
1650-
add_next_index_long(z_tab, (long)ret);
1651-
}
1643+
RETVAL_LONG((long)ret);
16521644
}
16531645
} else {
1654-
if (IS_ATOMIC(redis_sock)) {
1655-
RETVAL_FALSE;
1646+
if (ret > LONG_MAX) { /* overflow */
1647+
add_next_index_stringl(z_tab, response + 1, response_len - 1);
16561648
} else {
1657-
add_next_index_null(z_tab);
1649+
add_next_index_long(z_tab, (long)ret);
16581650
}
1659-
efree(response);
1660-
return FAILURE;
16611651
}
16621652

16631653
efree(response);
@@ -3376,8 +3366,10 @@ redis_mbulk_reply_zipped_raw_variant(RedisSock *redis_sock, zval *zret, int coun
33763366
return FAILURE;
33773367

33783368
/* This can vary */
3379-
if (redis_read_reply_type(redis_sock, &type, &vallen) < 0)
3369+
if (redis_read_reply_type(redis_sock, &type, &vallen) < 0) {
3370+
efree(key);
33803371
return FAILURE;
3372+
}
33813373

33823374
if (type == TYPE_BULK) {
33833375
if (vallen > INT_MAX || (val = redis_sock_read_bulk_reply(redis_sock, (int)vallen)) == NULL) {

0 commit comments

Comments
 (0)