Opened 11 years ago

Closed 9 years ago

#5043 closed defect (duplicate)

Apparent bug in OGRFieldDefn assignment operator

Reported by: bugpower Owned by: warmerdam
Priority: low Milestone:
Component: OGR_SF Version: 1.9.1
Severity: normal Keywords:
Cc:

Description (last modified by warmerdam)

I haven't researched it deeply, but here's how it looks.

This code works:

static void CreateStandardPolygonFields(OGRLayer *poLayer)
{
	OGRFieldDefn field1("Name", OGRFieldType::OFTString);
	field1.SetWidth(32);
	poLayer->CreateField(&field1);

	OGRFieldDefn field2("Session", OGRFieldType::OFTString);
	field2.SetWidth(128);
	poLayer->CreateField(&field2);

	OGRFieldDefn field3("Time", OGRFieldType::OFTString);
	field3.SetWidth(32);
	poLayer->CreateField(&field3);

	OGRFieldDefn field5("Position stream", OGRFieldType::OFTString);
	field5.SetWidth(32);
	poLayer->CreateField(&field5);

	OGRFieldDefn field6("Area_km2", OGRFieldType::OFTReal);
	poLayer->CreateField(&field6);
}

This one causes heap corruption on return:

static void CreateStandardPolygonFields(OGRLayer *poLayer)
{
	OGRFieldDefn field("Name", OGRFieldType::OFTString);
	field.SetWidth(32);
	poLayer->CreateField(&field);

	field = OGRFieldDefn("Session", OGRFieldType::OFTString);
	field.SetWidth(32);
	poLayer->CreateField(&field);

	field = OGRFieldDefn("Time", OGRFieldType::OFTString);
	field.SetWidth(32);
	poLayer->CreateField(&field);

	field = OGRFieldDefn("Position stream", OGRFieldType::OFTString);
	field.SetWidth(32);
	poLayer->CreateField(&field);

	field = OGRFieldDefn("Area_km2", OGRFieldType::OFTReal);
	poLayer->CreateField(&field);
}

The only difference is recycling the same "field" which should be okay.

Change History (6)

comment:1 by warmerdam, 11 years ago

Component: defaultOGR_SF
Description: modified (diff)

I've never seen something like:

  OGRFieldDefn field(...);

  field = OGRFieldDefn("Area_km2", OGRFieldType::OFTReal); 

before and I can't understand how it is intended to work.

comment:2 by warmerdam, 11 years ago

Resolution: invalid
Status: newclosed

I don't see an action item so I'm closing. Please reopen if you see something that needs to be done.

comment:3 by bugpower, 11 years ago

Resolution: invalid
Status: closedreopened

Explaining.

(if compiles) it is expected to overwrite the existing local with a temporary. From there it should be equivalent. It is not, this is the symptom.

comment:4 by Even Rouault, 11 years ago

Resolution: fixed
Status: reopenedclosed

r26461 "Add copy constructor and assigment operator to OGRFieldDefn (#5043)"

comment:5 by Even Rouault, 11 years ago

Resolution: fixed
Status: closedreopened

r26462 "Revert r26461 since it causes crashes on Windows, because the default assigment operator that does bit-to-bit copy is used instead of our specialized version, for some unknown reason... (#5043)"

comment:6 by Even Rouault, 9 years ago

Resolution: duplicate
Status: reopenedclosed

Dealt by #6100 (explicitly disabling copy constructor and assigment operator)

Note: See TracTickets for help on using tickets.