Method of Uninitialized Variable Detecting for C++ Program

Автор: Wan Lin, Liu Juan, Wang Qinzhao, Zhang Wei

Журнал: International Journal of Education and Management Engineering(IJEME) @ijeme

Статья в выпуске: 1 vol.1, 2011 года.

Бесплатный доступ

We present a testing approach which is a partially automated, partially manual inspection process that reports defects in C++ source code. In this paper we considered one of the faults type- uninitialized Variable- which the approach can detect. Uninitialized Variable is a common kind of error in programs written in C++, it often causes error result or system collapse. This paper analyses the classical C++ uninitialized variable errors, and describes a detecting method of uninitialized variable errors combining the advantage of ASI technology which based on static analysis.

Software testing, uninitialized variable syntax tree, controlling flow graph

Короткий адрес: https://sciup.org/15013571

IDR: 15013571

Текст научной статьи Method of Uninitialized Variable Detecting for C++ Program

Published Online July 2011 in MECS DOI: 10.5815/ijeme.2011.01.12

Software testing is very labor-intensive and expensive; It accounts for approximately 50% of the cost of a software system development.

Dynamic testing is a critical part of total quality assurance but it has many limitations, including:

  • • It is expensive and time-consuming to create, run, validate and maintain test cases and processes.

  • • Code coverage drops inexorably as the system grows larger, meaning that testing validates less of the system.

  • • It can be difficult and time-consuming to trace a failure from a test case back to the root cause so that developers know what code to change.

  • 2.    Abstract syntax tree analysis for C++

  • 2.1.    Abstract syntax tree structure

Static testing can avoid these limitations. As a static testing technology, software inspection or code review is a visual examination of source code to detect defects. Automated software inspection technologies are now emerging by overcome many of the disadvantages inherent in manual inspections. These technologies can locate many common programming faults. This paper introduces a method of uninitialized variable detecting. Before program running, warning messages regarding possible software defects would be reported by scanning the using of variable.

Corresponding author:

The starting point for the representation is abstract syntax trees. A parser reads the source code and produces an abstract syntax tree, which models all of the structural information contained in the source code.

The first application is to scan the C++ code for information about names, expressions, types and so on.

We imposed several requirements during the static analysis process. Lexical analysis generates syntax nodes for tokens such as constants and names. Parsing generates an abstract syntax tree with internal nodes representing appropriate syntactic constructs. Semantic analysis makes passes over the syntax tree to resolve names and operators and to transform the tree into a standard form.

All the faults detecting algorithms are based on abstract syntax trees. An abstract syntax tree is a syntax tree that has been cleaned up or abstracted to reflect the underlying language constructs without any syntactic sugar. It includes leaf nodes that represent non-keyword terminals in the language as well as internal nodes that represent syntactic constructs. The abstract syntax tree includes all the relevant information of the source and is a full representation of the source program. For example, an “if” statement such as “if (a

The top-lever node would represent the entire if statement. There are three subtrees under the if statement node:

  • •A subtree that models the condition “a

•The subtree that models the assignment “q=c+d” would be under the attribute “if-then actions”.

  • •The subtree that models the assignment “q=e+f” would be under the if-else-action attribute.

  • 2.2.    Abstract syntax tree pass through

  • 3.    Uninitialized variable detecting algorithms based on control flow graph

  • 3.    1 Uninitialized variable faults analysis

Figure 1 shows part of the parse tree of this example:

The second application involved the generation of program dependence graphs for C++. These were needed for a research project that attempts to help the user restructure programs. Because the algorithms for uninitialized variable detecting are based on control flow graph, the next step is to annotate this abstract representation with information about the control structures (control flow) of the application. As while as the abstract syntax tree been pass through, the algorithms worked. Some inspection points are reported about uninitialized variable after once scan of the tree. Our service based on ASI technology and the algorithms would deliver reports that show the cause and location of software defects in C++ applications.

Fig. 1 Abstract syntax tree of statement “if (a

The inspection points identified algorithms is the key point of this method. The quality of this testing method lies on the efficiency of the algorithms.

The fault of uninitialized variable can be defined as using of automatic variable before it is initialized.

For example:

121 char *readline(char *buf) {

122     char c;

  • 123     char *savebuf = buf;

125           *buf++ = c;

126      *buf = ’\0’;

128          return NULL;

129      else

130            return savebuf;

131 }

In this example the local variable c is checked for having the value of EOF before it is loaded with the next character. Because c is not initialized the first time the loop is executed, this is a use of an uninitialized variable.

Another example:

100      int a[10]={0,2,4,6} ,x ;

101     scanf(“%d”,x);

102      for (i=0;i<10;i++)

104     {  for(j=9;j>i+1;j--)  a[j]=a[j-1];

105                 a[j-1]=x;

106           }

In this example the array variable a defined on line 100 only be initialized partly. Then the use on line 103 may be cause uninitialized variable faults.

There are some other conditions may result in this fault type. We do not show them one by one here.

  • 3.    2 Detecting algorithms

In fact, defecting algorithms is the main point for system efficiency and usability of the testing service. Every fault type must have a corresponding defecting algorithms.

The algorithms for uninitialized variable can be designed as below:

Control flow graph of the program be described as G= ( N , E ) , in which V would be the set of the nodes and E would be the set of the edges. And e=(T(e),H(e)) means the twins of neighboring node, in which the edge e leaves the node T(e) and reaches the node H(e).

There are two targets in evaluating the automated detecting algorithms. One is its complication degree in time. The other is veracity and integrality of the faults report. Our algorithms consider all these targets.

  • 4.    Conclusion

Software failures are expensive and time consuming to detect, which cause significant damage directly or indirectly to end users. ASI provides a fast and cost-effective way to improve software quality.

We have build a prototype system for the fault type described above. During using of this tool, we find that there are many advantages of this method, such as working without any test case, faults can be located and so on. All these points are the user concerned and limited in other methods.

Список литературы Method of Uninitialized Variable Detecting for C++ Program

  • Tan Xueqing, Tzu-Ming and Zhou Dongru, “Personalized e-commerce shopping model”. Computer, vol.3, pp.147-148, March 2007.
  • Chen Zheng and Jian-Hua Gong, “A Java3D-based platform for collaborative virtual environments work”, Computer Applications, vol.08, pp.136-140, 2005.
  • Chen Xuelin and Chen Fengliang, “Virtual three-dimensional display of the core product realization”, Market Modernization, vol.27, 2008.
  • Fang Min, “Web3D technology development and application”, Xiangtan Normal University (Natural Science) , vol.24 (2), pp.65-68, 2002.
  • Ye Lin, “Virtual Reality Model mechanical drawing room set up”, Engineering Graphics, vol.3, pp.202-206, 2002.
  • Liu Yun, “Growth. Internet 3D Technology Web3D, Http://www.yesky.com/SoftChannel/72351167954812928/20021127/1641818.shtml, 2002.11.28/2005.05.01.
Статья научная