fmihpc / dccrg

Distributed cartesian cell-refinable grid
GNU Lesser General Public License v3.0
10 stars 10 forks source link

Patch for undefined behaviour (nullpointer reference). #26

Open ursg opened 1 year ago

ursg commented 1 year ago

For communication of empty (zero velocity blocks) Vlasiator cells, this was trying to do an AllGather of some empty arrays, but the actual Allgatherv call tried to acess &(temp_result[0]), which is technically a nullpointer dereference.

This probably wasn't causing any actual issue (because every sane compiler would optimize that away anyway), but was reported by GCC12's undefined behaviour sanitizer.

But anyway, if total_send_count is zero in the AllGather, the whole second stage of the communication can anyway be skipped, so that's how this is fixed now.

iljah commented 1 year ago

As commented above that code, this can also be fixed by using temp_result.data() instead of &(temp_result[0]) and by now c++11 is old enough for that :) But not even trying to send anything if there's nothing to send is probably even better...