Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Stack Overflow exeception

Stack Overflow exeception

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresdebugging
8 Posts 4 Posters 1 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Im getting a stack over flow execption its not from an ASSERT but storage on my stack frame is corrupted. I have a thread Waitting on event to be notified when a socket read is pending I trace socket number upon entry and its ok I initialize a WSABUF which 15 entires and its fine somewhere when I do the WaitforSingleObject the stack frame gets corrupted I did a data break point on the socket and its was somewhere in UserCallwinprocccheckwow. best to post my code some where in the WaiforSingleObject sonething happens to my stack frame here is the code for notification int ret1 = WSAEventSelect(mysocket, socksevent, FD_READ | FD_CLOSE); here is the createthread struct threadparm thethreads; thethreads.thesocket = mysocket; thethreads.sendwidow = pFrame->m_hWnd; thethreads.messge = WM_STORAGE; thethreads.sockevent = socksevent; struct threadparm* parmptr = &thethreads; HANDLE threadhandle = ::CreateThread(NULL, 0, SocketThread, (LPVOID)parmptr, 0, &threadid); the thread with Waitforsingleobect were somewhere threadptr->thesocket gets corrupted DWORD WINAPI SocketThread(LPVOID lphadleparater) { WSANETWORKEVENTS socknetwork; struct threadparm* threadptr; threadptr = (threadparm *)lphadleparater; WSABUF DataBuf[15]; DWORD recived; int i, j; DWORD flags = 0; WSAOVERLAPPED myoverlap; char* sendcopy = new char[3825]; char* holdptr = sendcopy; j = 0; for (i = 0; i < 15; i++) { DataBuf[i].buf = new char[255]; DataBuf[i].len = 255; } struct _WSABUF* tcpip = &DataBuf[0]; DWORD dwWaitStatus = WaitForSingleObject(threadptr->sockevent, INFINITE);

    switch (dwWaitStatus)
    /* a read is pending */
    case WAIT_OBJECT_0 + 0:
    {
    int return_code = WSAEnumNetworkEvents(threadptr->thesocket, threadptr->sockevent, &socknetwork);

    Greg UtasG Mircea NeacsuM 2 Replies Last reply
    0
    • F ForNow

      Im getting a stack over flow execption its not from an ASSERT but storage on my stack frame is corrupted. I have a thread Waitting on event to be notified when a socket read is pending I trace socket number upon entry and its ok I initialize a WSABUF which 15 entires and its fine somewhere when I do the WaitforSingleObject the stack frame gets corrupted I did a data break point on the socket and its was somewhere in UserCallwinprocccheckwow. best to post my code some where in the WaiforSingleObject sonething happens to my stack frame here is the code for notification int ret1 = WSAEventSelect(mysocket, socksevent, FD_READ | FD_CLOSE); here is the createthread struct threadparm thethreads; thethreads.thesocket = mysocket; thethreads.sendwidow = pFrame->m_hWnd; thethreads.messge = WM_STORAGE; thethreads.sockevent = socksevent; struct threadparm* parmptr = &thethreads; HANDLE threadhandle = ::CreateThread(NULL, 0, SocketThread, (LPVOID)parmptr, 0, &threadid); the thread with Waitforsingleobect were somewhere threadptr->thesocket gets corrupted DWORD WINAPI SocketThread(LPVOID lphadleparater) { WSANETWORKEVENTS socknetwork; struct threadparm* threadptr; threadptr = (threadparm *)lphadleparater; WSABUF DataBuf[15]; DWORD recived; int i, j; DWORD flags = 0; WSAOVERLAPPED myoverlap; char* sendcopy = new char[3825]; char* holdptr = sendcopy; j = 0; for (i = 0; i < 15; i++) { DataBuf[i].buf = new char[255]; DataBuf[i].len = 255; } struct _WSABUF* tcpip = &DataBuf[0]; DWORD dwWaitStatus = WaitForSingleObject(threadptr->sockevent, INFINITE);

      switch (dwWaitStatus)
      /* a read is pending */
      case WAIT_OBJECT_0 + 0:
      {
      int return_code = WSAEnumNetworkEvents(threadptr->thesocket, threadptr->sockevent, &socknetwork);

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #2

      It would be easier to look at your code if it was formatted. However, it isn't obvious to me what's causing your stack overflow. Do you have more code that you're not showing? A stack overflow is caused by too much function call nesting (perhaps because of recursion), too many local variables (usually large arrays), or creating a thread with a smaller stack than it needs (that's the second parameter to CreateThread, and since you're using 0, you're getting Windows' default size, which should be OK).

      Robust Services Core | Software Techniques for Lemmings | Articles
      The fox knows many things, but the hedgehog knows one big thing.

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      F 1 Reply Last reply
      0
      • F ForNow

        Im getting a stack over flow execption its not from an ASSERT but storage on my stack frame is corrupted. I have a thread Waitting on event to be notified when a socket read is pending I trace socket number upon entry and its ok I initialize a WSABUF which 15 entires and its fine somewhere when I do the WaitforSingleObject the stack frame gets corrupted I did a data break point on the socket and its was somewhere in UserCallwinprocccheckwow. best to post my code some where in the WaiforSingleObject sonething happens to my stack frame here is the code for notification int ret1 = WSAEventSelect(mysocket, socksevent, FD_READ | FD_CLOSE); here is the createthread struct threadparm thethreads; thethreads.thesocket = mysocket; thethreads.sendwidow = pFrame->m_hWnd; thethreads.messge = WM_STORAGE; thethreads.sockevent = socksevent; struct threadparm* parmptr = &thethreads; HANDLE threadhandle = ::CreateThread(NULL, 0, SocketThread, (LPVOID)parmptr, 0, &threadid); the thread with Waitforsingleobect were somewhere threadptr->thesocket gets corrupted DWORD WINAPI SocketThread(LPVOID lphadleparater) { WSANETWORKEVENTS socknetwork; struct threadparm* threadptr; threadptr = (threadparm *)lphadleparater; WSABUF DataBuf[15]; DWORD recived; int i, j; DWORD flags = 0; WSAOVERLAPPED myoverlap; char* sendcopy = new char[3825]; char* holdptr = sendcopy; j = 0; for (i = 0; i < 15; i++) { DataBuf[i].buf = new char[255]; DataBuf[i].len = 255; } struct _WSABUF* tcpip = &DataBuf[0]; DWORD dwWaitStatus = WaitForSingleObject(threadptr->sockevent, INFINITE);

        switch (dwWaitStatus)
        /* a read is pending */
        case WAIT_OBJECT_0 + 0:
        {
        int return_code = WSAEnumNetworkEvents(threadptr->thesocket, threadptr->sockevent, &socknetwork);

        Mircea NeacsuM Offline
        Mircea NeacsuM Offline
        Mircea Neacsu
        wrote on last edited by
        #3

        Seems to me the thethreads was allocated on the stack and disappeared by the time thread is executing. As Greg was saying, formatting would be nice.

        Mircea

        F 1 Reply Last reply
        0
        • Greg UtasG Greg Utas

          It would be easier to look at your code if it was formatted. However, it isn't obvious to me what's causing your stack overflow. Do you have more code that you're not showing? A stack overflow is caused by too much function call nesting (perhaps because of recursion), too many local variables (usually large arrays), or creating a thread with a smaller stack than it needs (that's the second parameter to CreateThread, and since you're using 0, you're getting Windows' default size, which should be OK).

          Robust Services Core | Software Techniques for Lemmings | Articles
          The fox knows many things, but the hedgehog knows one big thing.

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          is there a way to determine how much storage my local variables are currently taking maybe an output on the build thanks

          Greg UtasG 1 Reply Last reply
          0
          • Mircea NeacsuM Mircea Neacsu

            Seems to me the thethreads was allocated on the stack and disappeared by the time thread is executing. As Greg was saying, formatting would be nice.

            Mircea

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            you are right about the formatting thethreads is in the stackframe of CWinApp but still you are correct in your point I'll move its thehreads to the class thank you

            1 Reply Last reply
            0
            • F ForNow

              is there a way to determine how much storage my local variables are currently taking maybe an output on the build thanks

              Greg UtasG Offline
              Greg UtasG Offline
              Greg Utas
              wrote on last edited by
              #6

              If there's a compiler option to generate a listing file, that might contain the information. I've never done this in Windows C++, so you'd have to look into it. Another way would be to do this at the top of your function:

              int first;
              // rest of local variables
              int last;

              int size = &last - &first; // distance from first to last local variable
              if(size < 0) size = -size; // depends on how compiler lays out memory
              size -= sizeof(int); // the real size after removing FIRST and LAST

              cout << "This function's locals use " << size << " bytes." << std::endl;

              Robust Services Core | Software Techniques for Lemmings | Articles
              The fox knows many things, but the hedgehog knows one big thing.

              <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
              <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

              F G 2 Replies Last reply
              0
              • Greg UtasG Greg Utas

                If there's a compiler option to generate a listing file, that might contain the information. I've never done this in Windows C++, so you'd have to look into it. Another way would be to do this at the top of your function:

                int first;
                // rest of local variables
                int last;

                int size = &last - &first; // distance from first to last local variable
                if(size < 0) size = -size; // depends on how compiler lays out memory
                size -= sizeof(int); // the real size after removing FIRST and LAST

                cout << "This function's locals use " << size << " bytes." << std::endl;

                Robust Services Core | Software Techniques for Lemmings | Articles
                The fox knows many things, but the hedgehog knows one big thing.

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                Thanks

                1 Reply Last reply
                0
                • Greg UtasG Greg Utas

                  If there's a compiler option to generate a listing file, that might contain the information. I've never done this in Windows C++, so you'd have to look into it. Another way would be to do this at the top of your function:

                  int first;
                  // rest of local variables
                  int last;

                  int size = &last - &first; // distance from first to last local variable
                  if(size < 0) size = -size; // depends on how compiler lays out memory
                  size -= sizeof(int); // the real size after removing FIRST and LAST

                  cout << "This function's locals use " << size << " bytes." << std::endl;

                  Robust Services Core | Software Techniques for Lemmings | Articles
                  The fox knows many things, but the hedgehog knows one big thing.

                  G Offline
                  G Offline
                  Graham Breach
                  wrote on last edited by
                  #8

                  This might not work - the compiler doesn't have to maintain the order of variables on the stack, so last could end up before or after first and the other variables.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups