2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-02-08 22:58:25 +00:00

Use deterministic assignments for unique_id

Fixes qpdf/qpdf#419
This commit is contained in:
Dean Scarff 2020-04-04 12:48:25 +11:00 committed by Jay Berkenbilt
parent 2100b4ce15
commit c5c1a028cd

View File

@ -1,6 +1,7 @@
#include <qpdf/qpdf-config.h> // include first for large file support #include <qpdf/qpdf-config.h> // include first for large file support
#include <qpdf/QPDF.hh> #include <qpdf/QPDF.hh>
#include <atomic>
#include <vector> #include <vector>
#include <map> #include <map>
#include <algorithm> #include <algorithm>
@ -172,9 +173,8 @@ QPDF::QPDF() :
// Generate a unique ID. It just has to be unique among all QPDF // Generate a unique ID. It just has to be unique among all QPDF
// objects allocated throughout the lifetime of this running // objects allocated throughout the lifetime of this running
// application. // application.
m->unique_id = static_cast<unsigned long>(QUtil::get_current_time()); static std::atomic<unsigned long long> unique_id{0};
m->unique_id <<= 32; m->unique_id = unique_id.fetch_add(1ULL);
m->unique_id |= static_cast<unsigned long>(QUtil::random());
} }
QPDF::~QPDF() QPDF::~QPDF()