diff --git a/src/obidmscolumn.c b/src/obidmscolumn.c index 5ce1f3c..8c4b63d 100644 --- a/src/obidmscolumn.c +++ b/src/obidmscolumn.c @@ -1820,8 +1820,8 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha if (elt_names_idx != NULL) return (index_t)(*elt_names_idx); - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError: could not find element name %s", element_name); + obi_set_errno(OBI_ELT_IDX_ERROR); + obidebug(0, "\nError: could not find element name %s", element_name); return OBIIdx_NA; } @@ -1860,7 +1860,7 @@ char* obi_get_elements_names(OBIDMS_column_p column) -int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb) +int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb, index_t elt_idx) { // Check if the column is read-only if (!(column->writable)) @@ -1878,6 +1878,14 @@ int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb) return -1; } + // Check that the element index is not greater than the number of elements per line of the column + if (elt_idx >= (column->header)->nb_elements_per_line) + { + obi_set_errno(OBI_ELT_IDX_ERROR); + obidebug(0, "\nError trying to set a value at an element index greater than the number of elements per line of the column"); + return -1; + } + // Check if the file needs to be enlarged while ((line_nb+1) > (column->header)->line_count) { @@ -1899,8 +1907,8 @@ int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb) { if ((line_nb+1) > ((column->header)->line_count)) { - obi_set_errno(OBICOL_UNKNOWN_ERROR); - obidebug(1, "\nError trying to get a value that is beyond the current number of lines of the column"); + obi_set_errno(OBI_LINE_IDX_ERROR); + obidebug(0, "\nError trying to get a value that is beyond the current number of lines of the column"); return -1; } return 0; diff --git a/src/obidmscolumn.h b/src/obidmscolumn.h index 6a8b1db..75d5cfc 100644 --- a/src/obidmscolumn.h +++ b/src/obidmscolumn.h @@ -406,7 +406,7 @@ char* obi_get_elements_names(OBIDMS_column_p column); * @since April 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb); +int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb, index_t elt_idx); /** diff --git a/src/obidmscolumn_bool.c b/src/obidmscolumn_bool.c index 4841c9b..9dba449 100644 --- a/src/obidmscolumn_bool.c +++ b/src/obidmscolumn_bool.c @@ -26,7 +26,7 @@ int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value) { - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; // Set the value diff --git a/src/obidmscolumn_char.c b/src/obidmscolumn_char.c index d17a698..aa0e67d 100644 --- a/src/obidmscolumn_char.c +++ b/src/obidmscolumn_char.c @@ -26,7 +26,7 @@ int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value) { - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; // Set the value diff --git a/src/obidmscolumn_float.c b/src/obidmscolumn_float.c index f0f94a7..84e2d9f 100644 --- a/src/obidmscolumn_float.c +++ b/src/obidmscolumn_float.c @@ -25,7 +25,7 @@ int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value) { - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; // Set the value diff --git a/src/obidmscolumn_idx.c b/src/obidmscolumn_idx.c index c1318f7..d28dcbe 100644 --- a/src/obidmscolumn_idx.c +++ b/src/obidmscolumn_idx.c @@ -26,7 +26,7 @@ int obi_column_set_index_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, index_t value) { - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; // Set the value diff --git a/src/obidmscolumn_int.c b/src/obidmscolumn_int.c index ec2ffbc..58ef9ed 100644 --- a/src/obidmscolumn_int.c +++ b/src/obidmscolumn_int.c @@ -25,7 +25,7 @@ int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value) { - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; // Set the value diff --git a/src/obidmscolumn_qual.c b/src/obidmscolumn_qual.c index 15b2039..7faf04e 100644 --- a/src/obidmscolumn_qual.c +++ b/src/obidmscolumn_qual.c @@ -59,7 +59,7 @@ int obi_column_set_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t line index_t idx; char* new_indexer_name; - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; if (value == OBIQual_int_NA) diff --git a/src/obidmscolumn_seq.c b/src/obidmscolumn_seq.c index 675b980..1066e4b 100644 --- a/src/obidmscolumn_seq.c +++ b/src/obidmscolumn_seq.c @@ -28,7 +28,7 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, { index_t idx; - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; if (value == OBISeq_NA) diff --git a/src/obidmscolumn_str.c b/src/obidmscolumn_str.c index 872f045..b466ac5 100644 --- a/src/obidmscolumn_str.c +++ b/src/obidmscolumn_str.c @@ -28,7 +28,7 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, { index_t idx; - if (obi_column_prepare_to_set_value(column, line_nb) < 0) + if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0) return -1; if (value == OBIStr_NA)