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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:39:52+00:00 2026-05-26T15:39:52+00:00

The folowing function code: void add_edge(int** point, int start, int end) { int x;

  • 0

The folowing function code:

void add_edge(int** point, int start, int end)
{   

int x;

//start->end edge
x=point[start][0];
if(x>=2)        
{
    int* temp=new int[x+1];
    for(int i=0; i<=x; i++)
        temp[i]=point[start][i];
//  delete[] point[start];
    point[start]=temp;
}
point[start][++point[start][0]]=end;

if(start==end) return;

//end->start edge
x=point[end][0];
if(x>=2)
{
    int* temp=new int[x+1];
    for(int i=0; i<=x; i++)
        temp[i]=point[end][i];
//  delete[] point[end];
    point[end]=temp;
}
point[end][++point[end][0]]=start;
}

has a memory allocation error which I cannot find.

From valgrind I get this:

==9253== Invalid write of size 4
==9253==    at 0x8048643: add_edge(int**, int, int) (c1.cpp:34) (line: point[start][++point[start][0]]=end;)
==9253==    by 0x8048C8B: main (c1.cpp:184) (line:          add_edge(point,start,end); )
==9253==  Address 0x2d6a7074 is 0 bytes after a block of size 12 alloc'd
==9253==    at 0x4025FE5: operator new[](unsigned int) (vg_replace_malloc.c:299)
==9253==    by 0x80485D0: add_edge(int**, int, int) (c1.cpp:28)
==9253==    by 0x8048C8B: main (c1.cpp:184)
==9253== 
==9253== Invalid write of size 4
==9253==    at 0x80486EA: add_edge(int**, int, int) (c1.cpp:48) (line:  point[end][++point[end][0]]=start; )
==9253==    by 0x8048C8B: main (c1.cpp:184)
==9253==  Address 0x2d6a7134 is 0 bytes after a block of size 12 alloc'd
==9253==    at 0x4025FE5: operator new[](unsigned int) (vg_replace_malloc.c:299)
==9253==    by 0x8048677: add_edge(int**, int, int) (c1.cpp:42)
==9253==    by 0x8048C8B: main (c1.cpp:184)
==9253== 
--9253-- REDIR: 0x41e07c0 (__GI_strlen) redirected to 0x4026ccc (__GI_strlen)
  • 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-26T15:39:53+00:00Added an answer on May 26, 2026 at 3:39 pm

    If I understand your uncommented code correctly, the first element of each subarray describes the number of following elements. It also looks like you are trying to grow the subarray by one element. If that is the case you need new int[x+2] (1 for growth, and 1 for the length field).

    However, please find a cleaner way to write your code; point[start][++point[start][0]]is grotesque!

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

Sidebar

Related Questions

I have something analogous to the following code... void function(int x) { // complicated
I have a question about the following C code: void my_function() { int i1;
I have the following bit of code: protected function onEnterFrame(e:Event):void { var diff:Number; //
In the following code, g++ gives this error : 1.cpp: In member function void
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
I' m trying to enable adding/deleting rows to/from table using folowing code: Script: $(document).ready(function()
Consider the following base code: (function($) { $.fn.myPlugin = function(settings) { return this.each(function() {
If I have a function void Foo(params int[] bar){} The following runs fine: int[]
Say I have the following code: function One() {} One.prototype.x = undefined; function Two()
I am creating several image dynamically using the following code: function refresh_gallery(galleryidentifier, albumid) {

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.