diff --git a/src/obidms.c b/src/obidms.c index ad66431..e0a895e 100755 --- a/src/obidms.c +++ b/src/obidms.c @@ -1417,7 +1417,7 @@ char* obi_dms_formatted_infos(OBIDMS_p dms, bool detailed) char* view_name = NULL; char* tax_name = NULL; char* all_tax_dir_path = NULL; - int i; + int i, last_dot_pos; struct dirent* dp; Obiview_p view; @@ -1439,17 +1439,21 @@ char* obi_dms_formatted_infos(OBIDMS_p dms, bool detailed) if ((dp->d_name)[0] == '.') continue; i=0; - while ((dp->d_name)[i] != '.') + while (i < strlen(dp->d_name)) + { + if ((dp->d_name)[i] == '.') + last_dot_pos = i; i++; - view_name = (char*) malloc((i+1) * sizeof(char)); + } + view_name = (char*) malloc((last_dot_pos+1) * sizeof(char)); if (view_name == NULL) { obi_set_errno(OBI_MALLOC_ERROR); obidebug(1, "\nError allocating memory for a view name when getting formatted DMS infos: file %s", dp->d_name); return NULL; } - strncpy(view_name, dp->d_name, i); - view_name[i] = '\0'; + strncpy(view_name, dp->d_name, last_dot_pos); + view_name[last_dot_pos] = '\0'; view = obi_open_view(dms, view_name); if (view == NULL) {