summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2021-12-19 23:52:23 +0800
committerGitHub <noreply@github.com>2021-12-19 17:52:23 +0200
commit0fb1aa0645fd1e31d12c8d57d4326ded0aa4d555 (patch)
treea997d5739941b6036dc21fa57d489c273148669a /src
parent6add1b7217458dab90b2458e4bac3fa9a2c15e1b (diff)
downloadredis-0fb1aa0645fd1e31d12c8d57d4326ded0aa4d555.tar.gz
Fix some nonsense came from LGTM (#9962)
1. Local variable 's' hides a parameter of the same name. ``` int anetTcpAccept(char *err, int s, char *ip, size_t ip_len, int *port) { if ((fd = anetGenericAccept(err,s,(struct sockaddr*)&sa,&salen)) == ANET_ERR){} } ``` Change the parameter name from `s` to `serversock`, also unified with the header file definition. 2. Comparison is always false because i <= 48. ``` for (i = 0; i < DICT_STATS_VECTLEN-1; i++) { // i < 49 (i == DICT_STATS_VECTLEN-1)?">= ":"", // i == 49 } ``` `i == DICT_STATS_VECTLEN-1` always result false, it is a dead code. 3. Empty block without comment. `else if (!strcasecmp(opt,"ch")) {}`, add a comment to avoid warnings. 4. Bit field fill of type int should have explicitly unsigned integral, explicitly signed integral, or enumeration type. Modify `int fill: QL_FILL_BITS;` to `unsigned int fill: QL_FILL_BITS;` 5. The result of this call to reconnectingRedisCommand is not checked for null, but 80% of calls to reconnectingRedisCommand check for null. Just a cleanup job like others.
Diffstat (limited to 'src')
-rw-r--r--src/anet.c4
-rw-r--r--src/dict.c3
-rw-r--r--src/geo.c2
-rw-r--r--src/quicklist.h2
-rw-r--r--src/redis-cli.c9
5 files changed, 11 insertions, 9 deletions
diff --git a/src/anet.c b/src/anet.c
index b65301243..bde460fc8 100644
--- a/src/anet.c
+++ b/src/anet.c
@@ -529,11 +529,11 @@ static int anetGenericAccept(char *err, int s, struct sockaddr *sa, socklen_t *l
/* Accept a connection and also make sure the socket is non-blocking, and CLOEXEC.
* returns the new socket FD, or -1 on error. */
-int anetTcpAccept(char *err, int s, char *ip, size_t ip_len, int *port) {
+int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port) {
int fd;
struct sockaddr_storage sa;
socklen_t salen = sizeof(sa);
- if ((fd = anetGenericAccept(err,s,(struct sockaddr*)&sa,&salen)) == ANET_ERR)
+ if ((fd = anetGenericAccept(err,serversock,(struct sockaddr*)&sa,&salen)) == ANET_ERR)
return ANET_ERR;
if (sa.ss_family == AF_INET) {
diff --git a/src/dict.c b/src/dict.c
index 1420055e7..9d96c6c27 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -1154,8 +1154,7 @@ size_t _dictGetStatsHt(char *buf, size_t bufsize, dict *d, int htidx) {
if (clvector[i] == 0) continue;
if (l >= bufsize) break;
l += snprintf(buf+l,bufsize-l,
- " %s%ld: %ld (%.02f%%)\n",
- (i == DICT_STATS_VECTLEN-1)?">= ":"",
+ " %ld: %ld (%.02f%%)\n",
i, clvector[i], ((float)clvector[i]/DICTHT_SIZE(d->ht_size_exp[htidx]))*100);
}
diff --git a/src/geo.c b/src/geo.c
index d5a23f856..acfca2d08 100644
--- a/src/geo.c
+++ b/src/geo.c
@@ -444,7 +444,7 @@ void geoaddCommand(client *c) {
char *opt = c->argv[longidx]->ptr;
if (!strcasecmp(opt,"nx")) nx = 1;
else if (!strcasecmp(opt,"xx")) xx = 1;
- else if (!strcasecmp(opt,"ch")) {}
+ else if (!strcasecmp(opt,"ch")) { /* Handle in zaddCommand. */ }
else break;
longidx++;
}
diff --git a/src/quicklist.h b/src/quicklist.h
index 14c53ca4c..04136a733 100644
--- a/src/quicklist.h
+++ b/src/quicklist.h
@@ -107,7 +107,7 @@ typedef struct quicklist {
quicklistNode *tail;
unsigned long count; /* total count of all entries in all listpacks */
unsigned long len; /* number of quicklistNodes */
- int fill : QL_FILL_BITS; /* fill factor for individual nodes */
+ unsigned int fill : QL_FILL_BITS; /* fill factor for individual nodes */
unsigned int compress : QL_COMP_BITS; /* depth of end nodes not to compress;0=off */
unsigned int bookmark_count: QL_BM_BITS;
quicklistBookmark bookmarks[];
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 950e591f1..c826a93f0 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -7904,8 +7904,11 @@ static void statMode(void) {
int j;
reply = reconnectingRedisCommand(context,"INFO");
- if (reply->type == REDIS_REPLY_ERROR) {
- printf("ERROR: %s\n", reply->str);
+ if (reply == NULL) {
+ fprintf(stderr, "\nI/O error\n");
+ exit(1);
+ } else if (reply->type == REDIS_REPLY_ERROR) {
+ fprintf(stderr, "ERROR: %s\n", reply->str);
exit(1);
}
@@ -8071,7 +8074,7 @@ static void LRUTestMode(void) {
if (redisGetReply(context, (void**)&reply) == REDIS_OK) {
switch(reply->type) {
case REDIS_REPLY_ERROR:
- printf("%s\n", reply->str);
+ fprintf(stderr, "%s\n", reply->str);
break;
case REDIS_REPLY_NIL:
misses++;