Menu

char[] to wxString crushes on assert failure

wxD
Rommi
2009-02-10
2013-05-22
  • Rommi

    Rommi - 2009-02-10

    On wxd compiled with ansi (haven't tested with unicode) this code will crush an application with wxWidgets assertion failure:

    new StaticText(this, std.string.toString(0));

    Meanwhile this will not:

    new StaticText(this, std.string.toString(0) ~ '\0');

    As I understand, it crushes in wxc/common.h in class dstr on operator wxString.

     
    • Anders F Björklund

      can't reproduce with UNICODE, will need to try with ANSI

       
      • Rommi

        Rommi - 2009-02-11

        That should be because of different implementations of that function for UNICODE and ANSI. By the way, it is crushing under Windows. Under Linux I am using it with UNICODE.

         
        • Anders F Björklund

          testing with wxWidgets 2.6.4 ANSI (on Linux), it is normally using wxWidgets 2.8.9 UNICODE

          maybe the wxWidgets UTF-8 support code is broken on Windows and needs a workaround ?

           
          • Rommi

            Rommi - 2009-02-11

            Probably. It throws an exception from wxWidgets-2.6.4/src/common/strconv.cpp line 240. And this line is something interesting (especially it's comment):

            wxASSERT(szPos < szEnd); //something is _really_ screwed up if this rings true

             
            • Rommi

              Rommi - 2009-02-11

              Aha! I believe it has a bug and expects line to be \0 terminated.

              On strconv.cpp:243 it (as the comment says) tries to determine a length of a substring by sending a char* to MB2WC function, which has a while loop (strconv.cpp:444) on this char* checking that it's value is not zero and incrementing it.

               
              • Rommi

                Rommi - 2009-02-11

                I am not sure that this is only wxWidgets on Windows bug. I believe that it exists on Linux to, and the fact that is worked for you is just a matter of luck (there could be a spontaneous \0 in the RAM).

                 
                • Anders F Björklund

                  No, seems like it crashes on Linux too, when running in the old ANSI mode.

                  Will need to come up with something else to convert UTF-8 to wxString...

                   
              • Anders F Björklund

                terminated the input string now, by making yet another copy...

                 

Log in to post a comment.