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 8964989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:42:49+00:00 2026-06-15T16:42:49+00:00

I have this code for filling a table but I keep getting a segmentation

  • 0

I have this code for filling a table but I keep getting a segmentation error. I’m at my wit’s end trying to find what the error could be. My function takes in 2 maps and iterates through them to find the common strings. It takes the int value of these commons strings and puts it in a table to count the number of times there are common strings.

myMap findTable(mapGraph * dbgraph1, mapGraph * dbgraph2)
{
typedef mapGraph::const_iterator iter;
typedef myMap::const_iterator mapiter;

iter it1 = dbgraph1->begin();
iter it2 = dbgraph2->begin();
int count =0;
myMap * newTable = NULL;

//iterating through the 2 samples of dbgraphs
while (it1 != dbgraph1->end() && it2 != dbgraph2->end())
{
    //a match is found for 2 strings
    if (it1->first == it2->first)
    {
        //the component ids of first sample
        int compdb1 = it1->second->comp;

        //the component ids of second sample
        int compdb2 = it2->second->comp;

        //inserting the component ids and counts in the map
        newTable->insert(make_pair(make_pair(compdb1, compdb2), count));
        count++;

        for (mapiter it = newTable->begin(); it != newTable->end(); it++)
        {
            printf("%i %i\t %i\n", it->first.first, it->first.second, it->second);
        }

        it1++;
        it2++;

    }

    //match not found
    else
        it1++;
        it2++;

}
printf("\nCLEAR\n");
return newTable;
}

This is the error:

Address 0x10 is not stack'd, malloc'd or (recently) free'd
Invalid read of size 8
Process terminating with default action of signal 11 (SIGSEGV)
Access not within mapped region at address 0x10
  • 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-06-15T16:42:50+00:00Added an answer on June 15, 2026 at 4:42 pm

    newTable is NULL:

    myMap * newTable = NULL;
    

    and is never assigned to a valid object before:

    newTable->insert(make_pair(make_pair(compdb1, compdb2), count));
    

    Dereferencing a NULL pointer is undefined behaviour. Either dynamicaly allocate a myMap instance for newTable:

    myMap* newTable = new myMap(); // Remember to delete later.
    

    or use a stack allocated instance:

    myMap newTable;
    

    This is an error:

    //match not found
        else
            it1++;
            it2++;
    

    resulting in it2 being incremented on every iteration of the loop and will result in ++ being called on an end() iterator. Change to:

    //match not found
        else
        {
            it1++;
            it2++;
        }
    

    Or to simplify the code just increment the iterators at one place in the loop as they are incremented always (in each branch of the if\else).

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

Sidebar

Related Questions

So I have this piece of code, and let's assume I'm filling out a
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
I have this code: ie1.link(:text, /Exception:/) It is producing an error message which I
I have written this code to make a binary file of float numbers, but
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code for changing the image of a button: - (void)mouseEntered:(NSEvent *)event
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>
I have this code: EditText value = ( EditText )findViewById( R.id.editbox ); Integer int_value
I have this code: def __init__(self, a, b, c, d...): self.a = a self.b

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.