OpenCoverage

qmimemagicrule.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimemagicrule.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40-
41#define QT_NO_CAST_FROM_ASCII-
42-
43#include "qmimemagicrule_p.h"-
44-
45#ifndef QT_NO_MIMETYPE-
46-
47#include "qmimetypeparser_p.h"-
48#include <QtCore/QList>-
49#include <QtCore/QDebug>-
50#include <qendian.h>-
51-
52QT_BEGIN_NAMESPACE-
53-
54// in the same order as Type!-
55static const char magicRuleTypes_string[] =-
56 "invalid\0"-
57 "string\0"-
58 "host16\0"-
59 "host32\0"-
60 "big16\0"-
61 "big32\0"-
62 "little16\0"-
63 "little32\0"-
64 "byte\0"-
65 "\0";-
66-
67static const int magicRuleTypes_indices[] = {-
68 0, 8, 15, 22, 29, 35, 41, 50, 59, 65, 0-
69};-
70-
71QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName)-
72{-
73 for (int i = String; i <= Byte; ++i) {
i <= ByteDescription
TRUEevaluated 7377 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-7377
74 if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i])
theTypeName ==...pes_indices[i]Description
TRUEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3319 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
3319-4058
75 return Type(i);
executed 4058 times by 1 test: return Type(i);
Executed by:
  • tst_QMimeDatabase
4058
76 }
executed 3319 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
3319
77 return Invalid;
never executed: return Invalid;
0
78}-
79-
80QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType)-
81{-
82 return magicRuleTypes_string + magicRuleTypes_indices[theType];
never executed: return magicRuleTypes_string + magicRuleTypes_indices[theType];
0
83}-
84-
85bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const-
86{-
87 return m_type == other.m_type &&
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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96}-
97-
98// Used by both providers-
99bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength,-
100 int valueLength, const char *valueData, const char *mask)-
101{-
102 // Size of searched data.-
103 // Example: value="ABC", rangeLength=3 -> we need 3+3-1=5 bytes (ABCxx,xABCx,xxABC would match)-
104 const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart);-
105-
106 if (!mask) {
!maskDescription
TRUEevaluated 9901 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 17592 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
9901-17592
107 // callgrind says QByteArray::indexOf is much slower, since our strings are typically too-
108 // short for be worth Boyer-Moore matching (1 to 71 bytes, 11 bytes on average).-
109 bool found = false;-
110 for (int i = rangeStart; i < rangeStart + rangeLength; ++i) {
i < rangeStart + rangeLengthDescription
TRUEevaluated 39384 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 5928 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
5928-39384
111 if (i + valueLength > dataSize)
i + valueLength > dataSizeDescription
TRUEevaluated 3928 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 35456 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
3928-35456
112 break;
executed 3928 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
3928
113-
114 if (memcmp(valueData, dataPtr + i, valueLength) == 0) {
memcmp(valueDa...ueLength) == 0Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 35411 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
45-35411
115 found = true;-
116 break;
executed 45 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
45
117 }-
118 }
executed 35411 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
35411
119 if (!found)
!foundDescription
TRUEevaluated 9856 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
45-9856
120 return false;
executed 9856 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
9856
121 } else {
executed 45 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
45
122 bool found = false;-
123 const char *readDataBase = dataPtr + rangeStart;-
124 // Example (continued from above):-
125 // deviceSize is 4, so dataNeeded was max'ed to 4.-
126 // maxStartPos = 4 - 3 + 1 = 2, and indeed-
127 // we need to check for a match a positions 0 and 1 (ABCx and xABC).-
128 const int maxStartPos = dataNeeded - valueLength + 1;-
129 for (int i = 0; i < maxStartPos; ++i) {
i < maxStartPosDescription
TRUEevaluated 38620 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 17592 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
17592-38620
130 const char *d = readDataBase + i;-
131 bool valid = true;-
132 for (int idx = 0; idx < valueLength; ++idx) {
idx < valueLengthDescription
TRUEevaluated 39071 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 46 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
46-39071
133 if (((*d++) & mask[idx]) != (valueData[idx] & mask[idx])) {
((*d++) & mask...] & mask[idx])Description
TRUEevaluated 38574 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 497 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
497-38574
134 valid = false;-
135 break;
executed 38574 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
38574
136 }-
137 }
executed 497 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
497
138 if (valid)
validDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 38574 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
46-38574
139 found = true;
executed 46 times by 1 test: found = true;
Executed by:
  • tst_QMimeDatabase
46
140 }
executed 38620 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
38620
141 if (!found)
!foundDescription
TRUEevaluated 17546 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 46 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
46-17546
142 return false;
executed 17546 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
17546
143 }
executed 46 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
46
144 //qDebug() << "Found" << value << "in" << searchedData;-
145 return true;
executed 91 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
91
146}-
147-
148bool QMimeMagicRule::matchString(const QByteArray &data) const-
149{-
150 const int rangeLength = m_endPos - m_startPos + 1;-
151 return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());
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:
  • tst_QMimeDatabase
17377
152}-
153-
154template <typename T>-
155bool QMimeMagicRule::matchNumber(const QByteArray &data) const-
156{-
157 const T value(m_number);-
158 const T mask(m_numberMask);-
159-
160 //qDebug() << "matchNumber" << "0x" << QString::number(m_number, 16) << "size" << sizeof(T);-
161 //qDebug() << "mask" << QString::number(m_numberMask, 16);-
162-
163 const char *p = data.constData() + m_startPos;-
164 const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos + 1);-
165 for ( ; p <= e; ++p) {
p <= eDescription
TRUEevaluated 3457 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 1854 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
1854-3457
166 if ((qFromUnaligned<T>(p) & mask) == (value & mask))
(qFromUnaligne...(value & mask)Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3444 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
13-3444
167 return true;
executed 13 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
13
168 }
executed 3444 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
3444
169-
170 return false;
executed 1854 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
1854
171}-
172-
173static inline QByteArray makePattern(const QByteArray &value)-
174{-
175 QByteArray pattern(value.size(), Qt::Uninitialized);-
176 char *data = pattern.data();-
177-
178 const char *p = value.constData();-
179 const char *e = p + value.size();-
180 for ( ; p < e; ++p) {
p < eDescription
TRUEevaluated 33647 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3431 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
3431-33647
181 if (*p == '\\' && ++p < e) {
*p == '\\'Description
TRUEevaluated 2255 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 31392 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
++p < eDescription
TRUEevaluated 2255 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-31392
182 if (*p == 'x') { // hex (\\xff)
*p == 'x'Description
TRUEevaluated 775 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 1480 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
775-1480
183 char c = 0;-
184 for (int i = 0; i < 2 && p + 1 < e; ++i) {
i < 2Description
TRUEevaluated 1550 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 765 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p + 1 < eDescription
TRUEevaluated 1540 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
10-1550
185 ++p;-
186 if (*p >= '0' && *p <= '9')
*p >= '0'Description
TRUEevaluated 1540 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
*p <= '9'Description
TRUEevaluated 1260 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 280 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
0-1540
187 c = (c << 4) + *p - '0';
executed 1260 times by 1 test: c = (c << 4) + *p - '0';
Executed by:
  • tst_QMimeDatabase
1260
188 else if (*p >= 'a' && *p <= 'f')
*p >= 'a'Description
TRUEevaluated 220 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
*p <= 'f'Description
TRUEevaluated 220 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-220
189 c = (c << 4) + *p - 'a' + 10;
executed 220 times by 1 test: c = (c << 4) + *p - 'a' + 10;
Executed by:
  • tst_QMimeDatabase
220
190 else if (*p >= 'A' && *p <= 'F')
*p >= 'A'Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
*p <= 'F'Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-60
191 c = (c << 4) + *p - 'A' + 10;
executed 60 times by 1 test: c = (c << 4) + *p - 'A' + 10;
Executed by:
  • tst_QMimeDatabase
60
192 else-
193 continue;
never executed: continue;
0
194 }-
195 *data++ = c;-
196 } else if (*p >= '0' && *p <= '7') { // oct (\\7, or \\77, or \\377)
executed 775 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
*p >= '0'Description
TRUEevaluated 1435 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
*p <= '7'Description
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 155 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
45-1435
197 char c = *p - '0';-
198 if (p + 1 < e && p[1] >= '0' && p[1] <= '7') {
p + 1 < eDescription
TRUEevaluated 1195 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 85 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p[1] >= '0'Description
TRUEevaluated 1195 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
p[1] <= '7'Description
TRUEevaluated 1060 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 135 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
0-1195
199 c = (c << 3) + *(++p) - '0';-
200 if (p + 1 < e && p[1] >= '0' && p[1] <= '7' && p[-1] <= '3')
p + 1 < eDescription
TRUEevaluated 1055 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p[1] >= '0'Description
TRUEevaluated 1055 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
p[1] <= '7'Description
TRUEevaluated 1045 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
p[-1] <= '3'Description
TRUEevaluated 1045 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-1055
201 c = (c << 3) + *(++p) - '0';
executed 1045 times by 1 test: c = (c << 3) + *(++p) - '0';
Executed by:
  • tst_QMimeDatabase
1045
202 }
executed 1060 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
1060
203 *data++ = c;-
204 } else if (*p == 'n') {
executed 1280 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
*p == 'n'Description
TRUEevaluated 75 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 125 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
75-1280
205 *data++ = '\n';-
206 } else if (*p == 'r') {
executed 75 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
*p == 'r'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 115 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
10-115
207 *data++ = '\r';-
208 } else if (*p == 't') {
executed 10 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
*p == 't'Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 100 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
10-100
209 *data++ = '\t';-
210 } else { // escaped
executed 15 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
15
211 *data++ = *p;-
212 }
executed 100 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
100
213 } else {-
214 *data++ = *p;-
215 }
executed 31392 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
31392
216 }-
217 pattern.truncate(data - pattern.data());-
218-
219 return pattern;
executed 3431 times by 1 test: return pattern;
Executed by:
  • tst_QMimeDatabase
3431
220}-
221-
222// Evaluate a magic match rule like-
223// <match value="must be converted with BinHex" type="string" offset="11"/>-
224// <match value="0x9501" type="big16" offset="0:64"/>-
225-
226QMimeMagicRule::QMimeMagicRule(const QString &type,-
227 const QByteArray &value,-
228 const QString &offsets,-
229 const QByteArray &mask,-
230 QString *errorString)-
231 : m_type(QMimeMagicRule::type(type.toLatin1())),-
232 m_value(value),-
233 m_mask(mask),-
234 m_matchFunction(nullptr)-
235{-
236 if (Q_UNLIKELY(m_type == Invalid))
__builtin_expe...valid), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
0-4058
237 *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported");
never executed: *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported");
0
238-
239 // Parse for offset as "1" or "1:10"-
240 const int colonIndex = offsets.indexOf(QLatin1Char(':'));-
241 const QStringRef startPosStr = offsets.midRef(0, colonIndex); // \ These decay to returning 'offsets'-
242 const QStringRef endPosStr = offsets.midRef(colonIndex + 1);// / unchanged when colonIndex == -1-
243 if (Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) ||
__builtin_expe...ring)), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
0-4058
244 Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) {
__builtin_expe...ring)), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
0-4058
245 m_type = Invalid;-
246 return;
never executed: return;
0
247 }-
248-
249 if (Q_UNLIKELY(m_value.isEmpty())) {
__builtin_expe...pty()), false)Description
TRUEnever evaluated
FALSEevaluated 4058 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
0-4058
250 m_type = Invalid;-
251 if (errorString)
errorStringDescription
TRUEnever evaluated
FALSEnever evaluated
0
252 *errorString = QStringLiteral("Invalid empty magic rule value");
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; }());
never executed: return qstring_literal_temp;
0
253 return;
never executed: return;
0
254 }-
255-
256 if (m_type >= Host16 && m_type <= Byte) {
m_type >= Host16Description
TRUEevaluated 627 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3431 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
m_type <= ByteDescription
TRUEevaluated 627 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-3431
257 bool ok;-
258 m_number = m_value.toUInt(&ok, 0); // autodetect base-
259 if (Q_UNLIKELY(!ok)) {
__builtin_expe...!(!ok), false)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 625 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
2-625
260 m_type = Invalid;-
261 if (errorString)
errorStringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-2
262 *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
2
263 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QMimeDatabase
2
264 }-
265 m_numberMask = !m_mask.isEmpty() ? m_mask.toUInt(&ok, 0) : 0; // autodetect base
!m_mask.isEmpty()Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 575 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
50-575
266 }
executed 625 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
625
267-
268 switch (m_type) {-
269 case String:
executed 3431 times by 1 test: case String:
Executed by:
  • tst_QMimeDatabase
3431
270 m_pattern = makePattern(m_value);-
271 m_pattern.squeeze();-
272 if (!m_mask.isEmpty()) {
!m_mask.isEmpty()Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 3402 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
29-3402
273 if (Q_UNLIKELY(m_mask.size() < 4 || !m_mask.startsWith("0x"))) {
__builtin_expe..."0x")), false)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 27 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
2-27
274 m_type = Invalid;-
275 if (errorString)
errorStringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-2
276 *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
2
277 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QMimeDatabase
2
278 }-
279 const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData(-
280 m_mask.constData() + 2, m_mask.size() - 2));-
281 if (Q_UNLIKELY(tempMask.size() != m_pattern.size())) {
__builtin_expe...ize()), false)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
2-25
282 m_type = Invalid;-
283 if (errorString)
errorStringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-2
284 *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
executed 2 times by 1 test: *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
Executed by:
  • tst_QMimeDatabase
2
285 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QMimeDatabase
2
286 }-
287 m_mask = tempMask;-
288 } else {
executed 25 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
25
289 m_mask.fill(char(-1), m_pattern.size());-
290 }
executed 3402 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
3402
291 m_mask.squeeze();-
292 m_matchFunction = &QMimeMagicRule::matchString;-
293 break;
executed 3427 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
3427
294 case Byte:
executed 205 times by 1 test: case Byte:
Executed by:
  • tst_QMimeDatabase
205
295 if (m_number <= quint8(-1)) {
m_number <= quint8(-1)Description
TRUEevaluated 205 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-205
296 if (m_numberMask == 0)
m_numberMask == 0Description
TRUEevaluated 205 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-205
297 m_numberMask = quint8(-1);
executed 205 times by 1 test: m_numberMask = quint8(-1);
Executed by:
  • tst_QMimeDatabase
205
298 m_matchFunction = &QMimeMagicRule::matchNumber<quint8>;-
299 }
executed 205 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
205
300 break;
executed 205 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
205
301 case Big16:
executed 65 times by 1 test: case Big16:
Executed by:
  • tst_QMimeDatabase
65
302 case Host16:
executed 20 times by 1 test: case Host16:
Executed by:
  • tst_QMimeDatabase
20
303 case Little16:
executed 85 times by 1 test: case Little16:
Executed by:
  • tst_QMimeDatabase
85
304 if (m_number <= quint16(-1)) {
m_number <= quint16(-1)Description
TRUEevaluated 170 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-170
305 m_number = m_type == Little16 ? qFromLittleEndian<quint16>(m_number) : qFromBigEndian<quint16>(m_number);
m_type == Little16Description
TRUEevaluated 85 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 85 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
85
306 if (m_numberMask == 0)
m_numberMask == 0Description
TRUEevaluated 165 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
5-165
307 m_numberMask = quint16(-1);
executed 165 times by 1 test: m_numberMask = quint16(-1);
Executed by:
  • tst_QMimeDatabase
165
308 m_matchFunction = &QMimeMagicRule::matchNumber<quint16>;-
309 }
executed 170 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
170
310 break;
executed 170 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
170
311 case Big32:
executed 95 times by 1 test: case Big32:
Executed by:
  • tst_QMimeDatabase
95
312 case Host32:
executed 20 times by 1 test: case Host32:
Executed by:
  • tst_QMimeDatabase
20
313 case Little32:
executed 135 times by 1 test: case Little32:
Executed by:
  • tst_QMimeDatabase
135
314 if (m_number <= quint32(-1)) {
m_number <= quint32(-1)Description
TRUEevaluated 250 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEnever evaluated
0-250
315 m_number = m_type == Little32 ? qFromLittleEndian<quint32>(m_number) : qFromBigEndian<quint32>(m_number);
m_type == Little32Description
TRUEevaluated 135 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 115 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
115-135
316 if (m_numberMask == 0)
m_numberMask == 0Description
TRUEevaluated 205 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 45 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
45-205
317 m_numberMask = quint32(-1);
executed 205 times by 1 test: m_numberMask = quint32(-1);
Executed by:
  • tst_QMimeDatabase
205
318 m_matchFunction = &QMimeMagicRule::matchNumber<quint32>;-
319 }
executed 250 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
250
320 break;
executed 250 times by 1 test: break;
Executed by:
  • tst_QMimeDatabase
250
321 default:
never executed: default:
0
322 break;
never executed: break;
0
323 }-
324}-
325-
326QByteArray QMimeMagicRule::mask() const-
327{-
328 QByteArray result = m_mask;-
329 if (m_type == String) {
m_type == StringDescription
TRUEnever evaluated
FALSEnever evaluated
0
330 // restore '0x'-
331 result = "0x" + result.toHex();-
332 }
never executed: end of block
0
333 return result;
never executed: return result;
0
334}-
335-
336bool QMimeMagicRule::matches(const QByteArray &data) const-
337{-
338 const bool ok = m_matchFunction && (this->*m_matchFunction)(data);
(this->*m_matchFunction)(data)Description
TRUEevaluated 59 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 19185 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
59-19185
339 if (!ok)
!okDescription
TRUEevaluated 19185 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 59 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
59-19185
340 return false;
executed 19185 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
19185
341-
342 // No submatch? Then we are done.-
343 if (m_subMatches.isEmpty())
m_subMatches.isEmpty()Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 22 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
22-37
344 return true;
executed 37 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
37
345-
346 //qDebug() << "Checking" << m_subMatches.count() << "sub-rules";-
347 // Check that one of the submatches matches too-
348 for ( QList<QMimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ;-
349 it != end ; ++it ) {
it != endDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
18-22
350 if ((*it).matches(data)) {
(*it).matches(data)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QMimeDatabase
4-18
351 // One of the hierarchies matched -> mimetype recognized.-
352 return true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_QMimeDatabase
4
353 }-
354 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_QMimeDatabase
18
355 return false;
executed 18 times by 1 test: return false;
Executed by:
  • tst_QMimeDatabase
18
356-
357-
358}-
359-
360QT_END_NAMESPACE-
361-
362#endif // QT_NO_MIMETYPE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9