diff --git a/cpp/include/cudf/column/column.hpp b/cpp/include/cudf/column/column.hpp index 4f42910856f..c02991051d9 100644 --- a/cpp/include/cudf/column/column.hpp +++ b/cpp/include/cudf/column/column.hpp @@ -109,6 +109,8 @@ class column { * @note This constructor is primarily intended for use in column factory * functions. * + * @throws cudf::logic_error if `size < 0` + * * @param[in] dtype The element type * @param[in] size The number of elements in the column * @param[in] data The column's data @@ -133,6 +135,7 @@ class column { _null_count{null_count}, _children{std::move(children)} { + CUDF_EXPECTS(size >= 0, "Column size cannot be negative."); } /** diff --git a/cpp/include/cudf/column/column_factories.hpp b/cpp/include/cudf/column/column_factories.hpp index 85f4deecb1d..725faeae626 100644 --- a/cpp/include/cudf/column/column_factories.hpp +++ b/cpp/include/cudf/column/column_factories.hpp @@ -62,6 +62,7 @@ std::unique_ptr make_empty_column(type_id id); * * @throws std::bad_alloc if device memory allocation fails * @throws cudf::logic_error if `type` is not a numeric type + * @throws cudf::logic_error if `size < 0` * * @param[in] type The desired numeric element type * @param[in] size The number of elements in the column @@ -119,6 +120,7 @@ std::unique_ptr make_numeric_column( * @note The column's null count is determined by the requested null mask `state`. * * @throws cudf::logic_error if `type` is not a `fixed_point` type. + * @throws cudf::logic_error if `size < 0` * * @param[in] type The desired `fixed_point` element type. * @param[in] size The number of elements in the column. @@ -176,6 +178,7 @@ std::unique_ptr make_fixed_point_column( * * @throws std::bad_alloc if device memory allocation fails * @throws cudf::logic_error if `type` is not a timestamp type + * @throws cudf::logic_error if `size < 0` * * @param[in] type The desired timestamp element type * @param[in] size The number of elements in the column @@ -234,6 +237,7 @@ std::unique_ptr make_timestamp_column( * * @throws std::bad_alloc if device memory allocation fails * @throws cudf::logic_error if `type` is not a duration type + * @throws cudf::logic_error if `size < 0` * * @param[in] type The desired duration element type * @param[in] size The number of elements in the column @@ -292,6 +296,7 @@ std::unique_ptr make_duration_column( * * @throws std::bad_alloc if device memory allocation fails * @throws cudf::logic_error if `type` is not a fixed width type + * @throws cudf::logic_error if `size < 0` * * @param[in] type The desired fixed width type * @param[in] size The number of elements in the column @@ -366,7 +371,7 @@ std::unique_ptr make_fixed_width_column( * @param[in] stream CUDA stream used for device memory operations and kernel launches. * @param[in] mr Device memory resource used for allocation of the column's `null_mask` and children * columns' device memory. - * @return Constructed strings column + * @return Constructed strings column */ std::unique_ptr make_strings_column( cudf::device_span const> strings, diff --git a/cpp/src/column/column_factories.cpp b/cpp/src/column/column_factories.cpp index 098e0d3e2cc..5f455e26e52 100644 --- a/cpp/src/column/column_factories.cpp +++ b/cpp/src/column/column_factories.cpp @@ -79,6 +79,7 @@ std::unique_ptr make_numeric_column(data_type type, { CUDF_FUNC_RANGE(); CUDF_EXPECTS(is_numeric(type), "Invalid, non-numeric type."); + CUDF_EXPECTS(size >= 0, "Column size cannot be negative."); return std::make_unique(type, size, @@ -97,6 +98,7 @@ std::unique_ptr make_fixed_point_column(data_type type, { CUDF_FUNC_RANGE(); CUDF_EXPECTS(is_fixed_point(type), "Invalid, non-fixed_point type."); + CUDF_EXPECTS(size >= 0, "Column size cannot be negative."); return std::make_unique(type, size, @@ -115,6 +117,7 @@ std::unique_ptr make_timestamp_column(data_type type, { CUDF_FUNC_RANGE(); CUDF_EXPECTS(is_timestamp(type), "Invalid, non-timestamp type."); + CUDF_EXPECTS(size >= 0, "Column size cannot be negative."); return std::make_unique(type, size, @@ -133,6 +136,7 @@ std::unique_ptr make_duration_column(data_type type, { CUDF_FUNC_RANGE(); CUDF_EXPECTS(is_duration(type), "Invalid, non-duration type."); + CUDF_EXPECTS(size >= 0, "Column size cannot be negative."); return std::make_unique(type, size, @@ -166,6 +170,7 @@ std::unique_ptr make_dictionary_from_scalar(scalar const& s, rmm::mr::device_memory_resource* mr) { if (size == 0) return make_empty_column(type_id::DICTIONARY32); + CUDF_EXPECTS(size >= 0, "Column size cannot be negative."); CUDF_EXPECTS(s.is_valid(stream), "cannot create a dictionary with a null key"); return make_dictionary_column( make_column_from_scalar(s, 1, stream, mr),