Commit c5c1a028cdd3cf345046c46963fb0fdacfb2c33c
Committed by
Jay Berkenbilt
1 parent
2100b4ce
Use deterministic assignments for unique_id
Fixes qpdf/qpdf#419
Showing
1 changed file
with
3 additions
and
3 deletions
libqpdf/QPDF.cc
| 1 | 1 | #include <qpdf/qpdf-config.h> // include first for large file support |
| 2 | 2 | #include <qpdf/QPDF.hh> |
| 3 | 3 | |
| 4 | +#include <atomic> | |
| 4 | 5 | #include <vector> |
| 5 | 6 | #include <map> |
| 6 | 7 | #include <algorithm> |
| ... | ... | @@ -172,9 +173,8 @@ QPDF::QPDF() : |
| 172 | 173 | // Generate a unique ID. It just has to be unique among all QPDF |
| 173 | 174 | // objects allocated throughout the lifetime of this running |
| 174 | 175 | // application. |
| 175 | - m->unique_id = static_cast<unsigned long>(QUtil::get_current_time()); | |
| 176 | - m->unique_id <<= 32; | |
| 177 | - m->unique_id |= static_cast<unsigned long>(QUtil::random()); | |
| 176 | + static std::atomic<unsigned long long> unique_id{0}; | |
| 177 | + m->unique_id = unique_id.fetch_add(1ULL); | |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | QPDF::~QPDF() | ... | ... |