From 31726407a3c7e96619733c12f09589706515d7ae Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Fri, 24 Nov 2017 18:01:30 +0100 Subject: [PATCH] Taxonomy: fixed a bug where a pointer was not properly reallocated, and a bug where the merged list of taxids was not built correctly --- src/obidms_taxonomy.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/obidms_taxonomy.c b/src/obidms_taxonomy.c index 1ea50b7..060c06d 100644 --- a/src/obidms_taxonomy.c +++ b/src/obidms_taxonomy.c @@ -2210,7 +2210,7 @@ int read_delnodes_dmp(const char* taxdump, OBIDMS_taxonomy_p tax, int32_t** deln if (n == buffer_size) { buffer_size = buffer_size * 2; - (*delnodes_p) = (int32_t*) realloc(tax->merged_idx, sizeof(int32_t) * buffer_size); + (*delnodes_p) = (int32_t*) realloc(*delnodes_p, sizeof(int32_t) * buffer_size); if ((*delnodes_p) == NULL) { obi_set_errno(OBI_MALLOC_ERROR); @@ -2378,7 +2378,7 @@ int read_merged_dmp(const char* taxdump, OBIDMS_taxonomy_p tax, int32_t* delnode // and the deleted taxids with no current reference. An element of the list is composed of the taxid, and the index // of the taxon in the taxa structure, or -1 for deleted taxids. // Creating the merged list requires to merge the 3 ordered lists into one. - while (((nT < (tax->taxa)->count) && ((tax->taxa)->taxon[nT].taxid < old_taxid)) && ((nD >= 0) && (delnodes[nD] < old_taxid))) + while (((nT < (tax->taxa)->count) && ((tax->taxa)->taxon[nT].taxid < old_taxid)) || ((nD >= 0) && (delnodes[nD] < old_taxid))) { if ((tax->taxa)->taxon[nT].taxid < delnodes[nD]) { // Add element from taxa list @@ -2399,6 +2399,7 @@ int read_merged_dmp(const char* taxdump, OBIDMS_taxonomy_p tax, int32_t* delnode (tax->merged_idx)->merged[n].taxid = (tax->taxa)->taxon[nT].taxid; (tax->merged_idx)->merged[n].idx = nT; + nT++; n++; } @@ -2421,6 +2422,7 @@ int read_merged_dmp(const char* taxdump, OBIDMS_taxonomy_p tax, int32_t* delnode (tax->merged_idx)->merged[n].taxid = delnodes[nD]; (tax->merged_idx)->merged[n].idx = -1; // The index to tag deleted taxids is -1 + nD--; n++; } @@ -2448,6 +2450,7 @@ int read_merged_dmp(const char* taxdump, OBIDMS_taxonomy_p tax, int32_t* delnode // Store the old taxid with the index (tax->merged_idx)->merged[n].taxid = old_taxid; (tax->merged_idx)->merged[n].idx = t->idx; + n++; }