From 12408853ccdabd7d2aff1b86dc848a2755391bd2 Mon Sep 17 00:00:00 2001 From: oetiker Date: Sat, 16 Dec 2006 16:14:43 +0000 Subject: [PATCH] add missing \0 to the end of several strncpy strings git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@938 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_error.c | 2 +- src/rrd_thread_safe.c | 1 + src/rrd_thread_safe_nt.c | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rrd_error.c b/src/rrd_error.c index a102b1f..68fcc8e 100644 --- a/src/rrd_error.c +++ b/src/rrd_error.c @@ -80,6 +80,7 @@ rrd_set_error_r(struct rrd_context *rrd_ctx, char *fmt, ...) va_start(argp, fmt); #ifdef HAVE_VSNPRINTF vsnprintf((char *)rrd_ctx->rrd_error, rrd_ctx->len, fmt, argp); + rrd_ctx->rrd_error[rrd_ctx->len]='\0'; #else vsprintf((char *)rrd_ctx->rrd_error, fmt, argp); #endif @@ -110,7 +111,6 @@ rrd_new_context(void) { (struct rrd_context *) malloc(sizeof(struct rrd_context)); if (rrd_ctx) { - rrd_ctx->len = 0; rrd_ctx->rrd_error = malloc(MAXLEN+10); rrd_ctx->lib_errstr = malloc(ERRBUFLEN+10); if (rrd_ctx->rrd_error && rrd_ctx->lib_errstr) { diff --git a/src/rrd_thread_safe.c b/src/rrd_thread_safe.c index c06da05..bccea99 100644 --- a/src/rrd_thread_safe.c +++ b/src/rrd_thread_safe.c @@ -61,6 +61,7 @@ const char *rrd_strerror(int err) { ctx = rrd_get_context(); pthread_mutex_lock(&mtx); strncpy(ctx->lib_errstr, strerror(err), ctx->errlen); + ctx->lib_errstr[ctx->errlen]='\0'; pthread_mutex_unlock(&mtx); return ctx->lib_errstr; } diff --git a/src/rrd_thread_safe_nt.c b/src/rrd_thread_safe_nt.c index 8f68ea3..105507f 100644 --- a/src/rrd_thread_safe_nt.c +++ b/src/rrd_thread_safe_nt.c @@ -63,7 +63,8 @@ const char *rrd_strerror(int err) { EnterCriticalSection(&CriticalSection); strncpy(ctx->lib_errstr, strerror(err), ctx->errlen); - LeaveCriticalSection(&CriticalSection); + ctx->lib_errstr[ctx->errlen] = '\0'; + LeaveCriticalSection(&CriticalSection); return ctx->lib_errstr; } -- 2.30.2