Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
4995 Discussions

Passing string longer than 32 chars - first 16 bytes get filled with 0

Rajko_T_
Beginner
395 Views

Consider this simple program:

#include <string>
#include <assert.h>

void foo(const std::string& str)
{
   assert(str[0] != 0);
}

int main()
{
   foo("Test longer than 32 characters like this");
   return 0;
}

If the string passed to foo() is longer than 32 characters, then the assert throws an error. Detailed inspection shows first 16 characters of 'str' to be filled with 0 (therefore the string is - unexpectedly - altered)! Any workarounds?

Ray

InspectorXE 2016 - Update 2
Visual Studio 2015 Community

0 Kudos
3 Replies
Kevin_O_Intel1
Employee
395 Views

 

Hi,

What type of  Inspector analysis are you running?

It sounds like you might be running into a memory checker guard zone.

Can you try running a level 2 "Detect memory problems" analysis?

I'll run your example and see if under which conditions the issue duplicates.

Regards,

Kevin

0 Kudos
Rajko_T_
Beginner
395 Views

Hi,

It happens only when running with "Enable debugger when problem detected" option (level 2 or 3). At Level 1 or with "Analyze without debugger", no problems are encountered.

Ray

 

0 Kudos
Kevin_O_Intel1
Employee
395 Views

 

I just tested your example using the 2017 beta version of Inspector.

I'm not seeing the issue with this version. Can you try the 2017 beta?

Kevin

0 Kudos
Reply