Added a check on the element when setting a value in a column

This commit is contained in:
Celine Mercier
2017-07-05 14:49:20 +02:00
parent 1d2996c6c0
commit f5e992abbf
10 changed files with 22 additions and 14 deletions

View File

@ -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;