C: fixed the printing of view informations from a DMS (fixes #114)

This commit is contained in:
mercierc
2021-08-05 11:31:24 +12:00
parent 88c8463ed7
commit f10e78ba3c

View File

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