Skip to content

foverlaps segfault when y has 0 rows #7597

@nextpagesoft

Description

@nextpagesoft

Overview

Function fovelaps errors out with

 *** caught segfault ***
address 0xfffffffffffffffd, cause 'memory not mapped'

Traceback:
 1: foverlaps(x, y, by.x, by.y, )

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 1
R is aborting now ...

when y is a data.table with 0 rows. This happens in the official 1.18.0 version available on CRAN and the latest development version available on GitHub as of 15/01/2026.

Minimal reproducible example

library(data.table)
x <- data.table(Id = "A", StartX = 1L, EndX = 2L)
y <- data.table(Id = character(), StartY = integer(), EndY = integer())
by.x <- c("Id", "StartX", "EndX")
by.y <- c("Id", "StartY", "EndY")
setkeyv(y, by.y)
foverlaps(x, y, by.x, by.y)

Version 1.17.0 on the other hand produces:

> foverlaps(x, y, by.x, by.y)
       Id StartY  EndY StartX  EndX
   <char>  <int> <int>  <int> <int>
1:      A     NA    NA      1     2

Output of sessionInfo()

> sessionInfo()
R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.18.99

loaded via a namespace (and not attached):
[1] compiler_4.5.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions