Skip to content

RVec's swap is broken when RVec is adopting memory #10297

@eguiraud

Description

@eguiraud

std::swap seems to be working fine, but the custom swap implementation is broken. Self-contained reproducer by @ikabadzhov :

#include <ROOT/RVec.hxx>
#include <iostream>
#include <vector>

int main() {
  std::vector<int> v = {1};
  ROOT::RVecI rvec1(v.data(), v.size());
  ROOT::RVecI rvec2 = {2};
  swap(rvec1, rvec2);
  v[0] = 3;
  std::cout << rvec1 << '\n' << rvec2 << '\n';
}

This should print 2 and 3 but instead it prints 3 and 1.

Critically, this might be problematic for non-trivial usage of RVecs inside RDF code.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions