QXmlStreamReader: port Value::pos from int to qsizetype

It's an index into a QString, so it has to be qsizetype.

The length and prefix fields also shouldn't stay ints, but that's a
different patch, because they're just relative offsets to pos, and so
aren't as easily overflown.

This enlarges the Value struct; created QTBUG-103306 to track ideas to
shrink it again.

Pick-to: 6.3 6.2
Task-number: QTBUG-102465
Change-Id: Ib318e131420c2c535e26cb03cbf450e031626e64
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Marc Mutz 2022-05-06 09:35:42 +02:00
parent 6245d7dd3b
commit 61c83dfb22
3 changed files with 9 additions and 9 deletions

View File

@ -873,7 +873,7 @@ processing_instruction ::= LANGLE QUESTIONMARK name space;
/.
case $rule_number: {
setType(QXmlStreamReader::ProcessingInstruction);
int pos = sym(4).pos + sym(4).len;
const qsizetype pos = sym(4).pos + sym(4).len;
processingInstructionTarget = symString(3);
if (scanUntil("?>")) {
processingInstructionData = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 2);
@ -925,7 +925,7 @@ comment ::= comment_start RANGLE;
/.
case $rule_number: {
setType(QXmlStreamReader::Comment);
int pos = sym(1).pos + 4;
const qsizetype pos = sym(1).pos + 4;
text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
} break;
./
@ -937,7 +937,7 @@ cdata ::= langle_bang CDATA_START;
setType(QXmlStreamReader::Characters);
isCDATA = true;
isWhitespace = false;
int pos = sym(2).pos;
const qsizetype pos = sym(2).pos;
if (scanUntil("]]>", -1)) {
text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
} else {
@ -1216,7 +1216,7 @@ attribute ::= qname space_opt EQ space_opt attribute_value;
}
if (normalize) {
// normalize attribute value (simplify and trim)
int pos = textBuffer.size();
const qsizetype pos = textBuffer.size();
int n = 0;
bool wasSpace = true;
for (int i = 0; i < attribute.value.len; ++i) {

View File

@ -409,7 +409,7 @@ public:
int tos;
int stack_size;
struct Value {
int pos;
qsizetype pos; // offset into textBuffer
int len;
int prefix;
ushort c;

View File

@ -574,7 +574,7 @@ bool QXmlStreamReaderPrivate::parse()
case 96: {
setType(QXmlStreamReader::ProcessingInstruction);
int pos = sym(4).pos + sym(4).len;
const qsizetype pos = sym(4).pos + sym(4).len;
processingInstructionTarget = symString(3);
if (scanUntil("?>")) {
processingInstructionData = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 2);
@ -613,7 +613,7 @@ bool QXmlStreamReaderPrivate::parse()
case 100: {
setType(QXmlStreamReader::Comment);
int pos = sym(1).pos + 4;
const qsizetype pos = sym(1).pos + 4;
text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
} break;
@ -621,7 +621,7 @@ bool QXmlStreamReaderPrivate::parse()
setType(QXmlStreamReader::Characters);
isCDATA = true;
isWhitespace = false;
int pos = sym(2).pos;
const qsizetype pos = sym(2).pos;
if (scanUntil("]]>", -1)) {
text = XmlStringRef(&textBuffer, pos, textBuffer.size() - pos - 3);
} else {
@ -779,7 +779,7 @@ bool QXmlStreamReaderPrivate::parse()
}
if (normalize) {
// normalize attribute value (simplify and trim)
int pos = textBuffer.size();
const qsizetype pos = textBuffer.size();
int n = 0;
bool wasSpace = true;
for (int i = 0; i < attribute.value.len; ++i) {