Skip to content

Commit 5dfd491

Browse files
committed
Added a precondition
An empty range will mean a segfault when calling weights.back(), with the precondition, it will be more obvious.
1 parent 58a8eb0 commit 5dfd491

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Generator/include/CGAL/internal/Generic_random_point_generator.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
#ifndef CGAL_INTERNAL_GENERIC_RANDOM_POINT_GENERATOR_H
2222
#define CGAL_INTERNAL_GENERIC_RANDOM_POINT_GENERATOR_H
2323

24+
#include <CGAL/assertions.h>
25+
#include <CGAL/Iterator_range.h>
2426
#include <CGAL/generators.h>
2527
#include <CGAL/Random.h>
2628
#include <CGAL/property_map.h>
27-
#include <vector>
29+
2830
#include <boost/foreach.hpp>
29-
#include <CGAL/Iterator_range.h>
31+
32+
#include <vector>
3033

3134
namespace CGAL {
3235

@@ -56,6 +59,8 @@ class Generic_random_point_generator : public Random_generator_base<P>
5659
, random(rnd)
5760
{
5861
std::size_t input_size = input.size();
62+
CGAL_precondition(input_size > 0);
63+
5964
ids.reserve(input_size);
6065
weights.reserve(input_size);
6166

@@ -70,9 +75,11 @@ class Generic_random_point_generator : public Random_generator_base<P>
7075
total_weight += to_double( compute_weight(object) );
7176
weights.push_back(total_weight);
7277
}
78+
7379
//generate the first point
7480
generate_point();
7581
}
82+
7683
This& operator++()
7784
{
7885
generate_point();
@@ -84,6 +91,7 @@ class Generic_random_point_generator : public Random_generator_base<P>
8491
++(*this);
8592
return tmp;
8693
}
94+
8795
double sum_of_weights() const
8896
{
8997
if (weights.empty())

0 commit comments

Comments
 (0)