Commit 25cd884f authored by Jin Qing's avatar Jin Qing
Browse files

Fix __redisSetErrorFromErrno() can not get error string.

snprintf() may change errno.
parent 33152ad1
...@@ -65,12 +65,13 @@ static void redisContextCloseFd(redisContext *c) { ...@@ -65,12 +65,13 @@ static void redisContextCloseFd(redisContext *c) {
} }
static void __redisSetErrorFromErrno(redisContext *c, int type, const char *prefix) { static void __redisSetErrorFromErrno(redisContext *c, int type, const char *prefix) {
int errorno = errno; /* snprintf() may change errno */
char buf[128] = { 0 }; char buf[128] = { 0 };
size_t len = 0; size_t len = 0;
if (prefix != NULL) if (prefix != NULL)
len = snprintf(buf,sizeof(buf),"%s: ",prefix); len = snprintf(buf,sizeof(buf),"%s: ",prefix);
__redis_strerror_r(errno, (char *)(buf + len), sizeof(buf) - len); __redis_strerror_r(errorno, (char *)(buf + len), sizeof(buf) - len);
__redisSetError(c,type,buf); __redisSetError(c,type,buf);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment