Don't use qstrlen if string is not null

Change-Id: I4f9aec21af2ce24a1d27c6d140764e371bce5017
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
This commit is contained in:
João Abecasis 2012-03-31 01:27:27 +02:00 committed by Qt by Nokia
parent ccf25f1d28
commit 97f251b8c3

View File

@ -131,7 +131,7 @@ char *qstrcpy(char *dst, const char *src)
if (!src) if (!src)
return 0; return 0;
#if defined(_MSC_VER) && _MSC_VER >= 1400 #if defined(_MSC_VER) && _MSC_VER >= 1400
int len = qstrlen(src); int len = strlen(src);
// This is actually not secure!!! It will be fixed // This is actually not secure!!! It will be fixed
// properly in a later release! // properly in a later release!
if (len >= 0 && strcpy_s(dst, len+1, src) == 0) if (len >= 0 && strcpy_s(dst, len+1, src) == 0)
@ -916,7 +916,7 @@ QByteArray &QByteArray::operator=(const char *str)
} else if (!*str) { } else if (!*str) {
x = const_cast<Data *>(&shared_empty.ba); x = const_cast<Data *>(&shared_empty.ba);
} else { } else {
int len = qstrlen(str); int len = strlen(str);
if (d->ref.isShared() || len > int(d->alloc) || (len < d->size && len < int(d->alloc) >> 1)) if (d->ref.isShared() || len > int(d->alloc) || (len < d->size && len < int(d->alloc) >> 1))
realloc(len); realloc(len);
x = d; x = d;
@ -1650,7 +1650,7 @@ QByteArray &QByteArray::append(const QByteArray &ba)
QByteArray& QByteArray::append(const char *str) QByteArray& QByteArray::append(const char *str)
{ {
if (str) { if (str) {
int len = qstrlen(str); int len = strlen(str);
if (d->ref.isShared() || d->size + len > int(d->alloc)) if (d->ref.isShared() || d->size + len > int(d->alloc))
realloc(qAllocMore(d->size + len, sizeof(Data))); realloc(qAllocMore(d->size + len, sizeof(Data)));
memcpy(d->data() + d->size, str, len + 1); // include null terminator memcpy(d->data() + d->size, str, len + 1); // include null terminator
@ -2534,7 +2534,7 @@ bool QByteArray::startsWith(const char *str) const
{ {
if (!str || !*str) if (!str || !*str)
return true; return true;
int len = qstrlen(str); int len = strlen(str);
if (d->size < len) if (d->size < len)
return false; return false;
return qstrncmp(d->data(), str, len) == 0; return qstrncmp(d->data(), str, len) == 0;
@ -2579,7 +2579,7 @@ bool QByteArray::endsWith(const char *str) const
{ {
if (!str || !*str) if (!str || !*str)
return true; return true;
int len = qstrlen(str); int len = strlen(str);
if (d->size < len) if (d->size < len)
return false; return false;
return qstrncmp(d->data() + d->size - len, str, len) == 0; return qstrncmp(d->data() + d->size - len, str, len) == 0;