From 09a0fe626fa7d53666a3fa53aca79880f8fe3bff Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 15 Nov 2010 21:53:22 +0100 Subject: Explicitly initialize struct fields to NULL --- async.c | 13 +++++++++++-- async.h | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/async.c b/async.c index 04a4245..6821755 100644 --- a/async.c +++ b/async.c @@ -38,8 +38,17 @@ void __redisAppendCommand(redisContext *c, char *cmd, size_t len); static redisAsyncContext *redisAsyncInitialize(redisContext *c) { redisAsyncContext *ac = realloc(c,sizeof(redisAsyncContext)); - /* Set all bytes in the async part of the context to 0 */ - memset(ac+sizeof(redisContext),0,sizeof(redisAsyncContext)-sizeof(redisContext)); + ac->err = 0; + ac->errstr = NULL; + ac->data = NULL; + ac->evAddRead = NULL; + ac->evDelRead = NULL; + ac->evAddWrite = NULL; + ac->evDelWrite = NULL; + ac->evCleanup = NULL; + ac->onDisconnect = NULL; + ac->replies.head = NULL; + ac->replies.tail = NULL; return ac; } diff --git a/async.h b/async.h index d0a99da..be3a7a9 100644 --- a/async.h +++ b/async.h @@ -58,6 +58,9 @@ typedef struct redisAsyncContext { int err; char *errstr; + /* Not used by hiredis */ + void *data; + /* Called when the library expects to start reading/writing. * The supplied functions should be idempotent. */ void (*evAddRead)(void *privdata); @@ -65,7 +68,6 @@ typedef struct redisAsyncContext { void (*evAddWrite)(void *privdata); void (*evDelWrite)(void *privdata); void (*evCleanup)(void *privdata); - void *data; /* Called when either the connection is terminated due to an error or per * user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */ -- cgit v1.2.3