Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc undefined behavior #380

Closed
ilikegitlab opened this issue Jan 6, 2025 · 1 comment
Closed

gcc undefined behavior #380

ilikegitlab opened this issue Jan 6, 2025 · 1 comment
Labels

Comments

@ilikegitlab
Copy link

ilikegitlab commented Jan 6, 2025

I am hitting a CRAN undefined behavior check. The simplest way to reproduce is:

library(units)
vec <- c(1)
set_units(1, "1") - set_units(vec[F], "%")

normally this runs fine, but within the CRAN "additional issues" gcc-UBSAN environment:

/usr/local/lib/R/site-library/Rcpp/include/Rcpp/vector/traits.h:49:62: runtime error: reference binding to misaligned address 0x000000000001 for type 'type', which requires 8 byte alignment
0x000000000001: note: pointer points here
<memory cannot be printed>
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/vector/Vector.h:340:62: runtime error: reference binding to misaligned address 0x000000000001 for type 'type', which requires 8 byte alignment
0x000000000001: note: pointer points here
<memory cannot be printed>
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/vector/traits.h:49:62: runtime error: reference binding to misaligned address 0x000000000001 for type 'type', which requires 8 byte alignment
0x000000000001: note: pointer points here
<memory cannot be printed>
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/vector/Vector.h:340:62: runtime error: reference binding to misaligned address 0x000000000001 for type 'type', which requires 8 byte alignment
0x000000000001: note: pointer points here
<memory cannot be printed>
 [1]
Warning messages:
1: In ud_convert(unclass(x), str1, str2) :
  subscript out of bounds (index 0 >= vector size 0)
2: In ud_convert(unclass(x), str1, str2) :
  subscript out of bounds (index 0 >= vector size 0)

Now I agree its a bit strange code (and I can work around this), but sometimes operations on large vectors are only done on some elements, and sometimes there are no elements left in the vector. So perhaps it is something that can or should be addressed in ud_convert (as the UB is caused by the Rcpp glue).

@Enchufa2 Enchufa2 added the bug label Jan 8, 2025
@Enchufa2
Copy link
Member

Enchufa2 commented Jan 8, 2025

Certainly, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants