Annoying error of Uninitialized Memory Access

来源:互联网 发布:淘宝优品乐购 编辑:程序博客网 时间:2024/06/05 16:16
Categories: 
  • Intel® Parallel Inspector
Tags: 
  • Inspector 
  •  memory checker 
  •  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. 

1int main() {
2    char *foo = (char*)malloc(100);
3    char *bar = (char*)malloc(100);
4    memcpy(bar, foo, 100);
5     
6    free(bar);
7    free(foo);
8    return 0;
9}


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. 

1int main() {
2    char *foo = (char*)malloc(100);
3    char *bar = (char*)malloc(100);
4    memcpy(bar, foo, 100);
5    printf("%cn", bar[100]);//referencing uninitialized mem
6    free(bar);
7    free(foo);
8    return 0;
9}


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

u6.JPG

原创粉丝点击