- EnterCriticalSection(&CriticalSection);
- strncpy(ctx->lib_errstr, strerror(err), ctx->errlen);
- LeaveCriticalSection(&CriticalSection);
+ ctx = rrd_get_context();
+
+ EnterCriticalSection(&CriticalSection);
+ strncpy(ctx->lib_errstr, strerror(err), sizeof(ctx->lib_errstr));
+ ctx->lib_errstr[sizeof(ctx->lib_errstr) - 1] = '\0';
+ LeaveCriticalSection(&CriticalSection);