title: Valgrind invalid read and segmentation fault with QApplication
body: <p>I'm stuck with run-time errors in my Qt application. This is part of my Valgrind output. There is more before it but it is a lot to post.</p>
  
  <pre><code>==13659== Invalid read of size 8
  ==13659==    at 0x75E4085: QCoreApplication::arguments() (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x1B4E0114: ??? (in /usr/local/Qt/5.2.1/gcc_64/plugins/platforms/libqxcb.so)
  ==13659==    by 0x1B4E10E8: ??? (in /usr/local/Qt/5.2.1/gcc_64/plugins/platforms/libqxcb.so)
  ==13659==    by 0x1B9C0D2E: _SmcProcessMessage (in /usr/lib/x86_64-linux-gnu/libSM.so.6.0.1)
  ==13659==    by 0x1BBD48A5: IceProcessMessages (in /usr/lib/x86_64-linux-gnu/libICE.so.6.3.0)
  ==13659==    by 0x76096B0: QMetaObject::activate(QObject*, int, int, void**) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x767B1FD: QSocketNotifier::activated(int, QSocketNotifier::QPrivateSignal) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x7616840: QSocketNotifier::event(QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x65D20F3: QApplicationPrivate::notify_helper(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Widgets.so.5.2.1)
  ==13659==    by 0x65D56AD: QApplication::notify(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Widgets.so.5.2.1)
  ==13659==    by 0x75E0733: QCoreApplication::notifyInternal(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x7630A55: ??? (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==  Address 0x178ddfb0 is 0 bytes after a block of size 16 alloc'd
  ==13659==    at 0x4C28147: operator new[](unsigned long) (vg_replace_malloc.c:348)
  ==13659==    by 0x4FAD41: GUIApp::init() (GUIApp.cpp:73)
  ==13659==    by 0x423009: main (main.cpp:121)
  ==13659== 
  ==13659== Invalid read of size 1
  ==13659==    at 0x4C294E2: strlen (mc_replace_strmem.c:390)
  ==13659==    by 0x75E409B: QCoreApplication::arguments() (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x1B4E0114: ??? (in /usr/local/Qt/5.2.1/gcc_64/plugins/platforms/libqxcb.so)
  ==13659==    by 0x1B4E10E8: ??? (in /usr/local/Qt/5.2.1/gcc_64/plugins/platforms/libqxcb.so)
  ==13659==    by 0x1B9C0D2E: _SmcProcessMessage (in /usr/lib/x86_64-linux-gnu/libSM.so.6.0.1)
  ==13659==    by 0x1BBD48A5: IceProcessMessages (in /usr/lib/x86_64-linux-gnu/libICE.so.6.3.0)
  ==13659==    by 0x76096B0: QMetaObject::activate(QObject*, int, int, void**) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x767B1FD: QSocketNotifier::activated(int, QSocketNotifier::QPrivateSignal) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x7616840: QSocketNotifier::event(QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x65D20F3: QApplicationPrivate::notify_helper(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Widgets.so.5.2.1)
  ==13659==    by 0x65D56AD: QApplication::notify(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Widgets.so.5.2.1)
  ==13659==    by 0x75E0733: QCoreApplication::notifyInternal(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==  Address 0x50 is not stack'd, malloc'd or (recently) free'd
  ==13659== 
  ==13659== 
  ==13659== Process terminating with default action of signal 11 (SIGSEGV)
  ==13659==  Access not within mapped region at address 0x50
  ==13659==    at 0x4C294E2: strlen (mc_replace_strmem.c:390)
  ==13659==    by 0x75E409B: QCoreApplication::arguments() (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x1B4E0114: ??? (in /usr/local/Qt/5.2.1/gcc_64/plugins/platforms/libqxcb.so)
  ==13659==    by 0x1B4E10E8: ??? (in /usr/local/Qt/5.2.1/gcc_64/plugins/platforms/libqxcb.so)
  ==13659==    by 0x1B9C0D2E: _SmcProcessMessage (in /usr/lib/x86_64-linux-gnu/libSM.so.6.0.1)
  ==13659==    by 0x1BBD48A5: IceProcessMessages (in /usr/lib/x86_64-linux-gnu/libICE.so.6.3.0)
  ==13659==    by 0x76096B0: QMetaObject::activate(QObject*, int, int, void**) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x767B1FD: QSocketNotifier::activated(int, QSocketNotifier::QPrivateSignal) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x7616840: QSocketNotifier::event(QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==    by 0x65D20F3: QApplicationPrivate::notify_helper(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Widgets.so.5.2.1)
  ==13659==    by 0x65D56AD: QApplication::notify(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Widgets.so.5.2.1)
  ==13659==    by 0x75E0733: QCoreApplication::notifyInternal(QObject*, QEvent*) (in /usr/local/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5.2.1)
  ==13659==  If you believe this happened as a result of a stack
  ==13659==  overflow in your program's main thread (unlikely but
  ==13659==  possible), you can try to increase the size of the
  ==13659==  main thread stack using the --main-stacksize= flag.
  ==13659==  The main thread stack size used in this run was 8388608.
  </code></pre>
  
  <p>I am <code>porting code Qt3 to Qt5 and from 32-bit to 64-bit.</code> Line 73 in my code below is <code>test = new char*[2];</code>. </p>
  
  <p>My program seems to crash with segmentation fault on the <code>showFullScreen()</code> call.</p>
  
  <p>Could the use of the variable <code>test</code> be the cause of the Valgrind output and of the program crash? Is the form of argc and argv on 64-bit Linux the same as 32-bit?</p>
  
  <pre><code>void GUIApp::init()
  {
      QApplication::setStyle("motif");
  
      int nbrparams=1;
      test = new char*[2];
      test[0] = new char[100];
      test[1] = new char[100];
          printf("  Test : %d\n", (int)sizeof test );     //   Test : 8
          printf(" *Test : %d\n", (int)sizeof *test );    //  *Test : 8
          printf("**Test : %d\n", (int)sizeof **test );   // **Test : 1
      strcpy(test[0], "gv_GUI");
  
      go_app = new QApplication( nbrparams,test );
  
      translator = new QTranslator( 0 );
      // load translation file, make sure that this symbolic link points to the desired translation file
      if (translator-&gt;load("tt2_go.qm")) {
          go_app-&gt;installTranslator( translator );
      }
  
      gaw = new GO_QT_Application_Widget( GO_GUI_MODE, mytalkbackptr, NULL, "QTApp");
      gaw-&gt;init();
      gaw-&gt;startup();
  
      gaw-&gt;move(0,0);
      gaw-&gt;setFixedSize(3200,1200);
      gaw-&gt;showFullScreen();
  
      init_done = true;
  }
  </code></pre>