-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix sign error, int/size_t discrepancies, warnings on windows builds. #936
base: master
Are you sure you want to change the base?
Changes from all commits
e10388c
429c07f
4c8e732
5e8900a
b4b858d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,12 +312,12 @@ static size_t bulklen(size_t len) { | |
int redisvFormatCommand(char **target, const char *format, va_list ap) { | ||
const char *c = format; | ||
char *cmd = NULL; /* final command */ | ||
int pos; /* position in final command */ | ||
size_t pos; /* position in final command */ | ||
sds curarg, newarg; /* current argument */ | ||
int touched = 0; /* was the current argument touched? */ | ||
char **curargv = NULL, **newargv = NULL; | ||
int argc = 0; | ||
int totlen = 0; | ||
size_t totlen = 0; | ||
int error_type = 0; /* 0 = no error; -1 = memory error; -2 = format error */ | ||
int j; | ||
|
||
|
@@ -516,7 +516,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) { | |
|
||
hi_free(curargv); | ||
*target = cmd; | ||
return totlen; | ||
return (int)totlen; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These commands really should return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this comment was written, the API has been updated to return |
||
|
||
format_err: | ||
error_type = -2; | ||
|
@@ -576,7 +576,7 @@ long long redisFormatSdsCommandArgv(sds *target, int argc, const char **argv, | |
const size_t *argvlen) | ||
{ | ||
sds cmd, aux; | ||
unsigned long long totlen, len; | ||
size_t totlen, len; | ||
int j; | ||
|
||
/* Abort on a NULL target */ | ||
|
@@ -608,15 +608,15 @@ long long redisFormatSdsCommandArgv(sds *target, int argc, const char **argv, | |
cmd = sdscatfmt(cmd, "*%i\r\n", argc); | ||
for (j=0; j < argc; j++) { | ||
len = argvlen ? argvlen[j] : strlen(argv[j]); | ||
cmd = sdscatfmt(cmd, "$%U\r\n", len); | ||
cmd = sdscatfmt(cmd, "$%U\r\n", (unsigned long long)len); | ||
cmd = sdscatlen(cmd, argv[j], len); | ||
cmd = sdscatlen(cmd, "\r\n", sizeof("\r\n")-1); | ||
} | ||
|
||
assert(sdslen(cmd)==totlen); | ||
|
||
*target = cmd; | ||
return totlen; | ||
return (long long) totlen; /* api doesn't use ssize_t */ | ||
} | ||
|
||
void redisFreeSdsCommand(sds cmd) { | ||
|
@@ -663,7 +663,7 @@ long long redisFormatCommandArgv(char **target, int argc, const char **argv, con | |
cmd[pos] = '\0'; | ||
|
||
*target = cmd; | ||
return totlen; | ||
return (long long) totlen; /* api doesn't use ssize_t */ | ||
} | ||
|
||
void redisFreeCommand(char *cmd) { | ||
|
@@ -941,7 +941,7 @@ redisPushFn *redisSetPushCallback(redisContext *c, redisPushFn *fn) { | |
* see if there is a reply available. */ | ||
int redisBufferRead(redisContext *c) { | ||
char buf[1024*16]; | ||
int nread; | ||
ssize_t nread; | ||
|
||
/* Return early when the context has seen an error. */ | ||
if (c->err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,7 +272,7 @@ static int redisContextWaitReady(redisContext *c, long msec) { | |
} | ||
|
||
int redisCheckConnectDone(redisContext *c, int *completed) { | ||
int rc = connect(c->fd, (const struct sockaddr *)c->saddr, c->addrlen); | ||
int rc = connect(c->fd, (const struct sockaddr *)c->saddr, (socklen_t)c->addrlen); | ||
if (rc == 0) { | ||
*completed = 1; | ||
return REDIS_OK; | ||
|
@@ -331,7 +331,7 @@ int redisCheckSocketError(redisContext *c) { | |
|
||
int redisContextSetTimeout(redisContext *c, const struct timeval tv) { | ||
const void *to_ptr = &tv; | ||
size_t to_sz = sizeof(tv); | ||
socklen_t to_sz = sizeof(tv); | ||
|
||
if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,to_ptr,to_sz) == -1) { | ||
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)"); | ||
|
@@ -473,7 +473,7 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port, | |
} | ||
|
||
for (b = bservinfo; b != NULL; b = b->ai_next) { | ||
if (bind(s,b->ai_addr,b->ai_addrlen) != -1) { | ||
if (bind(s,b->ai_addr,(socklen_t)b->ai_addrlen) != -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Windows has |
||
bound = 1; | ||
break; | ||
} | ||
|
@@ -496,7 +496,7 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port, | |
memcpy(c->saddr, p->ai_addr, p->ai_addrlen); | ||
c->addrlen = p->ai_addrlen; | ||
|
||
if (connect(s,p->ai_addr,p->ai_addrlen) == -1) { | ||
if (connect(s,p->ai_addr,(socklen_t)p->ai_addrlen) == -1) { | ||
if (errno == EHOSTUNREACH) { | ||
redisNetClose(c); | ||
continue; | ||
|
@@ -616,13 +616,13 @@ int redisContextConnectUnix(redisContext *c, const char *path, const struct time | |
|
||
c->flags |= REDIS_CONNECTED; | ||
return REDIS_OK; | ||
oom: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix error about unused label (windows) |
||
__redisSetError(c, REDIS_ERR_OOM, "Out of memory"); | ||
return REDIS_ERR; | ||
#else | ||
/* We currently do not support Unix sockets for Windows. */ | ||
/* TODO(m): https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ */ | ||
errno = EPROTONOSUPPORT; | ||
return REDIS_ERR; | ||
#endif /* _WIN32 */ | ||
oom: | ||
__redisSetError(c, REDIS_ERR_OOM, "Out of memory"); | ||
return REDIS_ERR; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,9 @@ | |
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/* turn of windows warnings for _strcmp etc. */ | ||
#define _CRT_NONSTDC_NO_DEPRECATE | ||
|
||
#include "fmacros.h" | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
@@ -213,7 +216,7 @@ static int string2ll(const char *s, size_t slen, long long *value) { | |
if (negative) { | ||
if (v > ((unsigned long long)(-(LLONG_MIN+1))+1)) /* Overflow. */ | ||
return REDIS_ERR; | ||
if (value != NULL) *value = -v; | ||
if (value != NULL) *value = -(long long)v; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning on windows. Negation of an unsigned variable is shaky ground in C, better to be explicit. |
||
} else { | ||
if (v > LLONG_MAX) /* Overflow. */ | ||
return REDIS_ERR; | ||
|
@@ -222,9 +225,9 @@ static int string2ll(const char *s, size_t slen, long long *value) { | |
return REDIS_OK; | ||
} | ||
|
||
static char *readLine(redisReader *r, int *_len) { | ||
static char *readLine(redisReader *r, size_t *_len) { | ||
char *p, *s; | ||
int len; | ||
size_t len; | ||
|
||
p = r->buf+r->pos; | ||
s = seekNewline(p,(r->len-r->pos)); | ||
|
@@ -269,7 +272,7 @@ static int processLineItem(redisReader *r) { | |
redisReadTask *cur = r->task[r->ridx]; | ||
void *obj; | ||
char *p; | ||
int len; | ||
size_t len; | ||
|
||
if ((p = readLine(r,&len)) != NULL) { | ||
if (cur->type == REDIS_REPLY_INTEGER) { | ||
|
@@ -290,7 +293,7 @@ static int processLineItem(redisReader *r) { | |
char buf[326], *eptr; | ||
double d; | ||
|
||
if ((size_t)len >= sizeof(buf)) { | ||
if (len >= sizeof(buf)) { | ||
__redisReaderSetError(r,REDIS_ERR_PROTOCOL, | ||
"Double value is too large"); | ||
return REDIS_ERR; | ||
|
@@ -349,7 +352,7 @@ static int processLineItem(redisReader *r) { | |
} else if (cur->type == REDIS_REPLY_BIGNUM) { | ||
/* Ensure all characters are decimal digits (with possible leading | ||
* minus sign). */ | ||
for (int i = 0; i < len; i++) { | ||
for (size_t i = 0; i < len; i++) { | ||
/* XXX Consider: Allow leading '+'? Error on leading '0's? */ | ||
if (i == 0 && p[0] == '-') continue; | ||
if (p[i] < '0' || p[i] > '9') { | ||
|
@@ -364,7 +367,7 @@ static int processLineItem(redisReader *r) { | |
obj = (void*)REDIS_REPLY_BIGNUM; | ||
} else { | ||
/* Type will be error or status. */ | ||
for (int i = 0; i < len; i++) { | ||
for (size_t i = 0; i < len; i++) { | ||
if (p[i] == '\r' || p[i] == '\n') { | ||
__redisReaderSetError(r,REDIS_ERR_PROTOCOL, | ||
"Bad simple string value"); | ||
|
@@ -396,7 +399,7 @@ static int processBulkItem(redisReader *r) { | |
void *obj = NULL; | ||
char *p, *s; | ||
long long len; | ||
unsigned long bytelen; | ||
size_t bytelen; | ||
int success = 0; | ||
|
||
p = r->buf+r->pos; | ||
|
@@ -494,7 +497,8 @@ static int processAggregateItem(redisReader *r) { | |
void *obj; | ||
char *p; | ||
long long elements; | ||
int root = 0, len; | ||
int root = 0; | ||
size_t len; | ||
|
||
if (r->ridx == r->tasks - 1) { | ||
if (redisReaderGrow(r) == REDIS_ERR) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These commands really should return a
ssize_t
result to be consistent with the use ofsize_t
, but I didn't want to modify their signature since they are a public APIThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since then, have updated to reflect the new api which returns
long long
. Why that was chosen instead ofsize_t
orssize_t
is unclear.