Skip to content

Commit 73049f4

Browse files
authored
Merge pull request phpredis#1001 from yatsukhnenko/develop
Fix static analyzer warnings
2 parents 6de6374 + 8f3deb7 commit 73049f4

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed

cluster_library.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ unsigned short cluster_hash_key_zval(zval *z_key) {
589589
kptr = "Object";
590590
klen = sizeof("Object")-1;
591591
break;
592+
default:
593+
kptr = "";
594+
klen = 0;
592595
}
593596

594597
// Hash the string representation
@@ -1498,6 +1501,7 @@ PHP_REDIS_API void cluster_bulk_raw_resp(INTERNAL_FUNCTION_PARAMETERS,
14981501
RETURN_FALSE;
14991502
} else {
15001503
add_next_index_bool(c->multi_resp, 0);
1504+
return;
15011505
}
15021506
}
15031507

library.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,10 @@ PHP_REDIS_API void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, Redi
836836
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
837837
IF_MULTI_OR_PIPELINE() {
838838
add_next_index_bool(z_tab, 0);
839+
return;
839840
} else {
840841
RETURN_FALSE;
841842
}
842-
return;
843843
}
844844

845845
ret = atof(response);
@@ -859,6 +859,7 @@ PHP_REDIS_API void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
859859
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
860860
IF_MULTI_OR_PIPELINE() {
861861
add_next_index_bool(z_tab, 0);
862+
return;
862863
} else {
863864
RETURN_FALSE;
864865
}
@@ -1940,7 +1941,7 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
19401941
PHP_REDIS_API int redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz
19411942
TSRMLS_DC)
19421943
{
1943-
if(redis_sock && redis_sock->status == REDIS_SOCK_STATUS_DISCONNECTED) {
1944+
if (!redis_sock || redis_sock->status == REDIS_SOCK_STATUS_DISCONNECTED) {
19441945
zend_throw_exception(redis_exception_ce, "Connection closed",
19451946
0 TSRMLS_CC);
19461947
return -1;

redis.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,9 +2454,8 @@ redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETERS,
24542454
int numElems)
24552455
{
24562456

2457-
fold_item *head = redis_sock->head;
2458-
fold_item *current = redis_sock->current;
2459-
for(current = head; current; current = current->next) {
2457+
fold_item *current;
2458+
for (current = redis_sock->head; current; current = current->next) {
24602459
fold_this_item(INTERNAL_FUNCTION_PARAM_PASSTHRU, current, redis_sock,
24612460
z_tab);
24622461
}
@@ -2552,7 +2551,7 @@ PHP_REDIS_API void generic_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS,
25522551
if(*cmd) {
25532552
old_cmd = cmd;
25542553
}
2555-
cmd_len = spprintf(&cmd, 0, "%s %s", cmd, Z_STRVAL_P(data));
2554+
spprintf(&cmd, 0, "%s %s", cmd, Z_STRVAL_P(data));
25562555
if(old_cmd) {
25572556
efree(old_cmd);
25582557
}

redis_array.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
341341

342342
zval *zp_tmp, z_tmp;
343343
char *key = NULL; /* set to avoid "unused-but-set-variable" */
344-
int key_len;
345-
int i;
344+
int i, key_len = 0;
346345
zval *redis_inst;
347346
zval z_fun, *z_callargs;
348347
HashTable *h_args;

redis_array_impl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ ra_move_list(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
11221122
void
11231123
ra_move_key(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC) {
11241124

1125-
long res[2], type, ttl;
1125+
long res[2] = {0}, type, ttl;
11261126
zend_bool success = 0;
11271127
if (ra_get_key_type(z_from, key, key_len, z_from, res TSRMLS_CC)) {
11281128
type = res[0];
@@ -1224,7 +1224,7 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool
12241224
/* check that we're not moving to the same node. */
12251225
z_target = ra_find_node(ra, keys[i], key_lens[i], &target_pos TSRMLS_CC);
12261226

1227-
if(strcmp(hostname, ra->hosts[target_pos])) { /* different host */
1227+
if (z_target && strcmp(hostname, ra->hosts[target_pos])) { /* different host */
12281228
/* php_printf("move [%s] from [%s] to [%s]\n", keys[i], hostname, ra->hosts[target_pos]); */
12291229
ra_move_key(keys[i], key_lens[i], z_redis, z_target TSRMLS_CC);
12301230
}

redis_cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ static void cluster_eval_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
18891889
zval *z_arr=NULL, *z_ele;
18901890
HashTable *ht_arr;
18911891
long num_keys = 0;
1892-
short slot;
1892+
short slot = 0;
18931893
smart_string cmdstr = {0};
18941894

18951895
/* Parse args */

redis_commands.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,11 +2986,16 @@ int redis_command_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
29862986
/* Construct our command */
29872987
if(!kw) {
29882988
*cmd_len = redis_cmd_format_static(cmd, "COMMAND", "");
2989-
} else if(kw && !z_arg) {
2989+
} else if (!z_arg) {
29902990
/* Sanity check */
2991-
if(strncasecmp(kw, "info", sizeof("info")-1) ||
2992-
Z_TYPE_P(z_arg)!=IS_STRING)
2993-
{
2991+
if (strncasecmp(kw, "count", sizeof("count") - 1)) {
2992+
return FAILURE;
2993+
}
2994+
/* COMMAND COUNT */
2995+
*cmd_len = redis_cmd_format_static(cmd, "COMMAND", "s", "COUNT", sizeof("COUNT") - 1);
2996+
} else if (Z_TYPE_P(z_arg) == IS_STRING) {
2997+
/* Sanity check */
2998+
if (strncasecmp(kw, "info", sizeof("info") - 1)) {
29942999
return FAILURE;
29953000
}
29963001

0 commit comments

Comments
 (0)