From a28380996702ab84c397aeec04ab1227dc8e9224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20=C3=9Acar?= Date: Tue, 17 Feb 2026 13:49:48 +0100 Subject: [PATCH] Fix UB for non-integer RTYPEs in comparator --- ChangeLog | 5 +++++ .../include/Rcpp/sugar/operators/Comparator_With_One_Value.h | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89d2dfe48..cdbbc632a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2026-02-17 Iñaki Ucar + + * inst/include/Rcpp/sugar/operators/Comparator_With_One_Value.h: Fix UB + for non-integer RTYPEs in comparator + 2026-01-23 Dirk Eddelbuettel * inst/include/Rcpp/DataFrame.h (nrow): Use R_nrow() with R >= 4.6.0 diff --git a/inst/include/Rcpp/sugar/operators/Comparator_With_One_Value.h b/inst/include/Rcpp/sugar/operators/Comparator_With_One_Value.h index 5d3caaa5b..365432c5f 100644 --- a/inst/include/Rcpp/sugar/operators/Comparator_With_One_Value.h +++ b/inst/include/Rcpp/sugar/operators/Comparator_With_One_Value.h @@ -2,7 +2,8 @@ // // LessThan.h: Rcpp R/C++ interface class library -- vector operators // -// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2026 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar // // This file is part of Rcpp. // @@ -56,7 +57,7 @@ class Comparator_With_One_Value : public ::Rcpp::VectorBase< LGLSXP, true, Compa inline int rhs_is_na(int i) const { return rhs ; } inline int rhs_is_not_na(int i) const { STORAGE x = lhs[i] ; - return Rcpp::traits::is_na(x) ? x : op( x, rhs ) ; + return Rcpp::traits::is_na(x) ? NA_INTEGER : op( x, rhs ) ; } } ;