summaryrefslogtreecommitdiffstats
path: root/src/gui/util/qedidparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/util/qedidparser.cpp')
-rw-r--r--src/gui/util/qedidparser.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/gui/util/qedidparser.cpp b/src/gui/util/qedidparser.cpp
index b989503ec2..4dae151e6a 100644
--- a/src/gui/util/qedidparser.cpp
+++ b/src/gui/util/qedidparser.cpp
@@ -12,6 +12,7 @@
#define EDID_DESCRIPTOR_PRODUCT_NAME 0xfc
#define EDID_DESCRIPTOR_SERIAL_NUMBER 0xff
+#define EDID_DATA_BLOCK_COUNT 4
#define EDID_OFFSET_DATA_BLOCKS 0x36
#define EDID_OFFSET_LAST_BLOCK 0x6c
#define EDID_OFFSET_PNP_ID 0x08
@@ -71,7 +72,7 @@ static QString lookupVendorIdInSystemDatabase(QByteArrayView id)
bool QEdidParser::parse(const QByteArray &blob)
{
const quint8 *data = reinterpret_cast<const quint8 *>(blob.constData());
- const size_t length = blob.length();
+ const size_t length = blob.size();
// Verify header
if (length < 128)
@@ -104,7 +105,7 @@ bool QEdidParser::parse(const QByteArray &blob)
serialNumber = QString();
// Parse EDID data
- for (int i = 0; i < 5; ++i) {
+ for (int i = 0; i < EDID_DATA_BLOCK_COUNT; ++i) {
const uint offset = EDID_OFFSET_DATA_BLOCKS + i * 18;
if (data[offset] != 0 || data[offset + 1] != 0 || data[offset + 2] != 0)
@@ -234,16 +235,22 @@ QString QEdidParser::parseEdidString(const quint8 *data)
{
QByteArray buffer(reinterpret_cast<const char *>(data), 13);
- // Erase carriage return and line feed
- buffer = buffer.replace('\r', '\0').replace('\n', '\0');
-
- // Replace non-printable characters with dash
for (int i = 0; i < buffer.size(); ++i) {
+ // If there are less than 13 characters in the string, the string
+ // is terminated with the ASCII code ‘0Ah’ (line feed) and padded
+ // with ASCII code ‘20h’ (space). See EDID 1.4, sections 3.10.3.1,
+ // 3.10.3.2, and 3.10.3.4.
+ if (buffer[i] == '\n') {
+ buffer.truncate(i);
+ break;
+ }
+
+ // Replace non-printable characters with dash
if (buffer[i] < '\040' || buffer[i] > '\176')
buffer[i] = '-';
}
- return QString::fromLatin1(buffer.trimmed());
+ return QString::fromLatin1(buffer);
}
QT_END_NAMESPACE