Problems with a std::vector (begin and end): Different behavior debug and release version

H

Hans Stoessel

Windows XP / Visual Studio 2005
-----------------------------------

Hi

This is a code piece from an automatic generated C++ file in gSOAP:

SOAP_FMAC3 int SOAP_FMAC4 soap_out_std__vectorTemplateOfstd__string(struct
soap *soap, const char *tag, int id, const std::vector<std::string >*a,
const char *type)
{
for (std::vector<std::string >::const_iterator i = a->begin(); i !=
a->end(); ++i)
{
if (soap_out_std__string(soap, tag, id, &(*i), ""))
return soap->error;
}
return SOAP_OK;
}

I have a different behaviors in the debug and release version of the
application! The vector contains one element.

DEBUG:
The for loop is called one time, as it should be.

RELEASE:
The for loop is NEVER called, because the iterator i is a->end().

I have no idea why. I detect this with log files.

Interesting is the follow: I tried to reproduce this behavior in my own
code. The behavior in my code is correct, in the release and in the debug
version.

Any ideas?
A comiler option?
An include?

Thanks for any hints.
Hans
 
A

Alf P. Steinbach

* Hans Stoessel:
Windows XP / Visual Studio 2005
-----------------------------------

Hi

This is a code piece from an automatic generated C++ file in gSOAP:

SOAP_FMAC3 int SOAP_FMAC4 soap_out_std__vectorTemplateOfstd__string(struct
soap *soap, const char *tag, int id, const std::vector<std::string >*a,
const char *type)
{
for (std::vector<std::string >::const_iterator i = a->begin(); i !=
a->end(); ++i)
{
if (soap_out_std__string(soap, tag, id, &(*i), ""))
return soap->error;
}
return SOAP_OK;
}

Arguments that aren't used, and passing by pointer instead of by reference,
indicates less than brilliance on the part of the programmer who wrote the
template for this generated code.

I have a different behaviors in the debug and release version of the
application! The vector contains one element.

DEBUG:
The for loop is called one time, as it should be.

RELEASE:
The for loop is NEVER called, because the iterator i is a->end().

In that case the vector in the release version contains no elements.

I have no idea why.

It's somewhere in the code you haven't shown. Most probably an assert with side
effects, or something like that. Given the quality (novice level) of the
generated code you've shown, it may be in some of Microsoft's code.

Consider asking in a Microsoft-specific group.


Cheers,

- Alf
 
H

Hans Stoessel

In that case the vector in the release version contains no elements.
If I get out the size of the vector in a log file (release version), the
size of the vector is 1.

Hans
 
T

tonydee

If I get out the size of the vector in a log file (release version), the
size of the vector is 1.

When? Did you put the trace just inside that generated function,
reporting the size and whether begin() == end()? If you really have
both size == 1 when begin() == end(), that's violating vector's
invariants, and probably indicates corruption due to memory
mismanagement or similar issues. Keep simplifying the code until the
bug goes away or you have a trivial but complete test case that
fails....

Cheers,
Tony
 
H

Hans Stoessel

Hi

I solved the error.

I had the error in an InDesign plugin. I had to include the header
"VCPluginHeaders.h", then it works.

Thanks.

Regards
Hans



If I get out the size of the vector in a log file (release version), the
size of the vector is 1.

When? Did you put the trace just inside that generated function,
reporting the size and whether begin() == end()? If you really have
both size == 1 when begin() == end(), that's violating vector's
invariants, and probably indicates corruption due to memory
mismanagement or similar issues. Keep simplifying the code until the
bug goes away or you have a trivial but complete test case that
fails....

Cheers,
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top