add missing \0 to the end of several strncpy strings
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 16 Dec 2006 16:14:43 +0000 (16:14 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 16 Dec 2006 16:14:43 +0000 (16:14 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@938 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd_error.c
src/rrd_thread_safe.c
src/rrd_thread_safe_nt.c

index a102b1f..68fcc8e 100644 (file)
@@ -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) {
index c06da05..bccea99 100644 (file)
@@ -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;
 }
index 8f68ea3..105507f 100644 (file)
@@ -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;
 }