|
-
September 4th, 2008, 05:30 AM
#1
Stack corruption
I have a following member function prototype.
Code:
Dtk_Int32 ConvertToGeom(Geometric_set_select_entity **res = NULL) const;
If NULL is passed to the above function it returns the size of the output array;
I tried the following sets of code but I am getting stack corruption around the "entity" variable in each case when the function returns. If I remove the code altogether then there is no corruption and everything works fine.
Set 1:
Code:
Dtk_Int32 size = pLeaderPointer->ConvertToGeom(NULL);
Geometric_set_select_entity *entity = new Geometric_set_select_entity[size];
pLeaderPointer->ConvertToGeom(&entity);
Aussuming that I don't have to do the allocation and the function will:
Set 2:
Code:
Geometric_set_select_entity *entity = NULL;
Dtk_Int32 size = pLeaderPointer->ConvertToGeom(&entity);
The corruption again happens.
So I am in a doubt whether I am doing something wrong or the "ConvertToGeom" function is itself buggy.
Please help.
If there is no love sun won't shine
-
September 4th, 2008, 07:18 AM
#2
Re: Stack corruption
What's the documentation on ConvertToGeom say it expects?
-
September 4th, 2008, 07:24 AM
#3
Re: Stack corruption
The documentation is not upto the mark.
Here is what it says:
Dtk_Int32 Dtk_Leader::ConvertToGeom ( Geometric_set_select_entity ** res = NULL ) const
Converts the Dtk_Leader to geometrical elements.
Parameters:
outGeomsArray Geometrical elements array - or NULL -
Returns:
The number of geometrical elements.
Remarks:
If ConvertToGeom is used with NULL parameter, it only retrieves the number of geometrical elements.
And the most frustrating thing is that we don't have any of its usage example
Thanks,
If there is no love sun won't shine
-
September 4th, 2008, 07:52 AM
#4
Re: Stack corruption
The suspicious thing is that the parameter is a **. That, to me, implies either that the function intends to reallocate its argument to size (as you deduced), or that it takes a 2D array. I don't know whether that would make any sense, however.
Do you happen to know if Geometric_set_select_entity is a POD class or not? If so, it's *possible* the function is expecting an array created with malloc, not new. I'd consider that unlikely, but you never know.
-
September 4th, 2008, 08:59 AM
#5
Re: Stack corruption
 Originally Posted by miteshpandey
I tried the following sets of code but I am getting stack corruption around the "entity" variable in each case when the function returns. If I remove the code altogether then there is no corruption and everything works fine.
Set 1:
Code:
Dtk_Int32 size = pLeaderPointer->ConvertToGeom(NULL);
Geometric_set_select_entity *entity = new Geometric_set_select_entity[size];
pLeaderPointer->ConvertToGeom(&entity);
The issue with your code above is that you've only allocated the "rows", and not the columns. It should look similar to the way you build a 2d array of ints or doubles. The problem is that the function doesn't return you the size of each row along with the number of rows.
However, I have never seen a function that takes a "T**", and have the user only allocate the rows alone. All the examples I know of requires the user to build the whole thing, rows and columns (starting with a T**).
You should contact whoever wrote the function to actually provide examples. Just having a "**" parameter doesn't convey any information by itself, as the author thought it intended.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|