From d1d9a1c9b583cf16bc159f67cf718ca3eaeb2ef7 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 21 Feb 2022 17:08:01 +0100 Subject: [PATCH] module_get_path_str: added comments Added comments to describe the behavior and ensure that this is correct and resulting string is properly null-terminated. --- src/module.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/module.c b/src/module.c index e6f303447..24c44ce84 100644 --- a/src/module.c +++ b/src/module.c @@ -334,10 +334,11 @@ bool module_get_path_str(struct module *mod, char *buf, size_t buflen) { if (sizeof(buf) + 1 + sizeof(cur_name) >= buflen) { return false; } + // move content of buf strlen(cur_name) right if (strlen(buf) > 0) { memmove(buf + strlen(cur_name) + 1, buf, strlen(buf) + 1); - buf[strlen(cur_name)] = '.'; - } else { + buf[strlen(cur_name)] = '.'; // and separate with '.' + } else { // rightmost (first written) element buf[strlen(cur_name)] = '\0'; } memcpy(buf, cur_name, strlen(cur_name));