Skip to content

Return null start for empty vectors#1462

Open
Enchufa2 wants to merge 1 commit intomasterfrom
fix/1461
Open

Return null start for empty vectors#1462
Enchufa2 wants to merge 1 commit intomasterfrom
fix/1461

Conversation

@Enchufa2
Copy link
Member

@Enchufa2 Enchufa2 commented Mar 26, 2026

Closes #1461. This happens because this returns 0x1 for empty vectors. The question is whether we should do the same check in here. I think we should.

Checklist

  • Code compiles correctly
  • R CMD check still passes all tests
  • Preferably, new tests were added which fail without the change
  • Document the changes by file in ChangeLog

@Enchufa2 Enchufa2 marked this pull request as ready for review March 26, 2026 16:20
@eddelbuettel
Copy link
Member

That looks great. I could turn on the big bad rev.dep machine but I am not even sure it's needed.

Copy link
Member

@eddelbuettel eddelbuettel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good -- test on entry is the way to go. There might as always be other code paths but this is at a minimum a start if not even a solid 'squash' of that bug.

@kevinushey
Copy link
Contributor

Are we sure std::copy() is going to accept a null pointer here? If we don't already have it, a unit test would be nice -- presumably ASAN / UBSAN builds of Rcpp with those tests would catch this issue.

I'm also fairly certain the actual issue here comes from this bit of cruel code.

https://github.com/wch/r-source/blob/6b5f72eebd9211766bd159e017a167385c93772e/src/include/Rinlinedfuns.h#L135-L142

@kevinushey
Copy link
Contributor

kevinushey commented Mar 26, 2026

Perhaps we can return dataptr(x) instead of NULL? With the appropriate casting.

Or, alternatively -- instead of using __ACCESSOR__ here, just use DATAPTR_RO, and cast to the appropriate type. But we're sort of cheating since DATAPTR_RO is supposed to only give read access to memory, and these might be writable...

I just hate the idea of this zero-length check becoming necessary. :|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UBSAN issue can arise when std::copy(ing) an Rcpp::NumericVector of length 0

3 participants