Annoying error of Uninitialized Memory Access

While analyzing a huge project at the mi4 level of Intel® Parallel Inspector, a user may get a lot of errors referred as 'Uninitialized Memory Access' which might considered as a false positives. In some cases these errors do not reflect the real problem in the application and a bunch of such errors might be annoying. Before getting rid of these errors with the Suppressions mechanism let’s consider the problem. The result of a mi4 level memory analysis of simple program is represented on the picture below. Inspector fires the Uninitialized Memory Access error blaming memcpy() function which reads the uninitialized memory pointed by foo.

u1.JPG


Looking at the sample code, we can conclude that the flagged read operation does not affect correctness of the whole application, although it is not good engineering practice.

int main() {
	char *foo = (char*)malloc(100);
	char *bar = (char*)malloc(100);
	memcpy(bar, foo, 100);
	
	free(bar);
	free(foo);
	return 0;
}


It should be mentioned that Inspector does not report the error on the mi2 or mi3 levels (and not at mi1). However, a user might want to hide such reports for the sake of not littering the real errors list. There is an easy way to do that with the help of suppressions.
In the Details view of the results, select 'Read' observation for this problem, right-click the mouse for the context menu and choose 'Suppress...'.

u2.JPG


In the private suppression dialog create a filter with 'Uninitialized memory access' problem and 'Read' description. For all other columns (module, function, etc.) you may set * (all) depending of scope of interest. The setting will be saved in the .sup file which can be reused with any other project if made public (Tools > Options > Intel Parallel Inspector > General > Suppressions).

u3.JPG


This can also be set by selecting 'Private Suppression: Delete problems' in the Configure Analysis dialog box before you click on 'Run Analysis'.

u4.JPG


The error will not appear after level mi4 analysis is completed.

u5.JPG


Where an instruction is added to code that uses the uninitialized memory in a way that might affect correctness, Inspector should report the error regardless if 'Uninitialized memory access' is suppressed. Consider the following sample code. A printf() instruction sending the content of uninitialized memory to the output is added to the initial sample.

int main() {
	char *foo = (char*)malloc(100);
	char *bar = (char*)malloc(100);
	memcpy(bar, foo, 100);
	printf("%cn", bar[100]);//referencing uninitialized mem
	free(bar);
	free(foo);
	return 0;
}


Inspector will report ‘Invalid memory Access’ error on each level mi2-mi4 and flag the source code line containing the prinf() call.

u6.JPG

Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.