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. local string always corrupt
QtWS25 Last Chance

local string always corrupt

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 6 Posters 3.2k Views
  • 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.
  • rohit713R rohit713

    @ambershark yes its work fine in qt 5 but my problem occur in qt 4 .ijl is coruupetd debugger shows the locale value not accesible while we copy this to pr its crash .

    jsulmJ Online
    jsulmJ Online
    jsulm
    Lifetime Qt Champion
    wrote on last edited by jsulm
    #11

    @rohit713 As @Christian-Ehrlicher said: you implemented a nice example for stack overflow :-)
    You should use strncpy.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    aha_1980A rohit713R 2 Replies Last reply
    1
    • jsulmJ jsulm

      @rohit713 As @Christian-Ehrlicher said: you implemented a nice example for stack overflow :-)
      You should use strncpy.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #12

      @jsulm

      Even better: qstrncpy ;)

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • jsulmJ jsulm

        @rohit713 As @Christian-Ehrlicher said: you implemented a nice example for stack overflow :-)
        You should use strncpy.

        rohit713R Offline
        rohit713R Offline
        rohit713
        wrote on last edited by
        #13

        @jsulm i also tried strncpy but the same problem occurs .

        jsulmJ 1 Reply Last reply
        0
        • rohit713R rohit713

          @jsulm i also tried strncpy but the same problem occurs .

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #14

          @rohit713 Can you show how you used strncpy?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          rohit713R 2 Replies Last reply
          0
          • jsulmJ jsulm

            @rohit713 Can you show how you used strncpy?

            rohit713R Offline
            rohit713R Offline
            rohit713
            wrote on last edited by
            #15
            This post is deleted!
            1 Reply Last reply
            0
            • jsulmJ jsulm

              @rohit713 Can you show how you used strncpy?

              rohit713R Offline
              rohit713R Offline
              rohit713
              wrote on last edited by rohit713
              #16

              @jsulm strncpy(pr,ijl.toLocal8Bit().data(),ijl.length());

              jsulmJ aha_1980A 2 Replies Last reply
              0
              • rohit713R rohit713

                @jsulm strncpy(pr,ijl.toLocal8Bit().data(),ijl.length());

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #17

                @rohit713 This is same stack overflow as before...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                rohit713R 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @rohit713 This is same stack overflow as before...

                  rohit713R Offline
                  rohit713R Offline
                  rohit713
                  wrote on last edited by rohit713
                  #18

                  @jsulm can u share the stack overflow link

                  jsulmJ A 2 Replies Last reply
                  0
                  • rohit713R rohit713

                    @jsulm can u share the stack overflow link

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #19

                    @rohit713 What link? Think about what will happen if ijl.toLocal8Bit().data() is longer than pr.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • rohit713R rohit713

                      @jsulm strncpy(pr,ijl.toLocal8Bit().data(),ijl.length());

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #20

                      @rohit713

                      Use qstrncpy(pr, ijl.toLocal8Bit().constData(),sizeof(pr));

                      Qt has to stay free or it will die.

                      rohit713R 1 Reply Last reply
                      2
                      • aha_1980A aha_1980

                        @rohit713

                        Use qstrncpy(pr, ijl.toLocal8Bit().constData(),sizeof(pr));

                        rohit713R Offline
                        rohit713R Offline
                        rohit713
                        wrote on last edited by
                        #21

                        @aha_1980 same problem occur with qstrncpy.

                        jsulmJ 1 Reply Last reply
                        0
                        • rohit713R rohit713

                          @aha_1980 same problem occur with qstrncpy.

                          jsulmJ Online
                          jsulmJ Online
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #22

                          @rohit713 So, you used exactly this line:

                          qstrncpy(pr, ijl.toLocal8Bit().constData(),sizeof(pr));
                          

                          ?
                          Use debugger and step by step execution to see what happens.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2
                          • rohit713R rohit713

                            @jsulm can u share the stack overflow link

                            A Offline
                            A Offline
                            ambershark
                            wrote on last edited by ambershark
                            #23

                            @rohit713 said in local string always corrupt:

                            @jsulm can u share the stack overflow link

                            Lol he means an actual stack overflow, i.e. you have the potential for overrunning the memory in your buffer with how you used strcpy and strncpy. Not stackoverflow.com the website. ;)

                            You also don't leave room for the null terminator (or copy it). So you're resulting string if used in any string function is almost guaranteed to crash, at least in release mode. I don't think either of these are your actual issue though.

                            before strcpy it contain "risk" after calling strcpy it gives not accesible.

                            What does that mean? What gives not accessible? The debugger? If it was truly not accessible then it would cause a crash. After it's "not accessible" can you output it via qdebug? My guess here is QString is just reallocating it's internal memory and you are now watching the wrong memory location.

                            If you could show us the backtrace from the crash log that would help. Like I said I tested the code and it worked. I realize Qt5 is different that 4, but that string memory should be good during your copy even in Qt4. It worked in 5 I suspect if I had easy access to Qt4 it would work there too. Can you give us more information on what the actual problem is? "Not accessible" doesn't mean much.

                            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                            1 Reply Last reply
                            5

                            • Login

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