Open szhorvat opened 1 month ago
Generally, for any OPTIONAL
vector, NULL
in R should be converted to a NULL
pointer in C. If this is not appropriate for some function, we should either make changes in the C core (ping me) or special-case it in the R interface.
Thanks for the analysis. I'm not sure I follow.
In this code, line 8689 (the one shown in CRAN's backtrace) checks sample
for being an R NULL
, and passes 0
(a C NULL
) in this case. Initialization of c_sample
may be redundant, but perhaps harmless?
Can this be replicated with Docker and https://github.com/cynkra/docker-images/pkgs/container/docker-images%2Frigraph-san ?
Fortunately, the fix is easy.
Fortunately, the fix is easy.
OK, I see. I didn't read the code carefully, just observed the behaviour.
The CI shows another unrelated error, hopefully similarly simple to fix.
https://github.com/igraph/rigraph/actions/runs/11601556838/job/32304898594#step:5:6515
So what happened was that as.numeric(NULL)
gives a zero-length vector, right? Which is precisely what we don't want here. I investigated this from the C core side, improved the error messages there, and when I saw zero-length vectors arriving, I assumed that R/igraph was intentionally passing those. Some C functions do interpret zero-length vectors as "nothing" but we're getting rid of that behaviour.
There are a lot of as.numeric()
in the R glue code ... a lot of the in-conversion in type-RR.yaml
just does as.numeric()
. Can we / should we replace this with a function that keeps NULL
as NULL
?
In C, generally, the convention is that a vector parameter can be omitted by passing NULL
for it. Not all parameters can be omitted. interfaces.yaml
should indicate which one can using OPTIONAL
. For some functions, it still doesn't use OPTIONAL
, but specifies NULL
as a default value.
When a parameter cannot be omitted, but the user still passes NULL
in C, the result is a crash. So blindly passing NULL
from R even for non-OPTIONAL
parameters is not okay.
This should be reviewed carefully, the glue code should be adapted. What I can do on the C side is to make sure that OPTIONAL
is always used when appropriate.
@ntamas What is the proper way to specify an optional vector parameter in functions.yaml
? Should it be OPTIONAL SOMETHING param=NULL
or is OPTIONAL SOMETHING param
enough? It would make sense to me that =NULL
shouldn't be necessary when OPTIONAL
is already given.
When passing an integer vector from R to C, the
NULL
value is converted to an empty vector.This is the ultimate cause of the UBSan failure that CRAN caught,
It's not just an UBSan warning.
sample_motifs()
is essentially broken, and likely so are some other functions that take optional integer vectors.In
rinterface.c
, I see this:It should produce a
NULL
pointer instead of an empty vector.This should be changed, but be aware that doing so may cause issues elsewhere, which will need to be fixed as well.
I don't see the null check in
types-RC.yaml
, so I assume it comes directly from Stimulus. Can you have a look, @Antonov548 ?