mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Merge pull request #2301 from mattsta/fix/lengths
Improve type correctness
This commit is contained in:
commit
d83c810265
@ -391,7 +391,7 @@ int anetUnixNonBlockConnect(char *err, char *path)
|
|||||||
* (unless error or EOF condition is encountered) */
|
* (unless error or EOF condition is encountered) */
|
||||||
int anetRead(int fd, char *buf, int count)
|
int anetRead(int fd, char *buf, int count)
|
||||||
{
|
{
|
||||||
int nread, totlen = 0;
|
ssize_t nread, totlen = 0;
|
||||||
while(totlen != count) {
|
while(totlen != count) {
|
||||||
nread = read(fd,buf,count-totlen);
|
nread = read(fd,buf,count-totlen);
|
||||||
if (nread == 0) return totlen;
|
if (nread == 0) return totlen;
|
||||||
@ -406,7 +406,7 @@ int anetRead(int fd, char *buf, int count)
|
|||||||
* (unless error is encountered) */
|
* (unless error is encountered) */
|
||||||
int anetWrite(int fd, char *buf, int count)
|
int anetWrite(int fd, char *buf, int count)
|
||||||
{
|
{
|
||||||
int nwritten, totlen = 0;
|
ssize_t nwritten, totlen = 0;
|
||||||
while(totlen != count) {
|
while(totlen != count) {
|
||||||
nwritten = write(fd,buf,count-totlen);
|
nwritten = write(fd,buf,count-totlen);
|
||||||
if (nwritten == 0) return totlen;
|
if (nwritten == 0) return totlen;
|
||||||
|
@ -4552,7 +4552,7 @@ try_again:
|
|||||||
{
|
{
|
||||||
sds buf = cmd.io.buffer.ptr;
|
sds buf = cmd.io.buffer.ptr;
|
||||||
size_t pos = 0, towrite;
|
size_t pos = 0, towrite;
|
||||||
int nwritten = 0;
|
ssize_t nwritten = 0;
|
||||||
|
|
||||||
while ((towrite = sdslen(buf)-pos) > 0) {
|
while ((towrite = sdslen(buf)-pos) > 0) {
|
||||||
towrite = (towrite > (64*1024) ? (64*1024) : towrite);
|
towrite = (towrite > (64*1024) ? (64*1024) : towrite);
|
||||||
|
@ -336,10 +336,10 @@ void debugCommand(redisClient *c) {
|
|||||||
|
|
||||||
addReplyStatusFormat(c,
|
addReplyStatusFormat(c,
|
||||||
"Value at:%p refcount:%d "
|
"Value at:%p refcount:%d "
|
||||||
"encoding:%s serializedlength:%lld "
|
"encoding:%s serializedlength:%zu "
|
||||||
"lru:%d lru_seconds_idle:%llu%s",
|
"lru:%d lru_seconds_idle:%llu%s",
|
||||||
(void*)val, val->refcount,
|
(void*)val, val->refcount,
|
||||||
strenc, (long long) rdbSavedObjectLen(val),
|
strenc, rdbSavedObjectLen(val),
|
||||||
val->lru, estimateObjectIdleTime(val)/1000, extra);
|
val->lru, estimateObjectIdleTime(val)/1000, extra);
|
||||||
} else if (!strcasecmp(c->argv[1]->ptr,"sdslen") && c->argc == 3) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"sdslen") && c->argc == 3) {
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
|
@ -797,7 +797,8 @@ void freeClientsInAsyncFreeQueue(void) {
|
|||||||
|
|
||||||
void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
|
void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||||
redisClient *c = privdata;
|
redisClient *c = privdata;
|
||||||
int nwritten = 0, totwritten = 0, objlen;
|
ssize_t nwritten = 0, totwritten = 0;
|
||||||
|
size_t objlen;
|
||||||
size_t objmem;
|
size_t objmem;
|
||||||
robj *o;
|
robj *o;
|
||||||
REDIS_NOTUSED(el);
|
REDIS_NOTUSED(el);
|
||||||
@ -1621,7 +1622,7 @@ int checkClientOutputBufferLimits(redisClient *c) {
|
|||||||
* called from contexts where the client can't be freed safely, i.e. from the
|
* called from contexts where the client can't be freed safely, i.e. from the
|
||||||
* lower level functions pushing data inside the client output buffers. */
|
* lower level functions pushing data inside the client output buffers. */
|
||||||
void asyncCloseClientOnOutputBufferLimitReached(redisClient *c) {
|
void asyncCloseClientOnOutputBufferLimitReached(redisClient *c) {
|
||||||
redisAssert(c->reply_bytes < ULONG_MAX-(1024*64));
|
redisAssert(c->reply_bytes < SIZE_MAX-(1024*64));
|
||||||
if (c->reply_bytes == 0 || c->flags & REDIS_CLOSE_ASAP) return;
|
if (c->reply_bytes == 0 || c->flags & REDIS_CLOSE_ASAP) return;
|
||||||
if (checkClientOutputBufferLimits(c)) {
|
if (checkClientOutputBufferLimits(c)) {
|
||||||
sds client = catClientInfoString(sdsempty(),c);
|
sds client = catClientInfoString(sdsempty(),c);
|
||||||
|
26
src/rdb.c
26
src/rdb.c
@ -232,10 +232,10 @@ int rdbTryIntegerEncoding(char *s, size_t len, unsigned char *enc) {
|
|||||||
return rdbEncodeInteger(value,enc);
|
return rdbEncodeInteger(value,enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rdbSaveLzfBlob(rio *rdb, void *data, size_t compress_len,
|
ssize_t rdbSaveLzfBlob(rio *rdb, void *data, size_t compress_len,
|
||||||
size_t original_len) {
|
size_t original_len) {
|
||||||
unsigned char byte;
|
unsigned char byte;
|
||||||
int n, nwritten = 0;
|
ssize_t n, nwritten = 0;
|
||||||
|
|
||||||
/* Data compressed! Let's save it on disk */
|
/* Data compressed! Let's save it on disk */
|
||||||
byte = (REDIS_RDB_ENCVAL<<6)|REDIS_RDB_ENC_LZF;
|
byte = (REDIS_RDB_ENCVAL<<6)|REDIS_RDB_ENC_LZF;
|
||||||
@ -257,7 +257,7 @@ writeerr:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rdbSaveLzfStringObject(rio *rdb, unsigned char *s, size_t len) {
|
ssize_t rdbSaveLzfStringObject(rio *rdb, unsigned char *s, size_t len) {
|
||||||
size_t comprlen, outlen;
|
size_t comprlen, outlen;
|
||||||
void *out;
|
void *out;
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ int rdbSaveLzfStringObject(rio *rdb, unsigned char *s, size_t len) {
|
|||||||
zfree(out);
|
zfree(out);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t nwritten = rdbSaveLzfBlob(rdb, out, comprlen, len);
|
ssize_t nwritten = rdbSaveLzfBlob(rdb, out, comprlen, len);
|
||||||
zfree(out);
|
zfree(out);
|
||||||
return nwritten;
|
return nwritten;
|
||||||
}
|
}
|
||||||
@ -315,9 +315,9 @@ err:
|
|||||||
|
|
||||||
/* Save a string object as [len][data] on disk. If the object is a string
|
/* Save a string object as [len][data] on disk. If the object is a string
|
||||||
* representation of an integer value we try to save it in a special form */
|
* representation of an integer value we try to save it in a special form */
|
||||||
int rdbSaveRawString(rio *rdb, unsigned char *s, size_t len) {
|
ssize_t rdbSaveRawString(rio *rdb, unsigned char *s, size_t len) {
|
||||||
int enclen;
|
int enclen;
|
||||||
int n, nwritten = 0;
|
ssize_t n, nwritten = 0;
|
||||||
|
|
||||||
/* Try integer encoding */
|
/* Try integer encoding */
|
||||||
if (len <= 11) {
|
if (len <= 11) {
|
||||||
@ -348,9 +348,9 @@ int rdbSaveRawString(rio *rdb, unsigned char *s, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Save a long long value as either an encoded string or a string. */
|
/* Save a long long value as either an encoded string or a string. */
|
||||||
int rdbSaveLongLongAsStringObject(rio *rdb, long long value) {
|
ssize_t rdbSaveLongLongAsStringObject(rio *rdb, long long value) {
|
||||||
unsigned char buf[32];
|
unsigned char buf[32];
|
||||||
int n, nwritten = 0;
|
ssize_t n, nwritten = 0;
|
||||||
int enclen = rdbEncodeInteger(value,buf);
|
int enclen = rdbEncodeInteger(value,buf);
|
||||||
if (enclen > 0) {
|
if (enclen > 0) {
|
||||||
return rdbWriteRaw(rdb,buf,enclen);
|
return rdbWriteRaw(rdb,buf,enclen);
|
||||||
@ -542,8 +542,8 @@ int rdbLoadObjectType(rio *rdb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Save a Redis object. Returns -1 on error, number of bytes written on success. */
|
/* Save a Redis object. Returns -1 on error, number of bytes written on success. */
|
||||||
int rdbSaveObject(rio *rdb, robj *o) {
|
ssize_t rdbSaveObject(rio *rdb, robj *o) {
|
||||||
int n = 0, nwritten = 0;
|
ssize_t n = 0, nwritten = 0;
|
||||||
|
|
||||||
if (o->type == REDIS_STRING) {
|
if (o->type == REDIS_STRING) {
|
||||||
/* Save a string value */
|
/* Save a string value */
|
||||||
@ -664,8 +664,8 @@ int rdbSaveObject(rio *rdb, robj *o) {
|
|||||||
* the rdbSaveObject() function. Currently we use a trick to get
|
* the rdbSaveObject() function. Currently we use a trick to get
|
||||||
* this length with very little changes to the code. In the future
|
* this length with very little changes to the code. In the future
|
||||||
* we could switch to a faster solution. */
|
* we could switch to a faster solution. */
|
||||||
off_t rdbSavedObjectLen(robj *o) {
|
size_t rdbSavedObjectLen(robj *o) {
|
||||||
int len = rdbSaveObject(NULL,o);
|
ssize_t len = rdbSaveObject(NULL,o);
|
||||||
redisAssertWithInfo(NULL,o,len != -1);
|
redisAssertWithInfo(NULL,o,len != -1);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
@ -109,9 +109,8 @@ int rdbSaveBackground(char *filename);
|
|||||||
int rdbSaveToSlavesSockets(void);
|
int rdbSaveToSlavesSockets(void);
|
||||||
void rdbRemoveTempFile(pid_t childpid);
|
void rdbRemoveTempFile(pid_t childpid);
|
||||||
int rdbSave(char *filename);
|
int rdbSave(char *filename);
|
||||||
int rdbSaveObject(rio *rdb, robj *o);
|
ssize_t rdbSaveObject(rio *rdb, robj *o);
|
||||||
off_t rdbSavedObjectLen(robj *o);
|
size_t rdbSavedObjectLen(robj *o);
|
||||||
off_t rdbSavedObjectPages(robj *o);
|
|
||||||
robj *rdbLoadObject(int type, rio *rdb);
|
robj *rdbLoadObject(int type, rio *rdb);
|
||||||
void backgroundSaveDoneHandler(int exitcode, int bysignal);
|
void backgroundSaveDoneHandler(int exitcode, int bysignal);
|
||||||
int rdbSaveKeyValuePair(rio *rdb, robj *key, robj *val, long long expiretime, long long now);
|
int rdbSaveKeyValuePair(rio *rdb, robj *key, robj *val, long long expiretime, long long now);
|
||||||
|
@ -86,7 +86,7 @@ typedef struct _client {
|
|||||||
char **randptr; /* Pointers to :rand: strings inside the command buf */
|
char **randptr; /* Pointers to :rand: strings inside the command buf */
|
||||||
size_t randlen; /* Number of pointers in client->randptr */
|
size_t randlen; /* Number of pointers in client->randptr */
|
||||||
size_t randfree; /* Number of unused pointers in client->randptr */
|
size_t randfree; /* Number of unused pointers in client->randptr */
|
||||||
unsigned int written; /* Bytes of 'obuf' already written */
|
size_t written; /* Bytes of 'obuf' already written */
|
||||||
long long start; /* Start time of a request */
|
long long start; /* Start time of a request */
|
||||||
long long latency; /* Request latency */
|
long long latency; /* Request latency */
|
||||||
int pending; /* Number of pending requests (replies to consume) */
|
int pending; /* Number of pending requests (replies to consume) */
|
||||||
@ -266,7 +266,7 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
|
|||||||
|
|
||||||
if (sdslen(c->obuf) > c->written) {
|
if (sdslen(c->obuf) > c->written) {
|
||||||
void *ptr = c->obuf+c->written;
|
void *ptr = c->obuf+c->written;
|
||||||
int nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
|
ssize_t nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
|
||||||
if (nwritten == -1) {
|
if (nwritten == -1) {
|
||||||
if (errno != EPIPE)
|
if (errno != EPIPE)
|
||||||
fprintf(stderr, "Writing to socket: %s\n", strerror(errno));
|
fprintf(stderr, "Writing to socket: %s\n", strerror(errno));
|
||||||
|
10
src/redis.h
10
src/redis.h
@ -543,8 +543,8 @@ typedef struct redisClient {
|
|||||||
int multibulklen; /* number of multi bulk arguments left to read */
|
int multibulklen; /* number of multi bulk arguments left to read */
|
||||||
long bulklen; /* length of bulk argument in multi bulk request */
|
long bulklen; /* length of bulk argument in multi bulk request */
|
||||||
list *reply;
|
list *reply;
|
||||||
unsigned long reply_bytes; /* Tot bytes of objects in reply list */
|
size_t reply_bytes; /* Tot bytes of objects in reply list */
|
||||||
int sentlen; /* Amount of bytes already sent in the current
|
size_t sentlen; /* Amount of bytes already sent in the current
|
||||||
buffer or object being sent. */
|
buffer or object being sent. */
|
||||||
time_t ctime; /* Client creation time */
|
time_t ctime; /* Client creation time */
|
||||||
time_t lastinteraction; /* time of the last interaction, used for timeout */
|
time_t lastinteraction; /* time of the last interaction, used for timeout */
|
||||||
@ -554,8 +554,8 @@ typedef struct redisClient {
|
|||||||
int replstate; /* replication state if this is a slave */
|
int replstate; /* replication state if this is a slave */
|
||||||
int repl_put_online_on_ack; /* Install slave write handler on ACK. */
|
int repl_put_online_on_ack; /* Install slave write handler on ACK. */
|
||||||
int repldbfd; /* replication DB file descriptor */
|
int repldbfd; /* replication DB file descriptor */
|
||||||
off_t repldboff; /* replication DB file offset */
|
size_t repldboff; /* replication DB file offset */
|
||||||
off_t repldbsize; /* replication DB file size */
|
size_t repldbsize; /* replication DB file size */
|
||||||
sds replpreamble; /* replication DB preamble. */
|
sds replpreamble; /* replication DB preamble. */
|
||||||
long long reploff; /* replication offset if this is our master */
|
long long reploff; /* replication offset if this is our master */
|
||||||
long long repl_ack_off; /* replication ack offset, if this is a slave */
|
long long repl_ack_off; /* replication ack offset, if this is a slave */
|
||||||
@ -572,7 +572,7 @@ typedef struct redisClient {
|
|||||||
sds peerid; /* Cached peer ID. */
|
sds peerid; /* Cached peer ID. */
|
||||||
|
|
||||||
/* Response buffer */
|
/* Response buffer */
|
||||||
int bufpos;
|
size_t bufpos;
|
||||||
char buf[REDIS_REPLY_CHUNK_BYTES];
|
char buf[REDIS_REPLY_CHUNK_BYTES];
|
||||||
} redisClient;
|
} redisClient;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user