diff options
| -rw-r--r-- | src/data_management.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/data_management.c b/src/data_management.c index d4cf76c..ff2b3a9 100644 --- a/src/data_management.c +++ b/src/data_management.c @@ -21,6 +21,12 @@ inline struct list_node *create_node(char *fname, struct stat *ln_stat) { struct list_node *node = NULL; + size_t length = 0; +#ifdef DEBUGBUILD + static size_t count = 0; + + DBGTRC("DEBUG: Called fname '%s', attempting to create node #%lu\n", fname, ++count); +#endif if (fname == NULL || fname[0] == '\0') { LOGERR("ERROR: No valid filename given\n"); @@ -37,12 +43,17 @@ inline struct list_node *create_node(char *fname, struct stat *ln_stat) { return NULL; } + length = strnlen(fname,256); + if (length>255) { + LOGERR("ERROR: strnlen(\"%s\",256) == %lu, terminating with '\\0' at char[255].\n", + fname, length); + length = 255; + } node->next = NULL; - /* With strncpy and strict compiler options it complained. A file name - * can't be longer than 256 bytes, including the string terminating \0 - * byte at the end. As the code no longer's in the same file...*/ - memcpy(node->fname, fname, 255); - node->fname[255] = '\0'; + memcpy(node->fname, fname, length); + if (node->fname[255] != '\0') { + node->fname[255] = '\0'; + } memcpy(&(node->ln_stat), ln_stat, sizeof(struct stat)); return node; } |
