diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 367610b34a3a..139fd31a9ac0 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -757,15 +757,16 @@ ktrstruct(name, data, datalen) size_t datalen; { struct ktr_request *req; - char *buf = NULL; - size_t buflen; + char *buf; + size_t buflen, namelen; - if (!data) + if (data == NULL) datalen = 0; - buflen = strlen(name) + 1 + datalen; + namelen = strlen(name) + 1; + buflen = namelen + datalen; buf = malloc(buflen, M_KTRACE, M_WAITOK); strcpy(buf, name); - bcopy(data, buf + strlen(name) + 1, datalen); + bcopy(data, buf + namelen, datalen); if ((req = ktr_getrequest(KTR_STRUCT)) == NULL) { free(buf, M_KTRACE); return;