Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Bug found with writing to Data Segments and try catch statements

$
0
0
At our company we use data segments within the Binaries for various uses but when we attempted to compile with the Intel C++ compiler 14.0 we ran into a bug.  It was sort of a unique bug that happened only when you were using try and catch statements AND you were using #pragma directives to write to a data segment. Essentially what will happen is the Type definitions written within the catch parameter will be copied into a sum of memory between the data segments when you compile a program in just the right way.  This does not occur with the Microsoft Visual Studio C++ compiler.  The work around is very easy and the bug is really discrete but I wanted to let you guys know of this.  Here's how to reproduce (I'm using VS 2013 Intel C++ Compiler 14.0 to reiterate):

Create a console application.  In the header file copy this

stdafx.h:
#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>


#ifndef ASYMBOL
#define ASYMBOL

#pragma data_seg(push, "dummyData")
static  wchar_t mysection[16] = L"This is my end";
#pragma data_seg(pop)
//Add this to force your compiler to use the pop. aka this is how we worked around it
//static int DummyValue = 5;
#endif

// EOF

main.cpp:

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{

	try {

	}
	catch (int var){

	}


	return 0;

}

//EOF

Now open the resulting binary in a hex editor  Search the unicode for "int" or "This is the End" You'll notice whatever you change the catch statement's data type to, like char or void etc.  this will get written right next to the data section "This is the End".  If you uncomment the variable this seems to force the compiler to actually pop out of the data segment and no extra data get's wrongfully written to the data segments.

 

 


Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>