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

  • Home
  • SEARCH
  • 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 6391631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:43:00+00:00 2026-05-25T03:43:00+00:00

I’m working on an existing data parsing program that overlays a struct onto a

  • 0

I’m working on an existing data parsing program that overlays a struct onto a buffer in order to extract values. Recently a new data format has been added to the buffer and requires a new struct. I abstracted functions into a common base class and defined a new struct like this:

struct Header
{
    Header () { }

public:
    virtual unsigned __int8 getCommonField1() const = 0;
}

struct HeaderTypeA : public Header
{
    unsigned __int8 Field1;

public:
    unsigned __int8 getCommonField1() const { return Field1; }
}

struct HeaderTypeB : public Header
{
    unsigned __int8 Field0;
    unsigned __int8 Field1;

public:
    unsigned __int8 getCommonField1() const { return Field1; }
}

The existing code which does the processing evaluates the data (this is working) and returns a pointer to the calling function… something like this:

Header* parse()
{    
    Header* parsedHeader = 0;

    if (typeADetected)
    {
        parsedHeader = (HeaderTypeA *) &buffer[offset];
        // Other logic here...
    }
    else if (typeBDetected)
    {
        parsedHeader = (HeaderTypeB *) &buffer[offset];
        // Other logic here...
    }

    return (parsedHeader);
}

The problem arises in the caller of the parsing logic. When the header is returned as a pointer the calls to the member functions result in an access violation error:

Header * hdr;
hdr = m_parser->parse();
unsigned __int8 value = hdr->getCommonField1(); // Access Violation

I realize the snippet above is missing null pointer checks; I have excluded some of that logic for brevity. I’ve traced the code through and everything appears to be running smoothly until an attempt is made to call a method on the base class. In playing around with the code, I’ve also seen member function not present errors.

Thanks for any help.

  • 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-25T03:43:01+00:00Added an answer on May 25, 2026 at 3:43 am

    You seem to be using the memory in buffer without constructing an object there. Since Header is polymorphic it contains a virtual table pointer and you can’t initialize its data directly (legally you can’t even if it’s a POD but you would probably get away with it).

    You should be using placement new in order to construct the Header object in buffer.

     parsedHeader = new (&buffer[offset]) HeaderTypeA;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an XML file, the creators of it stuck in a bunch social
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.