QNetworkInterface: remove a use of (native) sprintf

Instead of using sprintf (and #ifdef'ing our way around Windows warnings),
simply do the conversion from uchar to hex digits ourselves, using
QtMiscUtils.

Also used the Qt::Uninitialized QString ctor, as the result length is
exactly known ahead of time.

Change-Id: Ie42e5f11c608e7719f7dc33d72739c1e41901b3b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2015-01-23 09:59:24 +01:00
parent 575029f09b
commit 63114f4d3c
1 changed files with 7 additions and 10 deletions

View File

@ -36,6 +36,7 @@
#include "qdebug.h"
#include "qendian.h"
#include "private/qtools_p.h"
#ifndef QT_NO_NETWORKINTERFACE
@ -116,18 +117,14 @@ QList<QSharedDataPointer<QNetworkInterfacePrivate> > QNetworkInterfaceManager::a
QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data)
{
QString result;
const int outLen = qMax(len * 2 + (len - 1) * 1, 0);
QString result(outLen, Qt::Uninitialized);
QChar *out = result.data();
for (int i = 0; i < len; ++i) {
if (i)
result += QLatin1Char(':');
char buf[3];
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400
sprintf_s(buf, 3, "%02hX", ushort(data[i]));
#else
sprintf(buf, "%02hX", ushort(data[i]));
#endif
result += QLatin1String(buf);
*out++ = QLatin1Char(':');
*out++ = QLatin1Char(QtMiscUtils::toHexUpper(data[i] / 16));
*out++ = QLatin1Char(QtMiscUtils::toHexUpper(data[i] % 16));
}
return result;
}