chr1shr / voro

Voro++: a three-dimensional Voronoi cell library in C++
Other
154 stars 44 forks source link

0 size allocation #27

Open thovide opened 1 year ago

thovide commented 1 year ago

Hello,

in cell.cpp or cell3d.cpp (depending on the version), the instruction in bold leads to a call to new int[0] for the first iteration...

void voronoicell_neighbor_3d::memory_setup() { int i; mne=new int[current_vertex_order]; ne=new int[current_vertices]; *for(i=0;i<3;i++) mne[i]=new int[init_n_verticesi];* mne[3]=new int[init_3_vertices3]; for(i=4;i<current_vertex_order;i++) mne[i]=new int[init_n_vertices*i]; }

chr1shr commented 1 year ago

You're right, although I believe this is valid C++ and not a bug; see, for example, this Stack Overflow post.

Since there is an associated array called mep that is also allocated from i=0, it made sense to start the mne array from i=0 also. But it could likely be adjusted to i=1, since the zero entry should never get accessed.

thovide commented 1 year ago

Thanks for your answer. Actually, it is detected as a programming error by our automated quality checking tools. It's valid but bad 🙂.