Commit 09f77930 authored by Friedemann Kleint's avatar Friedemann Kleint

Debugger: Do not use C99 types for pointers in sprintf() formats.

Pointer fit into long or long long (Win64).
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
parent 224bae15
......@@ -57,16 +57,6 @@
#include <QtCore/QTextStream>
#include <QtCore/QVector>
#ifndef Q_OS_WIN
# include <stdint.h>
#endif
#if (QT_POINTER_SIZE==4) // How to printf/scanf a pointer (uintptr_t)
# define POINTER_PRINTFORMAT "0x%x"
#else
# define POINTER_PRINTFORMAT "0x%lx"
#endif
#ifndef QT_BOOTSTRAPPED
#include <QtCore/QModelIndex>
......@@ -641,7 +631,9 @@ QDumper &QDumper::put(int i)
QDumper &QDumper::put(const void *p)
{
if (p) {
pos += sprintf(outBuffer + pos, POINTER_PRINTFORMAT, reinterpret_cast<uintptr_t>(p));
// Pointer is 'long long' on WIN_64, only
static const char *printFormat = sizeof(quintptr) == sizeof(long) ? "0x%lx" : "0x%llx";
pos += sprintf(outBuffer + pos, printFormat, reinterpret_cast<uintptr_t>(p));
} else {
pos += sprintf(outBuffer + pos, "<null>");
}
......@@ -1074,7 +1066,9 @@ static void qDumpQAbstractItem(QDumper &d)
ModelIndex *mm = reinterpret_cast<ModelIndex *>(&mi);
mm->r = mm->c = 0;
mm->p = mm->m = 0;
sscanf(d.templateParameters[0], "%d,%d,"POINTER_PRINTFORMAT","POINTER_PRINTFORMAT, &mm->r, &mm->c,
static const char *printFormat = sizeof(quintptr) == sizeof(long) ?
"%d,%d,0x%lx,0x%lx" : "%d,%d,0x%llx,0x%llx";
sscanf(d.templateParameters[0], printFormat, &mm->r, &mm->c,
reinterpret_cast<uintptr_t*>(&mm->p), reinterpret_cast<uintptr_t*>(&mm->m));
}
const QAbstractItemModel *m = mi.model();
......@@ -2152,10 +2146,14 @@ static void qDumpQVariantHelper(const QVariant *v, QString *value,
break;
#endif
default: {
static const char *qTypeFormat = sizeof(quintptr) == sizeof(long) ?
"'"NS"%s "NS"qVariantValue<"NS"%s >'(*('"NS"QVariant'*)0x%lx)" :
"'"NS"%s "NS"qVariantValue<"NS"%s >'(*('"NS"QVariant'*)0x%llx)";
static const char *nonQTypeFormat = sizeof(quintptr) == sizeof(long) ?
"'%s "NS"qVariantValue<%s >'(*('"NS"QVariant'*)0x%lx)" :
"'%s "NS"qVariantValue<%s >'(*('"NS"QVariant'*)0x%llx)";
char buf[1000];
const char *format = (v->typeName()[0] == 'Q')
? "'"NS"%s "NS"qVariantValue<"NS"%s >'(*('"NS"QVariant'*)"POINTER_PRINTFORMAT")"
: "'%s "NS"qVariantValue<%s >'(*('"NS"QVariant'*)"POINTER_PRINTFORMAT")";
const char *format = (v->typeName()[0] == 'Q') ? qTypeFormat : nonQTypeFormat;
qsnprintf(buf, sizeof(buf) - 1, format, v->typeName(), v->typeName(), v);
*exp = QLatin1String(buf);
*numchild = 1;
......
......@@ -10,11 +10,10 @@
#include <QtTest/QtTest>
//#include <QtTest/qtest_gui.h>
#if (QT_POINTER_SIZE==4)
# define POINTER_PRINTFORMAT "0x%x"
#else
# define POINTER_PRINTFORMAT "0x%lx"
#endif
static const char *pointerPrintFormat()
{
return sizeof(quintptr) == sizeof(long) ? "0x%lx" : "0x%llx";
}
#undef NS
#ifdef QT_NAMESPACE
......@@ -393,7 +392,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert
extraInt0, extraInt1, extraInt2, extraInt3);
QString expected(expected0);
char buf[100];
sprintf(buf, POINTER_PRINTFORMAT, (uintptr_t)data);
sprintf(buf, pointerPrintFormat(), (uintptr_t)data);
if ((!expected.startsWith('t') && !expected.startsWith('f'))
|| expected.startsWith("type"))
expected = "tiname='$I',addr='$A'," + expected;
......@@ -423,7 +422,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert
QByteArray str(const void *p)
{
char buf[100];
sprintf(buf, POINTER_PRINTFORMAT, (uintptr_t)p);
sprintf(buf, pointerPrintFormat(), (uintptr_t)p);
return buf;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment