Skip to content

Commit f1917e6

Browse files
committed
Added dimensions check [skip ci]
1 parent 5cdf935 commit f1917e6

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

include/pgvector/sparsevec.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <algorithm>
1010
#include <cstddef>
11+
#include <limits>
1112
#include <ostream>
1213
#include <span>
1314
#include <stdexcept>
@@ -33,7 +34,9 @@ class SparseVector {
3334

3435
/// Creates a sparse vector from a span.
3536
explicit SparseVector(std::span<const float> value) {
36-
// TODO throw exception
37+
if (value.size() > std::numeric_limits<int>::max()) {
38+
throw std::invalid_argument{"too many dimensions"};
39+
}
3740
dimensions_ = static_cast<int>(value.size());
3841
for (size_t i = 0; i < value.size(); i++) {
3942
float v = value[i];

0 commit comments

Comments
 (0)