Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:34:07+00:00 2026-05-31T05:34:07+00:00

Here is the code I have: #include <iostream> #include <typeinfo.h> typedef struct A {

  • 0

Here is the code I have:

#include <iostream>
#include <typeinfo.h>

typedef struct A
{

friend class W;

private:
        char c;
        void *v;
} A;

typedef struct LL
{

friend class W;

private:
        int n;
        LL *next, *prev;
} LL;

class W
{

private:
        void Handle(void *arg1, void *arg2)
        {
                A *ob1 = reinterpret_cast<A*>(arg1);
                ob1->c = 'c';
                ob1->v = (void*)0xffffffff;

                LL *ob2 = reinterpret_cast<LL*>(arg2);
                ob2->n = 0xff;
                ob2->next = new LL();
                ob2->prev = 0;
        }

protected:
        void Set()
        {
                A *ob1 = new A();
                LL *ob2 = new LL();

                this->Handle(&ob1, &ob2);
        }
};

class R : W
{

public:
        R(void)
        {
                this->Set();
        }
};

void main(void)
{
        R *ob = new R();
}

I’m getting the next result from dump:
Run-Time Check Failure #2 – Stack around the variable ‘ob2’ was corrupted.

‘http.exe’: Loaded ‘C:\Users\root\Documents\Visual Studio 2008\Projects\http\Debug\http.exe’
, Symbols loaded.
‘http.exe’: Loaded ‘C:\Windows\SysWOW64\ntdll.dll’
‘http.exe’: Loaded ‘C:\Windows\SysWOW64\kernel32.dll’
‘http.exe’: Loaded ‘C:\Windows\SysWOW64\KernelBase.dll’
‘http.exe’: Loaded ‘C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcr90d.dll’
Run-Time Check Failure #2 – Stack around the variable ‘ob2’ was corrupted.

My quesions are:
– What should I do to solve this problem?
– Why I have got such error, can you describe me, why its was exaclty corrupted?
– And why the Stack is corrupted? not the heap?

Thanks,
Best regards,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:34:07+00:00Added an answer on May 31, 2026 at 5:34 am
    A *ob1 = new A();
    LL *ob2 = new LL();
    
    this->Handle(&ob1, &ob2);
    

    ob1 and ob2 are already pointers. By taking the addresses of the variables (of types, respectively, A** and LL**), then passing them to Handle where they are hammered into A* and LL* with reinterpret_casts and then written to, the code invokes undefined behaviour. In this particular case it appears to be writing to locations near the ob1 and ob2 variables, which are probably on the stack frame of a call to Set.

    If instead of butchering the type system with reinterpret_cast, the code used it properly, the compiler would have caught the error immediately:

    void Handle(A *arg1, LL *arg2)
    {
            ob1->c = 'c';
            ob1->v = (void*)0xffffffff;
    
            ob2->n = 0xff;
            ob2->next = new LL();
            ob2->prev = 0;
    }
    
    // ...
    // the compiler would complain about this call making the problem clear
    this->Handle(&ob1, &ob2);
    

    It would be even better if the code didn’t use so many pointers all over the place, but I’m going to assume this was just a simple piece of code to demonstrate the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code #include <iostream> using namespace std; class Test{ public: int a;
I have this code: #include <iostream> #include <mp4.h> int main (int argc, char *
i have wrote code for quicksort with linked list ,here is code #include<stdio.h> #include<iostream>
here i have code for calculate hash value of unsigned char #include <cstdlib> #include
Here is my code: #include <iomanip> #include <fstream> #include <iostream> using namespace std; int
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
I have a metafunction: struct METAFUNCION { template<class T> struct apply { typedef T
i have following code #include <iostream> #include <string> using namespace std; string generate(){ for
enter code here I have a table on SQL server 2005 with bigint primary
Here is the code I have to create an UIAlertView with a textbox. UIAlertView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.