Opened 8 years ago

Closed 5 years ago

#10510 closed Bugs (fixed)

boost::uuids::uuid comparison error when used as key in std::map

Reported by: cosmin.szanto@… Owned by: Andy Tompkins
Milestone: Boost 1.59.0 Component: uuid
Version: Boost 1.56.0 Severity: Showstopper
Keywords: Cc:

Description

When using two almost equal uuids (e.g. the last character differs), a as a key of a std::map and b as parameter for the find function, the function will return that elements b is found in the map.

A simple test to reproduce the bug:

#include <map>
#include <iostream>

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/string_generator.hpp>

int main() {
  boost::uuids::string_generator gen;
  boost::uuids::uuid a = gen(std::string("145cfc95-8050-455a-8382-44ca57c1483b"));
  boost::uuids::uuid b = gen(std::string("145cfc95-8050-455a-8382-44ca57c1483c"));

  std::map<boost::uuids::uuid, int> elements;
  // Adding element 'a'
  elements.insert(std::make_pair(a, 1));
  // Element 'b' is found although is not added.
  std::cout << ((elements.find(b) != elements.end()) ? "Found." : "Not found.") << std::endl;
  return 0;
}

Change History (6)

comment:1 by hvemha@…, 8 years ago

This is a regression in 1.56.0 (the SIMD optimization of operator<). As a fix you can disable the optimization (define BOOST_UUID_NO_SIMD)

You can also have a look on this pull request: https://github.com/boostorg/uuid/pull/5

comment:2 by a.gronchi@…, 7 years ago

Version: Boost 1.56.0Boost 1.57.0

Bumping the ticket.

This is verified on 1.57.0, gcc version 4.9.2 (GCC), on Linux x86_64. The suggested workaround managed to get uuid::operator<() work correctly.

comment:3 by cosmin.szanto, 7 years ago

The bug is still reproducible with 1.58 and GCC version 5.1.0 on Linux x86_64.

comment:4 by Jonathan Wakely <jwakely.boost@…>, 7 years ago

This is fixed in 1.59.0

comment:5 by James E. King, III <jking@…>, 5 years ago

Version: Boost 1.57.0Boost 1.56.0

I cannot edit this defect and set the milestone to 1.59.0 - the earliest I could set it to is 1.61.0. Perhaps someone else can set it to the right thing and close it, once verified. Given it was seen first in 1.56.0 I changed the version field back to that.

comment:6 by Michael Caisse, 5 years ago

Milestone: To Be DeterminedBoost 1.59.0
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.