Added a check on the element when setting a value in a column
This commit is contained in:
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user