Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Crash when using QString and va_list under x86 (x64 works!)
Forum Updated to NodeBB v4.3 + New Features

Crash when using QString and va_list under x86 (x64 works!)

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Justin Sayne
    wrote on last edited by
    #1

    Does anyone have a moderate idea why the following works perfectly fine and as expected under x64 but crashes on the line indicated under x86? Having a look at argp in the debugger, argp already seems wrong because it contains character -52 like 100 times in a row whereas under x64 it has just around 8 reasonable and positive characters.
    Is there a work-around where I possibly don't have to change the method signature?

    #include <QString>
    
    static void test(const QString& format, ...)
    {
      static char msg[2048];
      
      va_list argp;
      va_start(argp, format);
      // crashes here under x86
      vsnprintf(msg, 2048, format.toStdString().c_str(), argp);
      va_end(argp);
      printf("%s", msg);
    }
    
    int main()
    {
      test("teststring: %s", "foobar");
      return 0;
    }
    

    The funny thing is that this also works perfectly fine under both configurations...

    static void test(const char* format, ...)
    {
      static char msg[2048];
      
      va_list argp;
      va_start(argp, format);
      vsnprintf(msg, 2048, format, argp);
      va_end(argp);
      printf("%s", msg);
    }
    
    int main()
    {
      QString qstr = "teststring: %s";
      test(qstr.toUtf8().data(), "foobar");
      return 0;
    }
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      KeithS
      wrote on last edited by
      #2

      You can't pass a reference to the format for va_start(). Use 'const QString format' instead of 'const QString& format'.

      J 1 Reply Last reply
      0
      • K KeithS

        You can't pass a reference to the format for va_start(). Use 'const QString format' instead of 'const QString& format'.

        J Offline
        J Offline
        Justin Sayne
        wrote on last edited by
        #3

        @KeithS
        Wow, thanks. After knowing the keyword I finally found the explanation and it completely makes sense. I'm now just wondering why it worked perfectly fine under x64, and not even by accident because this is a log function of our framework so it's used all over the place.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved