diff --git a/core/reactor_common.c b/core/reactor_common.c index 9fd04e356..d97b0a84d 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -153,25 +153,27 @@ const char* lf_reactor_full_name(self_base_t* self) { if (self->full_name != NULL) { return self->full_name; } - // First find the length of the name. - size_t len = 0; - len += strlen(self->name); + // First find the length of the full name. + size_t name_len = strlen(self->name); + size_t len = name_len; self_base_t* parent = self->parent; while (parent != NULL) { - len++; + len++; // For the dot. len += strlen(parent->name); parent = parent->parent; } self->full_name = (char*)lf_allocate(len + 1, sizeof(char), &self->allocations); + self->full_name[len] = '\0'; // Null terminate the string. - size_t location = len - strlen(self->name); - strncpy(&self->full_name[location], self->name, strlen(self->name) + 1); + size_t location = len - name_len; + memcpy(&self->full_name[location], self->name, name_len); parent = self->parent; while (parent != NULL) { location--; self->full_name[location] = '.'; - location -= strlen(parent->name); - strncpy(&self->full_name[location], parent->name, strlen(parent->name)); + size_t parent_len = strlen(parent->name); + location -= parent_len; + memcpy(&self->full_name[location], parent->name, parent_len); parent = parent->parent; } return self->full_name;