krlmlr / wrswoR

A package with different implementations of weighted random sampling without replacement in R
https://krlmlr.github.io/wrswoR
18 stars 2 forks source link

Segfault on NA sample size #9

Open jonlachmann opened 3 years ago

jonlachmann commented 3 years ago

Hi, I am building a package using this package, and am very happy with it!

I found a bug that if for some reason NA is passed as the sample size to sample_int_expj (and possibly other functions), the R process will be terminated caused by a "memory not mapped" exception. It is of course reasonable that is it not realistic to sample NA items, but maybe it would be appropriate to check for this in some way?

Code reproducing the error is

sample_int_expj(5, NA, rep(1,5))
krlmlr commented 3 years ago

Thanks, we need to do better input checking here. Would you like to contribute?