Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8374

QUuid::createUuid() is not unique per-process (based on qsrand())

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 4.7.0
    • 4.6.0, 4.6.1, 4.6.2
    • Core: Plugins
    • None

    Description

      If the following program is run on the same box twice within the same second, then the same UUID returned.
      ---------------------------
      #include <stdio.h>
      #include <QUuid>
      int main(int argc, char *argv[]) {
      fprintf(stdout, "%s\n", qPrintable(QUuid::createUuid().toString()));
      return 0;
      }
      ----------------------------
      The reason for this is that qsrand() (not qsrand(int)) in 4.6.x in src/corelib/global/qglobal.cpp doesn't distinguish on something that is process specific. It has time-specific & thread-specific (thanks to QTBUG-3543) descrimination, but not process-specific.

      To fix this, for both Unix & Windows, it should be as simple as adding in the process ID of the current process:
      Unix: + quint32(getpid())
      Windows: + quint32(GetCurrentProcessId())

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bhughes Bradley T. Hughes (closed Nokia Identity) (Inactive)
            dbroady1 Darin Broady
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes