| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimemagicrule.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | static const char magicRuleTypes_string[] = | - | ||||||||||||||||||||||||
| 9 | "invalid\0" | - | ||||||||||||||||||||||||
| 10 | "string\0" | - | ||||||||||||||||||||||||
| 11 | "host16\0" | - | ||||||||||||||||||||||||
| 12 | "host32\0" | - | ||||||||||||||||||||||||
| 13 | "big16\0" | - | ||||||||||||||||||||||||
| 14 | "big32\0" | - | ||||||||||||||||||||||||
| 15 | "little16\0" | - | ||||||||||||||||||||||||
| 16 | "little32\0" | - | ||||||||||||||||||||||||
| 17 | "byte\0" | - | ||||||||||||||||||||||||
| 18 | "\0"; | - | ||||||||||||||||||||||||
| 19 | - | |||||||||||||||||||||||||
| 20 | static const int magicRuleTypes_indices[] = { | - | ||||||||||||||||||||||||
| 21 | 0, 8, 15, 22, 29, 35, 41, 50, 59, 65, 0 | - | ||||||||||||||||||||||||
| 22 | }; | - | ||||||||||||||||||||||||
| 23 | - | |||||||||||||||||||||||||
| 24 | QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName) | - | ||||||||||||||||||||||||
| 25 | { | - | ||||||||||||||||||||||||
| 26 | for (int i = String; i <= Byte
| 0-7377 | ||||||||||||||||||||||||
| 27 | if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i]
| 3319-4058 | ||||||||||||||||||||||||
| 28 | return executed 4058 times by 1 test: Type(i);return Type(i);Executed by:
executed 4058 times by 1 test: return Type(i);Executed by:
| 4058 | ||||||||||||||||||||||||
| 29 | } executed 3319 times by 1 test: end of blockExecuted by:
| 3319 | ||||||||||||||||||||||||
| 30 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||||||||
| 31 | } | - | ||||||||||||||||||||||||
| 32 | - | |||||||||||||||||||||||||
| 33 | QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType) | - | ||||||||||||||||||||||||
| 34 | { | - | ||||||||||||||||||||||||
| 35 | return never executed: magicRuleTypes_string + magicRuleTypes_indices[theType];return magicRuleTypes_string + magicRuleTypes_indices[theType];never executed: return magicRuleTypes_string + magicRuleTypes_indices[theType]; | 0 | ||||||||||||||||||||||||
| 36 | } | - | ||||||||||||||||||||||||
| 37 | - | |||||||||||||||||||||||||
| 38 | bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const | - | ||||||||||||||||||||||||
| 39 | { | - | ||||||||||||||||||||||||
| 40 | return never executed: m_type == other.m_type &&return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction;never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 41 | m_value == other.m_value && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 42 | m_startPos == other.m_startPos && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 43 | m_endPos == other.m_endPos && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 44 | m_mask == other.m_mask && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 45 | m_pattern == other.m_pattern && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 46 | m_number == other.m_number && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 47 | m_numberMask == other.m_numberMask && never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 48 | m_matchFunction == other.m_matchFunction; never executed: return m_type == other.m_type && m_value == other.m_value && m_startPos == other.m_startPos && m_endPos == other.m_endPos && m_mask == other.m_mask && m_pattern == other.m_pattern && m_number == other.m_number && m_numberMask == other.m_numberMask && m_matchFunction == other.m_matchFunction; | 0 | ||||||||||||||||||||||||
| 49 | } | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, | - | ||||||||||||||||||||||||
| 53 | int valueLength, const char *valueData, const char *mask) | - | ||||||||||||||||||||||||
| 54 | { | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart); | - | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | if (!mask
| 9901-17592 | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | bool found = false; | - | ||||||||||||||||||||||||
| 63 | for (int i = rangeStart; i < rangeStart + rangeLength
| 5928-39384 | ||||||||||||||||||||||||
| 64 | if (i + valueLength > dataSize
| 3928-35456 | ||||||||||||||||||||||||
| 65 | break; executed 3928 times by 1 test: break;Executed by:
| 3928 | ||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | if (memcmp(valueData, dataPtr + i, valueLength) == 0
| 45-35411 | ||||||||||||||||||||||||
| 68 | found = true; | - | ||||||||||||||||||||||||
| 69 | break; executed 45 times by 1 test: break;Executed by:
| 45 | ||||||||||||||||||||||||
| 70 | } | - | ||||||||||||||||||||||||
| 71 | } executed 35411 times by 1 test: end of blockExecuted by:
| 35411 | ||||||||||||||||||||||||
| 72 | if (!found
| 45-9856 | ||||||||||||||||||||||||
| 73 | return executed 9856 times by 1 test: false;return false;Executed by:
executed 9856 times by 1 test: return false;Executed by:
| 9856 | ||||||||||||||||||||||||
| 74 | } executed 45 times by 1 test: else {end of blockExecuted by:
| 45 | ||||||||||||||||||||||||
| 75 | bool found = false; | - | ||||||||||||||||||||||||
| 76 | const char *readDataBase = dataPtr + rangeStart; | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | const int maxStartPos = dataNeeded - valueLength + 1; | - | ||||||||||||||||||||||||
| 82 | for (int i = 0; i < maxStartPos
| 17592-38620 | ||||||||||||||||||||||||
| 83 | const char *d = readDataBase + i; | - | ||||||||||||||||||||||||
| 84 | bool valid = true; | - | ||||||||||||||||||||||||
| 85 | for (int idx = 0; idx < valueLength
| 46-39071 | ||||||||||||||||||||||||
| 86 | if (((*
| 497-38574 | ||||||||||||||||||||||||
| 87 | valid = false; | - | ||||||||||||||||||||||||
| 88 | break; executed 38574 times by 1 test: break;Executed by:
| 38574 | ||||||||||||||||||||||||
| 89 | } | - | ||||||||||||||||||||||||
| 90 | } executed 497 times by 1 test: end of blockExecuted by:
| 497 | ||||||||||||||||||||||||
| 91 | if (valid
| 46-38574 | ||||||||||||||||||||||||
| 92 | found = true; executed 46 times by 1 test: found = true;Executed by:
| 46 | ||||||||||||||||||||||||
| 93 | } executed 38620 times by 1 test: end of blockExecuted by:
| 38620 | ||||||||||||||||||||||||
| 94 | if (!found
| 46-17546 | ||||||||||||||||||||||||
| 95 | return executed 17546 times by 1 test: false;return false;Executed by:
executed 17546 times by 1 test: return false;Executed by:
| 17546 | ||||||||||||||||||||||||
| 96 | } executed 46 times by 1 test: end of blockExecuted by:
| 46 | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | return executed 91 times by 1 test: true;return true;Executed by:
executed 91 times by 1 test: return true;Executed by:
| 91 | ||||||||||||||||||||||||
| 99 | } | - | ||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | bool QMimeMagicRule::matchString(const QByteArray &data) const | - | ||||||||||||||||||||||||
| 102 | { | - | ||||||||||||||||||||||||
| 103 | const int rangeLength = m_endPos - m_startPos + 1; | - | ||||||||||||||||||||||||
| 104 | return executed 17377 times by 1 test: QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());Executed by:
executed 17377 times by 1 test: return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());Executed by:
| 17377 | ||||||||||||||||||||||||
| 105 | } | - | ||||||||||||||||||||||||
| 106 | - | |||||||||||||||||||||||||
| 107 | template <typename T> | - | ||||||||||||||||||||||||
| 108 | bool QMimeMagicRule::matchNumber(const QByteArray &data) const | - | ||||||||||||||||||||||||
| 109 | { | - | ||||||||||||||||||||||||
| 110 | const T value(m_number); | - | ||||||||||||||||||||||||
| 111 | const T mask(m_numberMask); | - | ||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | const char *p = data.constData() + m_startPos; | - | ||||||||||||||||||||||||
| 117 | const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos + 1); | - | ||||||||||||||||||||||||
| 118 | for ( ; p <= e
| 1854-3457 | ||||||||||||||||||||||||
| 119 | if ((
| 13-3444 | ||||||||||||||||||||||||
| 120 | return executed 13 times by 1 test: true;return true;Executed by:
executed 13 times by 1 test: return true;Executed by:
| 13 | ||||||||||||||||||||||||
| 121 | } executed 3444 times by 1 test: end of blockExecuted by:
| 3444 | ||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | return executed 1854 times by 1 test: false;return false;Executed by:
executed 1854 times by 1 test: return false;Executed by:
| 1854 | ||||||||||||||||||||||||
| 124 | } | - | ||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | static inline QByteArray makePattern(const QByteArray &value) | - | ||||||||||||||||||||||||
| 127 | { | - | ||||||||||||||||||||||||
| 128 | QByteArray pattern(value.size(), Qt::Uninitialized); | - | ||||||||||||||||||||||||
| 129 | char *data = pattern.data(); | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | const char *p = value.constData(); | - | ||||||||||||||||||||||||
| 132 | const char *e = p + value.size(); | - | ||||||||||||||||||||||||
| 133 | for ( ; p < e
| 3431-33647 | ||||||||||||||||||||||||
| 134 | if (*
| 0-31392 | ||||||||||||||||||||||||
| 135 | if (*
| 775-1480 | ||||||||||||||||||||||||
| 136 | char c = 0; | - | ||||||||||||||||||||||||
| 137 | for (int i = 0; i < 2
| 10-1550 | ||||||||||||||||||||||||
| 138 | ++p; | - | ||||||||||||||||||||||||
| 139 | if (*
| 0-1540 | ||||||||||||||||||||||||
| 140 | c = (c << 4) + *p - '0'; executed 1260 times by 1 test: c = (c << 4) + *p - '0';Executed by:
| 1260 | ||||||||||||||||||||||||
| 141 | else if (*
| 0-220 | ||||||||||||||||||||||||
| 142 | c = (c << 4) + *p - 'a' + 10; executed 220 times by 1 test: c = (c << 4) + *p - 'a' + 10;Executed by:
| 220 | ||||||||||||||||||||||||
| 143 | else if (*
| 0-60 | ||||||||||||||||||||||||
| 144 | c = (c << 4) + *p - 'A' + 10; executed 60 times by 1 test: c = (c << 4) + *p - 'A' + 10;Executed by:
| 60 | ||||||||||||||||||||||||
| 145 | else | - | ||||||||||||||||||||||||
| 146 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 147 | } | - | ||||||||||||||||||||||||
| 148 | *data++ = c; | - | ||||||||||||||||||||||||
| 149 | } executed 775 times by 1 test: else if (*end of blockExecuted by:
| 45-1435 | ||||||||||||||||||||||||
| 150 | char c = *p - '0'; | - | ||||||||||||||||||||||||
| 151 | if (p + 1 < e
| 0-1195 | ||||||||||||||||||||||||
| 152 | c = (c << 3) + *(++p) - '0'; | - | ||||||||||||||||||||||||
| 153 | if (p + 1 < e
| 0-1055 | ||||||||||||||||||||||||
| 154 | c = (c << 3) + *(++p) - '0'; executed 1045 times by 1 test: c = (c << 3) + *(++p) - '0';Executed by:
| 1045 | ||||||||||||||||||||||||
| 155 | } executed 1060 times by 1 test: end of blockExecuted by:
| 1060 | ||||||||||||||||||||||||
| 156 | *data++ = c; | - | ||||||||||||||||||||||||
| 157 | } executed 1280 times by 1 test: else if (*end of blockExecuted by:
| 75-1280 | ||||||||||||||||||||||||
| 158 | *data++ = '\n'; | - | ||||||||||||||||||||||||
| 159 | } executed 75 times by 1 test: else if (*end of blockExecuted by:
| 10-115 | ||||||||||||||||||||||||
| 160 | *data++ = '\r'; | - | ||||||||||||||||||||||||
| 161 | } executed 10 times by 1 test: else if (*end of blockExecuted by:
| 10-100 | ||||||||||||||||||||||||
| 162 | *data++ = '\t'; | - | ||||||||||||||||||||||||
| 163 | } executed 15 times by 1 test: else {end of blockExecuted by:
| 15 | ||||||||||||||||||||||||
| 164 | *data++ = *p; | - | ||||||||||||||||||||||||
| 165 | } executed 100 times by 1 test: end of blockExecuted by:
| 100 | ||||||||||||||||||||||||
| 166 | } else { | - | ||||||||||||||||||||||||
| 167 | *data++ = *p; | - | ||||||||||||||||||||||||
| 168 | } executed 31392 times by 1 test: end of blockExecuted by:
| 31392 | ||||||||||||||||||||||||
| 169 | } | - | ||||||||||||||||||||||||
| 170 | pattern.truncate(data - pattern.data()); | - | ||||||||||||||||||||||||
| 171 | - | |||||||||||||||||||||||||
| 172 | return executed 3431 times by 1 test: pattern;return pattern;Executed by:
executed 3431 times by 1 test: return pattern;Executed by:
| 3431 | ||||||||||||||||||||||||
| 173 | } | - | ||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||
| 179 | QMimeMagicRule::QMimeMagicRule(const QString &type, | - | ||||||||||||||||||||||||
| 180 | const QByteArray &value, | - | ||||||||||||||||||||||||
| 181 | const QString &offsets, | - | ||||||||||||||||||||||||
| 182 | const QByteArray &mask, | - | ||||||||||||||||||||||||
| 183 | QString *errorString) | - | ||||||||||||||||||||||||
| 184 | : m_type(QMimeMagicRule::type(type.toLatin1())), | - | ||||||||||||||||||||||||
| 185 | m_value(value), | - | ||||||||||||||||||||||||
| 186 | m_mask(mask), | - | ||||||||||||||||||||||||
| 187 | m_matchFunction(nullptr) | - | ||||||||||||||||||||||||
| 188 | { | - | ||||||||||||||||||||||||
| 189 | if (__builtin_expect(!!(m_type == Invalid), false)
| 0-4058 | ||||||||||||||||||||||||
| 190 | * never executed: errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported");*errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported");never executed: *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported"); | 0 | ||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | const int colonIndex = offsets.indexOf(QLatin1Char(':')); | - | ||||||||||||||||||||||||
| 194 | const QStringRef startPosStr = offsets.midRef(0, colonIndex); | - | ||||||||||||||||||||||||
| 195 | const QStringRef endPosStr = offsets.midRef(colonIndex + 1); | - | ||||||||||||||||||||||||
| 196 | if (__builtin_expect(!!(!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)), false)
| 0-4058 | ||||||||||||||||||||||||
| 197 | __builtin_expect(!!(!QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString)), false)
| 0-4058 | ||||||||||||||||||||||||
| 198 | m_type = Invalid; | - | ||||||||||||||||||||||||
| 199 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 200 | } | - | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | if (__builtin_expect(!!(m_value.isEmpty()), false)
| 0-4058 | ||||||||||||||||||||||||
| 203 | m_type = Invalid; | - | ||||||||||||||||||||||||
| 204 | if (errorString
| 0 | ||||||||||||||||||||||||
| 205 | * never executed: errorString = ([]() -> QString { enum { Size = sizeof(u"" "Invalid empty magic rule value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid empty magic rule value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return*errorString = ([]() -> QString { enum { Size = sizeof(u"" "Invalid empty magic rule value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid empty magic rule value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }());return qstring_literal_temp;never executed: *errorString = ([]() -> QString { enum { Size = sizeof(u"" "Invalid empty magic rule value")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid empty magic rule value" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); | 0 | ||||||||||||||||||||||||
| 206 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 207 | } | - | ||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||
| 209 | if (m_type >= Host16
| 0-3431 | ||||||||||||||||||||||||
| 210 | bool ok; | - | ||||||||||||||||||||||||
| 211 | m_number = m_value.toUInt(&ok, 0); | - | ||||||||||||||||||||||||
| 212 | if (__builtin_expect(!!(!ok), false)
| 2-625 | ||||||||||||||||||||||||
| 213 | m_type = Invalid; | - | ||||||||||||||||||||||||
| 214 | if (errorString
| 0-2 | ||||||||||||||||||||||||
| 215 | * executed 2 times by 1 test: errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');*errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');Executed by:
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');Executed by:
| 2 | ||||||||||||||||||||||||
| 216 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 217 | } | - | ||||||||||||||||||||||||
| 218 | m_numberMask = !m_mask.isEmpty()
| 50-575 | ||||||||||||||||||||||||
| 219 | } executed 625 times by 1 test: end of blockExecuted by:
| 625 | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | switch (m_type) { | - | ||||||||||||||||||||||||
| 222 | case executed 3431 times by 1 test: String:case String:Executed by:
executed 3431 times by 1 test: case String:Executed by:
| 3431 | ||||||||||||||||||||||||
| 223 | m_pattern = makePattern(m_value); | - | ||||||||||||||||||||||||
| 224 | m_pattern.squeeze(); | - | ||||||||||||||||||||||||
| 225 | if (!m_mask.isEmpty()
| 29-3402 | ||||||||||||||||||||||||
| 226 | if (__builtin_expect(!!(m_mask.size() < 4 || !m_mask.startsWith("0x")), false)
| 2-27 | ||||||||||||||||||||||||
| 227 | m_type = Invalid; | - | ||||||||||||||||||||||||
| 228 | if (errorString
| 0-2 | ||||||||||||||||||||||||
| 229 | * executed 2 times by 1 test: errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');*errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');Executed by:
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');Executed by:
| 2 | ||||||||||||||||||||||||
| 230 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 231 | } | - | ||||||||||||||||||||||||
| 232 | const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( | - | ||||||||||||||||||||||||
| 233 | m_mask.constData() + 2, m_mask.size() - 2)); | - | ||||||||||||||||||||||||
| 234 | if (__builtin_expect(!!(tempMask.size() != m_pattern.size()), false)
| 2-25 | ||||||||||||||||||||||||
| 235 | m_type = Invalid; | - | ||||||||||||||||||||||||
| 236 | if (errorString
| 0-2 | ||||||||||||||||||||||||
| 237 | * executed 2 times by 1 test: errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');*errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');Executed by:
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');Executed by:
| 2 | ||||||||||||||||||||||||
| 238 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 239 | } | - | ||||||||||||||||||||||||
| 240 | m_mask = tempMask; | - | ||||||||||||||||||||||||
| 241 | } executed 25 times by 1 test: else {end of blockExecuted by:
| 25 | ||||||||||||||||||||||||
| 242 | m_mask.fill(char(-1), m_pattern.size()); | - | ||||||||||||||||||||||||
| 243 | } executed 3402 times by 1 test: end of blockExecuted by:
| 3402 | ||||||||||||||||||||||||
| 244 | m_mask.squeeze(); | - | ||||||||||||||||||||||||
| 245 | m_matchFunction = &QMimeMagicRule::matchString; | - | ||||||||||||||||||||||||
| 246 | break; executed 3427 times by 1 test: break;Executed by:
| 3427 | ||||||||||||||||||||||||
| 247 | case executed 205 times by 1 test: Byte:case Byte:Executed by:
executed 205 times by 1 test: case Byte:Executed by:
| 205 | ||||||||||||||||||||||||
| 248 | if (m_number <= quint8(-1)
| 0-205 | ||||||||||||||||||||||||
| 249 | if (m_numberMask == 0
| 0-205 | ||||||||||||||||||||||||
| 250 | m_numberMask = quint8(-1); executed 205 times by 1 test: m_numberMask = quint8(-1);Executed by:
| 205 | ||||||||||||||||||||||||
| 251 | m_matchFunction = &QMimeMagicRule::matchNumber<quint8>; | - | ||||||||||||||||||||||||
| 252 | } executed 205 times by 1 test: end of blockExecuted by:
| 205 | ||||||||||||||||||||||||
| 253 | break; executed 205 times by 1 test: break;Executed by:
| 205 | ||||||||||||||||||||||||
| 254 | case executed 65 times by 1 test: Big16:case Big16:Executed by:
executed 65 times by 1 test: case Big16:Executed by:
| 65 | ||||||||||||||||||||||||
| 255 | case executed 20 times by 1 test: Host16:case Host16:Executed by:
executed 20 times by 1 test: case Host16:Executed by:
| 20 | ||||||||||||||||||||||||
| 256 | case executed 85 times by 1 test: Little16:case Little16:Executed by:
executed 85 times by 1 test: case Little16:Executed by:
| 85 | ||||||||||||||||||||||||
| 257 | if (m_number <= quint16(-1)
| 0-170 | ||||||||||||||||||||||||
| 258 | m_number = m_type == Little16
| 85 | ||||||||||||||||||||||||
| 259 | if (m_numberMask == 0
| 5-165 | ||||||||||||||||||||||||
| 260 | m_numberMask = quint16(-1); executed 165 times by 1 test: m_numberMask = quint16(-1);Executed by:
| 165 | ||||||||||||||||||||||||
| 261 | m_matchFunction = &QMimeMagicRule::matchNumber<quint16>; | - | ||||||||||||||||||||||||
| 262 | } executed 170 times by 1 test: end of blockExecuted by:
| 170 | ||||||||||||||||||||||||
| 263 | break; executed 170 times by 1 test: break;Executed by:
| 170 | ||||||||||||||||||||||||
| 264 | case executed 95 times by 1 test: Big32:case Big32:Executed by:
executed 95 times by 1 test: case Big32:Executed by:
| 95 | ||||||||||||||||||||||||
| 265 | case executed 20 times by 1 test: Host32:case Host32:Executed by:
executed 20 times by 1 test: case Host32:Executed by:
| 20 | ||||||||||||||||||||||||
| 266 | case executed 135 times by 1 test: Little32:case Little32:Executed by:
executed 135 times by 1 test: case Little32:Executed by:
| 135 | ||||||||||||||||||||||||
| 267 | if (m_number <= quint32(-1)
| 0-250 | ||||||||||||||||||||||||
| 268 | m_number = m_type == Little32
| 115-135 | ||||||||||||||||||||||||
| 269 | if (m_numberMask == 0
| 45-205 | ||||||||||||||||||||||||
| 270 | m_numberMask = quint32(-1); executed 205 times by 1 test: m_numberMask = quint32(-1);Executed by:
| 205 | ||||||||||||||||||||||||
| 271 | m_matchFunction = &QMimeMagicRule::matchNumber<quint32>; | - | ||||||||||||||||||||||||
| 272 | } executed 250 times by 1 test: end of blockExecuted by:
| 250 | ||||||||||||||||||||||||
| 273 | break; executed 250 times by 1 test: break;Executed by:
| 250 | ||||||||||||||||||||||||
| 274 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||||||||
| 275 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 276 | } | - | ||||||||||||||||||||||||
| 277 | } | - | ||||||||||||||||||||||||
| 278 | - | |||||||||||||||||||||||||
| 279 | QByteArray QMimeMagicRule::mask() const | - | ||||||||||||||||||||||||
| 280 | { | - | ||||||||||||||||||||||||
| 281 | QByteArray result = m_mask; | - | ||||||||||||||||||||||||
| 282 | if (m_type == String
| 0 | ||||||||||||||||||||||||
| 283 | - | |||||||||||||||||||||||||
| 284 | result = "0x" + result.toHex(); | - | ||||||||||||||||||||||||
| 285 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 286 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||||||||||||||
| 287 | } | - | ||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||
| 289 | bool QMimeMagicRule::matches(const QByteArray &data) const | - | ||||||||||||||||||||||||
| 290 | { | - | ||||||||||||||||||||||||
| 291 | const bool ok = m_matchFunction && (
| 59-19185 | ||||||||||||||||||||||||
| 292 | if (!ok
| 59-19185 | ||||||||||||||||||||||||
| 293 | return executed 19185 times by 1 test: false;return false;Executed by:
executed 19185 times by 1 test: return false;Executed by:
| 19185 | ||||||||||||||||||||||||
| 294 | - | |||||||||||||||||||||||||
| 295 | - | |||||||||||||||||||||||||
| 296 | if (m_subMatches.isEmpty()
| 22-37 | ||||||||||||||||||||||||
| 297 | return executed 37 times by 1 test: true;return true;Executed by:
executed 37 times by 1 test: return true;Executed by:
| 37 | ||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||
| 299 | - | |||||||||||||||||||||||||
| 300 | - | |||||||||||||||||||||||||
| 301 | for ( QList<QMimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ; | - | ||||||||||||||||||||||||
| 302 | it != end
| 18-22 | ||||||||||||||||||||||||
| 303 | if ((*
| 4-18 | ||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||
| 305 | return executed 4 times by 1 test: true;return true;Executed by:
executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||||||||
| 306 | } | - | ||||||||||||||||||||||||
| 307 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 308 | return executed 18 times by 1 test: false;return false;Executed by:
executed 18 times by 1 test: return false;Executed by:
| 18 | ||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||
| 310 | - | |||||||||||||||||||||||||
| 311 | } | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |