| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/plugin/quuid.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | template <class Char, class Integral> | - | ||||||||||||
| 8 | void _q_toHex(Char *&dst, Integral value) | - | ||||||||||||
| 9 | { | - | ||||||||||||
| 10 | value = qToBigEndian(value); | - | ||||||||||||
| 11 | - | |||||||||||||
| 12 | const char* p = reinterpret_cast<const char*>(&value); | - | ||||||||||||
| 13 | - | |||||||||||||
| 14 | for (uint i = 0; i < sizeof(Integral); ++i, dst += 2) { | - | ||||||||||||
| 15 | dst[0] = Char(QtMiscUtils::toHexLower((p[i] >> 4) & 0xf)); | - | ||||||||||||
| 16 | dst[1] = Char(QtMiscUtils::toHexLower(p[i] & 0xf)); | - | ||||||||||||
| 17 | } | - | ||||||||||||
| 18 | } | - | ||||||||||||
| 19 | - | |||||||||||||
| 20 | template <class Char, class Integral> | - | ||||||||||||
| 21 | bool _q_fromHex(const Char *&src, Integral &value) | - | ||||||||||||
| 22 | { | - | ||||||||||||
| 23 | value = 0; | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | for (uint i = 0; i < sizeof(Integral) * 2; ++i) { | - | ||||||||||||
| 26 | uint ch = *src++; | - | ||||||||||||
| 27 | int tmp = QtMiscUtils::fromHex(ch); | - | ||||||||||||
| 28 | if (tmp == -1) | - | ||||||||||||
| 29 | return false; | - | ||||||||||||
| 30 | - | |||||||||||||
| 31 | value = value * 16 + tmp; | - | ||||||||||||
| 32 | } | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | return true; | - | ||||||||||||
| 35 | } | - | ||||||||||||
| 36 | - | |||||||||||||
| 37 | template <class Char> | - | ||||||||||||
| 38 | void _q_uuidToHex(Char *&dst, const uint &d1, const ushort &d2, const ushort &d3, const uchar (&d4)[8]) | - | ||||||||||||
| 39 | { | - | ||||||||||||
| 40 | *dst++ = Char('{'); | - | ||||||||||||
| 41 | _q_toHex(dst, d1); | - | ||||||||||||
| 42 | *dst++ = Char('-'); | - | ||||||||||||
| 43 | _q_toHex(dst, d2); | - | ||||||||||||
| 44 | *dst++ = Char('-'); | - | ||||||||||||
| 45 | _q_toHex(dst, d3); | - | ||||||||||||
| 46 | *dst++ = Char('-'); | - | ||||||||||||
| 47 | for (int i = 0; i < 2; i++) | - | ||||||||||||
| 48 | _q_toHex(dst, d4[i]); | - | ||||||||||||
| 49 | *dst++ = Char('-'); | - | ||||||||||||
| 50 | for (int i = 2; i < 8; i++) | - | ||||||||||||
| 51 | _q_toHex(dst, d4[i]); | - | ||||||||||||
| 52 | *dst = Char('}'); | - | ||||||||||||
| 53 | } | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | template <class Char> | - | ||||||||||||
| 56 | bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar (&d4)[8]) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | if (*src == Char('{')) | - | ||||||||||||
| 59 | src++; | - | ||||||||||||
| 60 | if (!_q_fromHex(src, d1) | - | ||||||||||||
| 61 | || *src++ != Char('-') | - | ||||||||||||
| 62 | || !_q_fromHex(src, d2) | - | ||||||||||||
| 63 | || *src++ != Char('-') | - | ||||||||||||
| 64 | || !_q_fromHex(src, d3) | - | ||||||||||||
| 65 | || *src++ != Char('-') | - | ||||||||||||
| 66 | || !_q_fromHex(src, d4[0]) | - | ||||||||||||
| 67 | || !_q_fromHex(src, d4[1]) | - | ||||||||||||
| 68 | || *src++ != Char('-') | - | ||||||||||||
| 69 | || !_q_fromHex(src, d4[2]) | - | ||||||||||||
| 70 | || !_q_fromHex(src, d4[3]) | - | ||||||||||||
| 71 | || !_q_fromHex(src, d4[4]) | - | ||||||||||||
| 72 | || !_q_fromHex(src, d4[5]) | - | ||||||||||||
| 73 | || !_q_fromHex(src, d4[6]) | - | ||||||||||||
| 74 | || !_q_fromHex(src, d4[7])) { | - | ||||||||||||
| 75 | return false; | - | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | return true; | - | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | - | |||||||||||||
| 82 | static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version) | - | ||||||||||||
| 83 | { | - | ||||||||||||
| 84 | QByteArray hashResult; | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | - | |||||||||||||
| 87 | { | - | ||||||||||||
| 88 | QCryptographicHash hash(algorithm); | - | ||||||||||||
| 89 | hash.addData(ns.toRfc4122()); | - | ||||||||||||
| 90 | hash.addData(baseData); | - | ||||||||||||
| 91 | hashResult = hash.result(); | - | ||||||||||||
| 92 | } | - | ||||||||||||
| 93 | hashResult.resize(16); | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | QUuid result = QUuid::fromRfc4122(hashResult); | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | result.data3 &= 0x0FFF; | - | ||||||||||||
| 98 | result.data3 |= (version << 12); | - | ||||||||||||
| 99 | result.data4[0] &= 0x3F; | - | ||||||||||||
| 100 | result.data4[0] |= 0x80; | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | return result; | - | ||||||||||||
| 103 | } | - | ||||||||||||
| 104 | QUuid::QUuid(const QString &text) | - | ||||||||||||
| 105 | { | - | ||||||||||||
| 106 | if (text.length() < 36) { | - | ||||||||||||
| 107 | *this = QUuid(); | - | ||||||||||||
| 108 | return; | - | ||||||||||||
| 109 | } | - | ||||||||||||
| 110 | - | |||||||||||||
| 111 | const ushort *data = reinterpret_cast<const ushort *>(text.unicode()); | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | if (*data == '{' && text.length() < 37) { | - | ||||||||||||
| 114 | *this = QUuid(); | - | ||||||||||||
| 115 | return; | - | ||||||||||||
| 116 | } | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | if (!_q_uuidFromHex(data, data1, data2, data3, data4)) { | - | ||||||||||||
| 119 | *this = QUuid(); | - | ||||||||||||
| 120 | return; | - | ||||||||||||
| 121 | } | - | ||||||||||||
| 122 | } | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | - | |||||||||||||
| 125 | - | |||||||||||||
| 126 | - | |||||||||||||
| 127 | QUuid::QUuid(const char *text) | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | if (!text) { | - | ||||||||||||
| 130 | *this = QUuid(); | - | ||||||||||||
| 131 | return; | - | ||||||||||||
| 132 | } | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | if (!_q_uuidFromHex(text, data1, data2, data3, data4)) { | - | ||||||||||||
| 135 | *this = QUuid(); | - | ||||||||||||
| 136 | return; | - | ||||||||||||
| 137 | } | - | ||||||||||||
| 138 | } | - | ||||||||||||
| 139 | QUuid::QUuid(const QByteArray &text) | - | ||||||||||||
| 140 | { | - | ||||||||||||
| 141 | if (text.length() < 36) { | - | ||||||||||||
| 142 | *this = QUuid(); | - | ||||||||||||
| 143 | return; | - | ||||||||||||
| 144 | } | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | const char *data = text.constData(); | - | ||||||||||||
| 147 | - | |||||||||||||
| 148 | if (*data == '{' && text.length() < 37) { | - | ||||||||||||
| 149 | *this = QUuid(); | - | ||||||||||||
| 150 | return; | - | ||||||||||||
| 151 | } | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | if (!_q_uuidFromHex(data, data1, data2, data3, data4)) { | - | ||||||||||||
| 154 | *this = QUuid(); | - | ||||||||||||
| 155 | return; | - | ||||||||||||
| 156 | } | - | ||||||||||||
| 157 | } | - | ||||||||||||
| 158 | QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData) | - | ||||||||||||
| 159 | { | - | ||||||||||||
| 160 | return createFromName(ns, baseData, QCryptographicHash::Md5, 3); | - | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData) | - | ||||||||||||
| 164 | { | - | ||||||||||||
| 165 | return createFromName(ns, baseData, QCryptographicHash::Sha1, 5); | - | ||||||||||||
| 166 | } | - | ||||||||||||
| 167 | QUuid QUuid::fromRfc4122(const QByteArray &bytes) | - | ||||||||||||
| 168 | { | - | ||||||||||||
| 169 | if (bytes.isEmpty() || bytes.length() != 16) | - | ||||||||||||
| 170 | return QUuid(); | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | uint d1; | - | ||||||||||||
| 173 | ushort d2, d3; | - | ||||||||||||
| 174 | uchar d4[8]; | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | const uchar *data = reinterpret_cast<const uchar *>(bytes.constData()); | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | d1 = qFromBigEndian<quint32>(data); | - | ||||||||||||
| 179 | data += sizeof(quint32); | - | ||||||||||||
| 180 | d2 = qFromBigEndian<quint16>(data); | - | ||||||||||||
| 181 | data += sizeof(quint16); | - | ||||||||||||
| 182 | d3 = qFromBigEndian<quint16>(data); | - | ||||||||||||
| 183 | data += sizeof(quint16); | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | for (int i = 0; i < 8; ++i) { | - | ||||||||||||
| 186 | d4[i] = *(data); | - | ||||||||||||
| 187 | data++; | - | ||||||||||||
| 188 | } | - | ||||||||||||
| 189 | - | |||||||||||||
| 190 | return QUuid(d1, d2, d3, d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7]); | - | ||||||||||||
| 191 | } | - | ||||||||||||
| 192 | QString QUuid::toString() const | - | ||||||||||||
| 193 | { | - | ||||||||||||
| 194 | QString result(38, Qt::Uninitialized); | - | ||||||||||||
| 195 | ushort *data = (ushort *)result.data(); | - | ||||||||||||
| 196 | - | |||||||||||||
| 197 | _q_uuidToHex(data, data1, data2, data3, data4); | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | return result; | - | ||||||||||||
| 200 | } | - | ||||||||||||
| 201 | QByteArray QUuid::toByteArray() const | - | ||||||||||||
| 202 | { | - | ||||||||||||
| 203 | QByteArray result(38, Qt::Uninitialized); | - | ||||||||||||
| 204 | char *data = result.data(); | - | ||||||||||||
| 205 | - | |||||||||||||
| 206 | _q_uuidToHex(data, data1, data2, data3, data4); | - | ||||||||||||
| 207 | - | |||||||||||||
| 208 | return result; | - | ||||||||||||
| 209 | } | - | ||||||||||||
| 210 | QByteArray QUuid::toRfc4122() const | - | ||||||||||||
| 211 | { | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | QByteArray bytes(16, Qt::Uninitialized); | - | ||||||||||||
| 214 | uchar *data = reinterpret_cast<uchar*>(bytes.data()); | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | qToBigEndian(data1, data); | - | ||||||||||||
| 217 | data += sizeof(quint32); | - | ||||||||||||
| 218 | qToBigEndian(data2, data); | - | ||||||||||||
| 219 | data += sizeof(quint16); | - | ||||||||||||
| 220 | qToBigEndian(data3, data); | - | ||||||||||||
| 221 | data += sizeof(quint16); | - | ||||||||||||
| 222 | - | |||||||||||||
| 223 | for (int i = 0; i < 8; ++i) { | - | ||||||||||||
| 224 | *(data) = data4[i]; | - | ||||||||||||
| 225 | data++; | - | ||||||||||||
| 226 | } | - | ||||||||||||
| 227 | - | |||||||||||||
| 228 | return bytes; | - | ||||||||||||
| 229 | } | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | - | |||||||||||||
| 232 | - | |||||||||||||
| 233 | - | |||||||||||||
| 234 | - | |||||||||||||
| 235 | - | |||||||||||||
| 236 | QDataStream &operator<<(QDataStream &s, const QUuid &id) | - | ||||||||||||
| 237 | { | - | ||||||||||||
| 238 | QByteArray bytes; | - | ||||||||||||
| 239 | if (s.byteOrder() == QDataStream::BigEndian) { | - | ||||||||||||
| 240 | bytes = id.toRfc4122(); | - | ||||||||||||
| 241 | } else { | - | ||||||||||||
| 242 | - | |||||||||||||
| 243 | bytes = QByteArray(16, Qt::Uninitialized); | - | ||||||||||||
| 244 | uchar *data = reinterpret_cast<uchar*>(bytes.data()); | - | ||||||||||||
| 245 | - | |||||||||||||
| 246 | qToLittleEndian(id.data1, data); | - | ||||||||||||
| 247 | data += sizeof(quint32); | - | ||||||||||||
| 248 | qToLittleEndian(id.data2, data); | - | ||||||||||||
| 249 | data += sizeof(quint16); | - | ||||||||||||
| 250 | qToLittleEndian(id.data3, data); | - | ||||||||||||
| 251 | data += sizeof(quint16); | - | ||||||||||||
| 252 | - | |||||||||||||
| 253 | for (int i = 0; i < 8; ++i) { | - | ||||||||||||
| 254 | *(data) = id.data4[i]; | - | ||||||||||||
| 255 | data++; | - | ||||||||||||
| 256 | } | - | ||||||||||||
| 257 | } | - | ||||||||||||
| 258 | - | |||||||||||||
| 259 | if (s.writeRawData(bytes.data(), 16) != 16) { | - | ||||||||||||
| 260 | s.setStatus(QDataStream::WriteFailed); | - | ||||||||||||
| 261 | } | - | ||||||||||||
| 262 | return s; | - | ||||||||||||
| 263 | } | - | ||||||||||||
| 264 | - | |||||||||||||
| 265 | - | |||||||||||||
| 266 | - | |||||||||||||
| 267 | - | |||||||||||||
| 268 | - | |||||||||||||
| 269 | QDataStream &operator>>(QDataStream &s, QUuid &id) | - | ||||||||||||
| 270 | { | - | ||||||||||||
| 271 | QByteArray bytes(16, Qt::Uninitialized); | - | ||||||||||||
| 272 | if (s.readRawData(bytes.data(), 16) != 16) { | - | ||||||||||||
| 273 | s.setStatus(QDataStream::ReadPastEnd); | - | ||||||||||||
| 274 | return s; | - | ||||||||||||
| 275 | } | - | ||||||||||||
| 276 | - | |||||||||||||
| 277 | if (s.byteOrder() == QDataStream::BigEndian) { | - | ||||||||||||
| 278 | id = QUuid::fromRfc4122(bytes); | - | ||||||||||||
| 279 | } else { | - | ||||||||||||
| 280 | const uchar *data = reinterpret_cast<const uchar *>(bytes.constData()); | - | ||||||||||||
| 281 | - | |||||||||||||
| 282 | id.data1 = qFromLittleEndian<quint32>(data); | - | ||||||||||||
| 283 | data += sizeof(quint32); | - | ||||||||||||
| 284 | id.data2 = qFromLittleEndian<quint16>(data); | - | ||||||||||||
| 285 | data += sizeof(quint16); | - | ||||||||||||
| 286 | id.data3 = qFromLittleEndian<quint16>(data); | - | ||||||||||||
| 287 | data += sizeof(quint16); | - | ||||||||||||
| 288 | - | |||||||||||||
| 289 | for (int i = 0; i < 8; ++i) { | - | ||||||||||||
| 290 | id.data4[i] = *(data); | - | ||||||||||||
| 291 | data++; | - | ||||||||||||
| 292 | } | - | ||||||||||||
| 293 | } | - | ||||||||||||
| 294 | - | |||||||||||||
| 295 | return s; | - | ||||||||||||
| 296 | } | - | ||||||||||||
| 297 | - | |||||||||||||
| 298 | - | |||||||||||||
| 299 | - | |||||||||||||
| 300 | - | |||||||||||||
| 301 | - | |||||||||||||
| 302 | - | |||||||||||||
| 303 | bool QUuid::isNull() const noexcept | - | ||||||||||||
| 304 | { | - | ||||||||||||
| 305 | return executed 58 times by 2 tests: data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;Executed by: 
 executed 58 times by 2 tests:  return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;Executed by: 
 | 58 | ||||||||||||
| 306 | data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && executed 58 times by 2 tests:  return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;Executed by: 
 | 58 | ||||||||||||
| 307 | data1 == 0 && data2 == 0 && data3 == 0; executed 58 times by 2 tests:  return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;Executed by: 
 | 58 | ||||||||||||
| 308 | } | - | ||||||||||||
| 309 | QUuid::Variant QUuid::variant() const noexcept | - | ||||||||||||
| 310 | { | - | ||||||||||||
| 311 | if (isNull() 
 | 12-35 | ||||||||||||
| 312 | return executed 12 times by 1 test: VarUnknown; return VarUnknown;Executed by: 
 executed 12 times by 1 test:  return VarUnknown;Executed by: 
 | 12 | ||||||||||||
| 313 | - | |||||||||||||
| 314 | if (( 
 
 executed 2 times by 1 test: NCS; return NCS;Executed by: 
 executed 2 times by 1 test:  return NCS;Executed by: 
 | 2-33 | ||||||||||||
| 315 | else if (( 
 
 executed 33 times by 1 test: DCE; return DCE;Executed by: 
 executed 33 times by 1 test:  return DCE;Executed by: 
 | 0-33 | ||||||||||||
| 316 | else if (( 
 
 never executed: Microsoft; return Microsoft;never executed:  return Microsoft; | 0 | ||||||||||||
| 317 | else if (( 
 
 never executed: Reserved; return Reserved;never executed:  return Reserved; | 0 | ||||||||||||
| 318 | return never executed: VarUnknown; return VarUnknown;never executed:  return VarUnknown; | 0 | ||||||||||||
| 319 | } | - | ||||||||||||
| 320 | QUuid::Version QUuid::version() const noexcept | - | ||||||||||||
| 321 | { | - | ||||||||||||
| 322 | - | |||||||||||||
| 323 | Version ver = (Version)(data3>>12); | - | ||||||||||||
| 324 | if (isNull() 
 | 0-4 | ||||||||||||
| 325 | || ( 
 
 | 1-3 | ||||||||||||
| 326 | || ver < Time 
 | 0-3 | ||||||||||||
| 327 | || ver > Sha1 
 | 0-3 | ||||||||||||
| 328 | return executed 1 time by 1 test: VerUnknown; return VerUnknown;Executed by: 
 executed 1 time by 1 test:  return VerUnknown;Executed by: 
 | 1 | ||||||||||||
| 329 | return executed 3 times by 1 test: ver; return ver;Executed by: 
 executed 3 times by 1 test:  return ver;Executed by: 
 | 3 | ||||||||||||
| 330 | } | - | ||||||||||||
| 331 | bool QUuid::operator<(const QUuid &other) const noexcept | - | ||||||||||||
| 332 | { | - | ||||||||||||
| 333 | if (variant() != other.variant() 
 | 4-12 | ||||||||||||
| 334 | return executed 4 times by 1 test: variant() < other.variant(); return variant() < other.variant();Executed by: 
 executed 4 times by 1 test:  return variant() < other.variant();Executed by: 
 | 4 | ||||||||||||
| 335 | - | |||||||||||||
| 336 | - | |||||||||||||
| 337 | if (data1!=other.data1 
 executed 8 times by 1 test: (data1<other.data1); return (data1<other.data1);Executed by: 
 executed 8 times by 1 test: ; return (data1<other.data1);Executed by: 
 | 4-8 | ||||||||||||
| 338 | if (data2!=other.data2 
 never executed: (data2<other.data2); return (data2<other.data2);never executed: ; return (data2<other.data2); | 0-4 | ||||||||||||
| 339 | if (data3!=other.data3 
 never executed: (data3<other.data3); return (data3<other.data3);never executed: ; return (data3<other.data3); | 0-4 | ||||||||||||
| 340 | for (int n = 0; n < 8 
 | 4-32 | ||||||||||||
| 341 | if (data4[n]!=other.data4[n] 
 never executed: (data4[n]<other.data4[n]); return (data4[n]<other.data4[n]);never executed: ; return (data4[n]<other.data4[n]); | 0-32 | ||||||||||||
| 342 | } executed 32 times by 1 test:  end of blockExecuted by: 
 | 32 | ||||||||||||
| 343 | - | |||||||||||||
| 344 | return executed 4 times by 1 test: false; return false;Executed by: 
 executed 4 times by 1 test:  return false;Executed by: 
 | 4 | ||||||||||||
| 345 | } | - | ||||||||||||
| 346 | bool QUuid::operator>(const QUuid &other) const noexcept | - | ||||||||||||
| 347 | { | - | ||||||||||||
| 348 | return executed 3 times by 1 test: other < *this; return other < *this;Executed by: 
 executed 3 times by 1 test:  return other < *this;Executed by: 
 | 3 | ||||||||||||
| 349 | } | - | ||||||||||||
| 350 | - | |||||||||||||
| 351 | - | |||||||||||||
| 352 | - | |||||||||||||
| 353 | - | |||||||||||||
| 354 | - | |||||||||||||
| 355 | namespace { namespace Q_QGS_devUrandomStorage { typedef QThreadStorage<QFile *> Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QThreadStorage<QFile *>, Q_QGS_devUrandomStorage::innerFunction, Q_QGS_devUrandomStorage::guard> devUrandomStorage;; | - | ||||||||||||
| 356 | - | |||||||||||||
| 357 | - | |||||||||||||
| 358 | QUuid QUuid::createUuid() | - | ||||||||||||
| 359 | { | - | ||||||||||||
| 360 | QUuid result; | - | ||||||||||||
| 361 | uint *data = &(result.data1); | - | ||||||||||||
| 362 | - | |||||||||||||
| 363 | - | |||||||||||||
| 364 | QFile *devUrandom; | - | ||||||||||||
| 365 | - | |||||||||||||
| 366 | devUrandom = devUrandomStorage()->localData(); | - | ||||||||||||
| 367 | if (!devUrandom) { | - | ||||||||||||
| 368 | devUrandom = new QFile(QLatin1String("/dev/urandom")); | - | ||||||||||||
| 369 | devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered); | - | ||||||||||||
| 370 | devUrandomStorage()->setLocalData(devUrandom); | - | ||||||||||||
| 371 | } | - | ||||||||||||
| 372 | - | |||||||||||||
| 373 | - | |||||||||||||
| 374 | - | |||||||||||||
| 375 | - | |||||||||||||
| 376 | - | |||||||||||||
| 377 | enum { AmountToRead = 4 * sizeof(uint) }; | - | ||||||||||||
| 378 | if (devUrandom->isOpen() | - | ||||||||||||
| 379 | && devUrandom->read((char *) data, AmountToRead) == AmountToRead) { | - | ||||||||||||
| 380 | - | |||||||||||||
| 381 | ; | - | ||||||||||||
| 382 | } else | - | ||||||||||||
| 383 | - | |||||||||||||
| 384 | { | - | ||||||||||||
| 385 | static const int intbits = sizeof(int)*8; | - | ||||||||||||
| 386 | static int randbits = 0; | - | ||||||||||||
| 387 | if (!randbits) { | - | ||||||||||||
| 388 | int r = 0; | - | ||||||||||||
| 389 | int max = 2147483647; | - | ||||||||||||
| 390 | do { ++r; } while ((max=max>>1)); | - | ||||||||||||
| 391 | randbits = r; | - | ||||||||||||
| 392 | } | - | ||||||||||||
| 393 | - | |||||||||||||
| 394 | - | |||||||||||||
| 395 | - | |||||||||||||
| 396 | - | |||||||||||||
| 397 | - | |||||||||||||
| 398 | static QThreadStorage<int *> uuidseed; | - | ||||||||||||
| 399 | if (!uuidseed.hasLocalData()) | - | ||||||||||||
| 400 | { | - | ||||||||||||
| 401 | int *pseed = new int; | - | ||||||||||||
| 402 | static QBasicAtomicInt serial = { 2 }; | - | ||||||||||||
| 403 | qsrand(*pseed = QDateTime::currentDateTimeUtc().toTime_t() | - | ||||||||||||
| 404 | + quintptr(&pseed) | - | ||||||||||||
| 405 | + serial.fetchAndAddRelaxed(1)); | - | ||||||||||||
| 406 | uuidseed.setLocalData(pseed); | - | ||||||||||||
| 407 | } | - | ||||||||||||
| 408 | - | |||||||||||||
| 409 | - | |||||||||||||
| 410 | - | |||||||||||||
| 411 | - | |||||||||||||
| 412 | - | |||||||||||||
| 413 | - | |||||||||||||
| 414 | - | |||||||||||||
| 415 | int chunks = 16 / sizeof(uint); | - | ||||||||||||
| 416 | while (chunks--) { | - | ||||||||||||
| 417 | uint randNumber = 0; | - | ||||||||||||
| 418 | for (int filled = 0; filled < intbits; filled += randbits) | - | ||||||||||||
| 419 | randNumber |= qrand()<<filled; | - | ||||||||||||
| 420 | *(data+chunks) = randNumber; | - | ||||||||||||
| 421 | } | - | ||||||||||||
| 422 | } | - | ||||||||||||
| 423 | - | |||||||||||||
| 424 | result.data4[0] = (result.data4[0] & 0x3F) | 0x80; | - | ||||||||||||
| 425 | result.data3 = (result.data3 & 0x0FFF) | 0x4000; | - | ||||||||||||
| 426 | - | |||||||||||||
| 427 | return result; | - | ||||||||||||
| 428 | } | - | ||||||||||||
| 429 | QDebug operator<<(QDebug dbg, const QUuid &id) | - | ||||||||||||
| 430 | { | - | ||||||||||||
| 431 | QDebugStateSaver saver(dbg); | - | ||||||||||||
| 432 | dbg.nospace() << "QUuid(" << id.toString() << ')'; | - | ||||||||||||
| 433 | return dbg; | - | ||||||||||||
| 434 | } | - | ||||||||||||
| 435 | - | |||||||||||||
| 436 | - | |||||||||||||
| 437 | - | |||||||||||||
| 438 | - | |||||||||||||
| 439 | - | |||||||||||||
| 440 | - | |||||||||||||
| 441 | - | |||||||||||||
| 442 | uint qHash(const QUuid &uuid, uint seed) noexcept | - | ||||||||||||
| 443 | { | - | ||||||||||||
| 444 | return executed 3 times by 1 test: uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;Executed by: 
 executed 3 times by 1 test:  return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;Executed by: 
 | 3 | ||||||||||||
| 445 | ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) executed 3 times by 1 test:  return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;Executed by: 
 | 3 | ||||||||||||
| 446 | ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) executed 3 times by 1 test:  return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;Executed by: 
 | 3 | ||||||||||||
| 447 | ^ seed; executed 3 times by 1 test:  return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;Executed by: 
 | 3 | ||||||||||||
| 448 | } | - | ||||||||||||
| 449 | - | |||||||||||||
| 450 | - | |||||||||||||
| 451 | - | |||||||||||||
| Switch to Source code | Preprocessed file |