OSDN Git Service

correct the buffer size in qRandomUuid() function
authorIvailo Monev <xakepa10@gmail.com>
Tue, 1 Nov 2022 07:39:49 +0000 (09:39 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 1 Nov 2022 07:39:49 +0000 (09:39 +0200)
the initial implementation was not passing the buffer size to the
QByteArray constructor so the additional bit was for qstrlen()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/tools/qbytearray.cpp

index e1d374a..a6cc250 100644 (file)
@@ -263,7 +263,7 @@ QByteArray qRandomUuid()
     uuidbuf[bufi + 1] = tohex[randombuf[randi] & 0xf];
 
     static const char tohex[] = "0123456789abcdef";
-    QSTACKARRAY(char, uuidbuf, 37);
+    QSTACKARRAY(char, uuidbuf, 36);
     UUID_TOHEX(0, 0);
     UUID_TOHEX(2, 1);
     UUID_TOHEX(4, 2);
@@ -1195,7 +1195,7 @@ QByteArray::QByteArray(int size, char ch)
     if (size <= 0) {
         d = &shared_null;
     } else {
-        d = static_cast<Data *>(::malloc(sizeof(Data)+size));
+        d = static_cast<Data *>(::malloc(sizeof(Data) + size));
         Q_CHECK_PTR(d);
         d->ref = 0;
         d->alloc = d->size = size;