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

Skip to content

Commit f8c762e

Browse files
Use ZEND_STRL where appropriate.
Use the `ZEND_STRL` macro in several places rather than manually sending a static string and its length as a constant.
1 parent c139de3 commit f8c762e

4 files changed

Lines changed: 35 additions & 25 deletions

File tree

cluster_library.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,15 +1910,15 @@ PHP_REDIS_API void cluster_type_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
19101910
// Switch on the type
19111911
if (strncmp (c->line_reply, "string", 6) == 0) {
19121912
CLUSTER_RETURN_LONG(c, REDIS_STRING);
1913-
} else if (strncmp(c->line_reply, "set", 3) == 0) {
1913+
} else if (strncmp(c->line_reply, ZEND_STRL("set")) == 0) {
19141914
CLUSTER_RETURN_LONG(c, REDIS_SET);
1915-
} else if (strncmp(c->line_reply, "list", 4) == 0) {
1915+
} else if (strncmp(c->line_reply, ZEND_STRL("list")) == 0) {
19161916
CLUSTER_RETURN_LONG(c, REDIS_LIST);
1917-
} else if (strncmp(c->line_reply, "hash", 4) == 0) {
1917+
} else if (strncmp(c->line_reply, ZEND_STRL("hash")) == 0) {
19181918
CLUSTER_RETURN_LONG(c, REDIS_HASH);
1919-
} else if (strncmp(c->line_reply, "zset", 4) == 0) {
1919+
} else if (strncmp(c->line_reply, ZEND_STRL("zset")) == 0) {
19201920
CLUSTER_RETURN_LONG(c, REDIS_ZSET);
1921-
} else if (strncmp(c->line_reply, "stream", 6) == 0) {
1921+
} else if (strncmp(c->line_reply, ZEND_STRL("stream")) == 0) {
19221922
CLUSTER_RETURN_LONG(c, REDIS_STREAM);
19231923
} else {
19241924
CLUSTER_RETURN_LONG(c, REDIS_NOT_FOUND);
@@ -1977,8 +1977,8 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
19771977
}
19781978

19791979
// Make sure we have a message or pmessage
1980-
if (!strncmp(Z_STRVAL_P(z_type), "message", 7) ||
1981-
!strncmp(Z_STRVAL_P(z_type), "pmessage", 8)
1980+
if (!strncmp(Z_STRVAL_P(z_type), ZEND_STRL("message")) ||
1981+
!strncmp(Z_STRVAL_P(z_type), ZEND_STRL("pmessage"))
19821982
) {
19831983
is_pmsg = *Z_STRVAL_P(z_type) == 'p';
19841984
} else {

library.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static int reselect_db(RedisSock *redis_sock) {
155155
return -1;
156156
}
157157

158-
if (strncmp(response, "+OK", 3)) {
158+
if (strncmp(response, ZEND_STRL("+OK"))) {
159159
efree(response);
160160
return -1;
161161
}
@@ -254,7 +254,9 @@ PHP_REDIS_API int redis_sock_auth(RedisSock *redis_sock) {
254254
}
255255
efree(cmd);
256256

257-
if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0 || strncmp(inbuf, "+OK", 3)) {
257+
if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0 ||
258+
strncmp(inbuf, ZEND_STRL("+OK")))
259+
{
258260
return FAILURE;
259261
}
260262
return SUCCESS;
@@ -1208,17 +1210,17 @@ PHP_REDIS_API int redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *r
12081210
return FAILURE;
12091211
}
12101212

1211-
if (strncmp(response, "+string", 7) == 0) {
1213+
if (strncmp(response, ZEND_STRL("+string")) == 0) {
12121214
l = REDIS_STRING;
1213-
} else if (strncmp(response, "+set", 4) == 0){
1215+
} else if (strncmp(response, ZEND_STRL("+set")) == 0){
12141216
l = REDIS_SET;
1215-
} else if (strncmp(response, "+list", 5) == 0){
1217+
} else if (strncmp(response, ZEND_STRL("+list")) == 0){
12161218
l = REDIS_LIST;
1217-
} else if (strncmp(response, "+zset", 5) == 0){
1219+
} else if (strncmp(response, ZEND_STRL("+zset")) == 0){
12181220
l = REDIS_ZSET;
1219-
} else if (strncmp(response, "+hash", 5) == 0){
1221+
} else if (strncmp(response, ZEND_STRL("+hash")) == 0){
12201222
l = REDIS_HASH;
1221-
} else if (strncmp(response, "+stream", 7) == 0) {
1223+
} else if (strncmp(response, ZEND_STRL("+stream")) == 0) {
12221224
l = REDIS_STREAM;
12231225
} else {
12241226
l = REDIS_NOT_FOUND;
@@ -3019,14 +3021,19 @@ redis_sock_check_liveness(RedisSock *redis_sock)
30193021
}
30203022

30213023
if (auth) {
3022-
if (strncmp(inbuf, "+OK", 3) == 0 || strncmp(inbuf, "-ERR Client sent AUTH", 21) == 0) {
3024+
if (strncmp(inbuf, ZEND_STRL("+OK")) == 0 ||
3025+
strncmp(inbuf, ZEND_STRL("-ERR Client sent AUTH")) == 0)
3026+
{
30233027
/* successfully authenticated or authentication isn't required */
30243028
if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0) {
30253029
goto failure;
30263030
}
3027-
} else if (strncmp(inbuf, "-NOAUTH", 7) == 0) {
3028-
/* connection is fine but authentication failed, next command must fails too */
3029-
if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0 || strncmp(inbuf, "-NOAUTH", 7) != 0) {
3031+
} else if (strncmp(inbuf, ZEND_STRL("-NOAUTH")) == 0) {
3032+
/* connection is fine but authentication failed, next command must
3033+
* fail too */
3034+
if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0
3035+
|| strncmp(inbuf, ZEND_STRL("-NOAUTH")) != 0)
3036+
{
30303037
goto failure;
30313038
}
30323039
return SUCCESS;
@@ -3035,15 +3042,15 @@ redis_sock_check_liveness(RedisSock *redis_sock)
30353042
}
30363043
redis_sock->status = REDIS_SOCK_STATUS_AUTHENTICATED;
30373044
} else {
3038-
if (strncmp(inbuf, "-NOAUTH", 7) == 0) {
3045+
if (strncmp(inbuf, ZEND_STRL("-NOAUTH")) == 0) {
30393046
/* connection is fine but authentication required */
30403047
return SUCCESS;
30413048
}
30423049
}
30433050

30443051
/* check echo response */
30453052
if ((redis_sock->sentinel && (
3046-
strncmp(inbuf, "-ERR unknown command", 20) != 0 ||
3053+
strncmp(inbuf, ZEND_STRL("-ERR unknown command")) != 0 ||
30473054
strstr(inbuf, id) == NULL
30483055
)) || *inbuf != TYPE_BULK || atoi(inbuf + 1) != idlen ||
30493056
redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0 ||

redis.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ PHP_METHOD(Redis, multi)
19061906
}
19071907
if ((resp = redis_sock_read(redis_sock, &resp_len)) == NULL) {
19081908
RETURN_FALSE;
1909-
} else if (strncmp(resp, "+OK", 3) != 0) {
1909+
} else if (strncmp(resp, ZEND_STRL("+OK")) != 0) {
19101910
efree(resp);
19111911
RETURN_FALSE;
19121912
}
@@ -2045,7 +2045,7 @@ redis_response_enqueued(RedisSock *redis_sock)
20452045
int resp_len, ret = FAILURE;
20462046

20472047
if ((resp = redis_sock_read(redis_sock, &resp_len)) != NULL) {
2048-
if (strncmp(resp, "+QUEUED", 7) == 0) {
2048+
if (strncmp(resp, ZEND_STRL("+QUEUED")) == 0) {
20492049
ret = SUCCESS;
20502050
}
20512051
efree(resp);
@@ -2068,7 +2068,9 @@ redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETERS,
20682068
size_t len;
20692069
char inbuf[255];
20702070

2071-
if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0 || strncmp(inbuf, "+OK", 3) != 0) {
2071+
if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0 ||
2072+
strncmp(inbuf, ZEND_STRL("+OK")) != 0)
2073+
{
20722074
return FAILURE;
20732075
}
20742076

redis_array_impl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ RedisArray *ra_load_array(const char *name) {
277277
array_init(&z_tmp);
278278
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
279279
if ((z_data = zend_hash_str_find(Z_ARRVAL(z_tmp), name, name_len)) != NULL) {
280-
consistent = Z_TYPE_P(z_data) == IS_STRING && strncmp(Z_STRVAL_P(z_data), "1", 1) == 0;
280+
consistent = Z_TYPE_P(z_data) == IS_STRING &&
281+
strncmp(Z_STRVAL_P(z_data), ZEND_STRL("1")) == 0;
281282
}
282283
zval_dtor(&z_tmp);
283284
}

0 commit comments

Comments
 (0)