This application claims priority under 35 U.S.C. § 119(a) to Republic of Korea Patent Application No. 10-2016-0118171 filed on Sep. 13, 2016, which is incorporated by reference herein in its entirety.
The present disclosure relates to a method for correcting violation of a source code and a computer readable recording medium having a program performing the same, and more particularly to a method for correcting violation of a source code, which automatically corrects the defect of a source code and a computer readable recording medium having a program performing the same.
A static code analysis is one of various computer software analysis methods. The method has a feature of performing an analysis on the source code of software under development without directly executing the software.
A static analysis tool is a program developed to automatically perform a static program analysis by using software instead of a human hand. In general, a source code has a very large size, so that it can be found that it is almost impossible to perform the static program analysis one by one by human hand operation. Therefore, it can be said that the static analysis tool functions to automatically perform such an analysis. The static analysis tool is able to detect various kinds of defects or vulnerabilities of the source code in accordance with its type and to notify the defects detected through the analysis to a user.
Such a static analysis tool type of a source code analysis apparatus has been previously proposed. However, the source code analysis apparatus which has been previously proposed or used provides limited functions of detecting defects and generating a detection message of the defect. Therefore, a process of correcting the detected defects has a limitation of being dependent on personal knowledge and experiences of the user (programmer).
Also, when thousands to tens of thousands of the defects are detected by the source code analysis apparatus which has been previously proposed or used, a lot of time is required to correct such numerous defects one by one. Particularly, even when some of the numerous defects are very simple, a lot of time is required for repetitively correcting the defects one by one.
One conventional technology is disclosed in Korean Patent No. 10-1623174 (hereinafter, referred to as a prior art). The prior art is characterized in that, when a defect is detected in a source code analyzed by a predefined analysis tool, “the defect correction method is presented to the user.” That is to say, the prior art simply presents the user the defect correction method, and it is the user (programmer) who has to directly perform the defect correction. Therefore, even in the prior art, there still exists a limit that the correction of the detected defect has to depend on the personal knowledge and experiences of the user (programmer). When thousands to tens of thousands of the defects are detected, a lot of time is required to correct the detected defects one by one.
Accordingly, a method and a tool for automatically correcting the detected defects are required without direct correction of the detected defects by the user (programmer).
One embodiment is a method for correcting violation of a source code, the method comprises: a violation detection step in which a source code is analyzed and one or multiple violations are detected; a correction information generation step in which multiple pieces of the correction information for correcting the detected violation are generated; a correction information merging step in which the multiple pieces of the generated correction information are merged; and a correction step in which the source code is corrected on the basis of the merged correction information.
Each of the multiple pieces of the correction information may include at least any one of a correction start line number, correction contents, correction types, and order.
In the correction information merging step, the multiple pieces of the correction information may be merged by arranging the order of the multiple pieces of the correction information. In the correction step, the source code may be corrected according to the order.
When the one or multiple violations detected in the violation detection step are additions or deletions of two or more continuous lines, information on the additions or deletions of the two or more continuous lines may be included in one piece of the correction information in the correction information merging step.
In the correction information merging step, the multiple pieces of the generated correction information may be merged by a predetermined rule. The predetermined rule may include: a step in which the multiple pieces of the correction information are arranged by the order of the correction start line; a step in which, when there are the multiple pieces of the correction information on any one line, the multiple pieces of the correction information are arranged in the order of Modify-Delete-Add; and a step in which, when there are two or more pieces of the correction information on the deletion of the any one line, one piece of merging correction information is generated by a predetermined merging rule, and when two or more pieces of the correction information on the deletion of the any one line, only the correction information on the deletion of the most lines is selected, and when two or more pieces of the correction information on the addition to the any one line, the pieces of the correction information are arranged by a predefined order.
The predetermined merging rule may include: an arrangement step in which two or more pieces of the correction information are arranged by an order included in each of the two or more pieces of the correction information; an addition step in which the an indexer is added to a source code original for the any one line and is added to a first column of each of the two or more pieces of the correction information; and a determination step in which the merging correction information is determined by comparing letters pointed to by all the added indexers, and movements of all the indexers are determined.
The determination step may include: a step in which, when the letters pointed to by all the indexers are the same, the same letter is added to a first column of the merging correction information, and all the indexers are moved to the next column; and a step in which, when any one of the letters pointed to by all the indexers is different from the others and the others are the same, the movements of all the indexers and the merging correction information are determined by any one of the following (a), (b), and (c). (a) When a type of the correction information to which the any one letter belongs is insert, the any one letter is added to the first column of the merging correction information, and only the indexer of the correction information to which the any one letter belongs is moved to the next column. (b) When the type of the correction information to which the any one letter belongs is delete, no letter is added to the first column of the merging correction information, and remaining indexers other than the indexer of the correction information to which the any one letter belongs are moved to the next column. (c) When the type of the correction information to which the any one letter belongs is replace, the any one letter is added to the first column of the merging correction information, and all the indexers are moved to the next column.
A computer readable recording medium having a program performing the method for correcting violation of a source code in accordance with the above-described embodiments is included.
Hereafter, an exemplary embodiment of the present invention will be described in detail with reference to the accompanying drawings. It is noted that the same reference numerals are used to denote the same elements throughout the drawings. In the following description of the present invention, the detailed description of known functions and configurations incorporated herein is omitted when it may make the subject matter of the present invention unclear. Hereafter, a method for correcting violation of a source code and a computer readable recording medium having a program performing the same in accordance with the embodiment of the present invention will be described below with reference to the accompanying drawings.
Referring to
In the violation detection step 110, the input source code is analyzed and one or multiple violations are detected.
The source code may be received in the form of a code file. For example, the code file input may be performed by user's file input or off manipulation.
The source code may be analyzed by a program such as a static analysis tool. The static analysis tool may have a variety of methods such as a syntactic analysis method, a semantic analysis method, or the like. Through use of the static analysis tool, the violation of a predefined rule can be detected.
In the correction information generation step 130, one or multiple pieces of the correction information for correcting the violation detected in the violation detection step 110 are generated.
In the correction information, a difference between a source code where the violation exists and a source code corrected by the rule may be recorded and stored by a specific unit. Here, the correction information may have a unified diff format.
The correction information may include at least any one of a correction start line number, correction contents, correction types (e.g., addition, deletion, change), and order. Also, the correction information may further include violation details.
Here, the order is determined in consideration of the line number, correction type, and code block depth of violation occurrence location. The foremost number of the order may represent the line number. The next number may be determined by the correction type (e.g., “1” for modification, “2” for addition, and “3” for deletion). The next numbers may be determined by the code block depth of violation occurrence location.
The multiple pieces of the correction information may be generated in the correction information generation step 130.
For example, when two or more discontinuous lines are added (or deleted), the number of the pieces of the correction information may be determined by the number of the added (or deleted) lines. Also, the number of the pieces of the correction information may be determined by the number of the modifications (e.g., addition, deletion, change) of one or more columns existing within any one particular line. For example, this will be described with reference to the following tables.
The table 1 assumes that one or multiple violations exist in a current source code, for the purpose of correcting the one or multiple violations, one line (bbbbb) should be added after the line 1 of the current source code, and one line (ddddd) should be added after the line 3 of the current source code. In the case of the table 1, the number of the pieces of the generated correction information is 2 as follows.
correction information 1: @@−1,0 +1,1 @@
correction information 2: @@−3,0 +3,1 @@
The table 2 assumes that one or multiple violations exist in the current source code, for the purpose of correcting the one or multiple violations, the line (bbbbb) after the line 1 of the current source code should be deleted, and the line (ddddd) after the line 3 of the current source code should be deleted. In the case of the table 2, the number of the pieces of the generated correction information is 2 as follows.
correction information 1: @@−1,0 +1,1 @@
correction information 2: @@−3,0 +3,1 @@
The table 3 assumes that one or multiple violations exist in the current source code, for the purpose of correcting the one or multiple violations, a new column (zz) should be added after the column (aa) within the line 1 of the current source code, and another column (cc) within the line 1 of the current source code should be changed into a new column (ee). In the case of the table 3, the number of the pieces of the generated correction information is 2 as follows.
correction information 1: @@−1,1 +1,1 @@
correction information 2: @@−1,1 +1,1 @@
Meanwhile, the correction information generated in the correction information generation step 130 may include two or more correction contents. For example, when two or more continuous lines should be added or deleted in order to correct one or multiple detected violations, one piece of the correction information may include information on the additions or deletions of the two or more continuous lines. For example, this will be described with reference to the following tables.
The table 4 assumes that one or multiple violations exist in the current source code, for the purpose of correcting the one or multiple violations, two or more continuous lines, i.e., two lines (ccccc, ddddd) should be added after the line 2. In the case of the table 4, the number of the pieces of the generated correction information is 1 as follows.
correction information: @@−2,0 +2,2 @@
The table 5 assumes that one or multiple violations exist in the current source code, for the purpose of correcting the one or multiple violations, two or more continuous lines, i.e., the line 3 (ccccc) and the line 4 (ddddd) should be deleted. In the case of the table 5, the number of the pieces of the generated correction information is 1 as follows.
correction information: @@−2,2 +2,0 @@
In the correction information merging step 150, the multiple pieces of the generated correction information are merged. Therefore, when only one piece of the correction information is generated in the correction information generation step 130, this step 150 can be omitted.
In the correction information merging step 150, the multiple pieces of the correction information are merged by a predetermined rule. The predetermined rule may be as follows.
(1) The multiple pieces of the correction information are arranged by the order of the correction start line.
(2) In the case of the multiple pieces of the correction information on any one line, the multiple pieces of the correction information are arranged in the order of Modify-Delete-Add.
(3) In the case of two or more pieces of the correction information on the modification of any one line, merging correction information is generated by a predetermined merging rule. In the case of two or more pieces of the correction information on the deletion of any one line, only the correction information on the deletion of the most lines is selected. Also, in the case of two or more pieces of the correction information on the addition to any one line, the pieces of the correction information are arranged by the order included in each correction information.
(4) In the case of two or more pieces of the correction information on the modification of any one line, according to the predetermined merging rule for generating the merging correction information,
Here, the above c) will be described in more detail. If the letters pointed to by all the indexers are the same, the same letter is added to the first column of the merging correction information, and all the indexers are moved to the next column.
Meanwhile, if any one of the letters pointed to by all the indexers is different from the others and the others are the same, the following three determination are made. When the type of the correction information to which any one letter belongs is insert, any one letter is added to the first column of the merging correction information, and only the indexer of the correction information to which any one letter belongs is moved to the next column. On the other hand, when the type of the correction information to which any one letter belongs is delete, no letter is added to the merging correction information, and remaining indexers other than the indexer of the correction information to which any one letter belongs are moved to the next column. On the other hand, when the type of the correction information to which any one letter belongs is replace, any one letter is added to the first column of the merging correction information, and all the indexers are moved to the next column.
In the correction step 170, the source code is corrected on the basis of the correction information merged in the correction information merging step 150. In the correction step 170, the source code is automatically corrected according to the order of the pieces of the correction information arranged by the above-described rules of (1) to (4) within the correction information merged in the correction information merging step 150.
Then, an example of the method for correcting violation of a source code in accordance with the embodiment of the present invention will be described below in detail with reference to the accompanying drawings.
First, as shown in
Rule 1: A suffix “1” must be represented in upper case.
Rule 2: A constant must be followed by a suffix “u”.
Rule 3: One line must contain only one sentence.
In the violation detection step 110 shown in
In the correction information generation step 130 shown in
For example, a first correction information (diff 1) may include, as shown in
“Modification of Line 5 to ‘a=5L; b=a;’, order 5120”,
a second correction information (diff 2) may include, as shown in
“Modification of Line 5 to ‘a=5lu, b=a;’, order 5120”, and
a third correction information (diff 3) may include, as shown in
“Modification of Line 5 to ‘a=5l;’, order 5120, and
Addition of ‘b=a;’ to the next line to Line 5, order 5220”.
In the correction information merging step 150 shown in
Specifically, in the correction information merging step 150, in accordance with the rule (1) of the above-described predetermined rule, the first to third pieces of the correction information (diff1, diff2, and diff 3) are arranged by the order of the correction start line. Here, in the above-given example, since the correction start lines of the first to third pieces of the correction information (diff1, diff2, and diff 3) are all Line 5, the order of the correction information is not changed by the predetermined rule (1).
Next, the pieces of the correction information are arranged as described below in the order of Modify-Delete-Add by the rule (2) of the predetermined rule.
{circle around (1)} Modification of Line 5 to ‘a=5L, b=a;’, order 5120
{circle around (2)} Modification of Line 5 to ‘a=5lu, b=a;’, order 5120
{circle around (3)} Modification of Line 5 to ‘a=5l;’, order 5120
{circle around (4)} Addition of ‘b=a;’ to the next line to Line 5, order 5220
Here, since there are two or more pieces of the correction information ({circle around (1)}, {circle around (2)}, and {circle around (3)}) on the modification of Line 5, one piece of the merging correction information on {circle around (1)} to {circle around (3)} is generated by the rule (3). The one piece of the merging correction information on {circle around (1)} to {circle around (3)} is generated by the above-described predetermined merging rule. This will be described in detail with reference to
First, referring to
In
In
In
In
In
In
In
In
When the process of
“Modification of Line 5 to ‘a=5Lu;’, order 5120”
Eventually, one piece of the correction information generated in the correction information merging step 150 shown in
Modification of Line 5 to ‘a=5Lu;’, order 5120 (three diffs are merged)
Addition of ‘b=a;’ to the next line to Line 5, order 5220
In the correction step 170 shown in
First, as shown in
Referring to the corrected source code on the right side of
First, as shown in
Rule 1: An if statement must have a brace.
In the violation detection step 110 shown in
In the correction information generation step 130 shown in
For example, a first correction information (diff 1) may include, as shown in
“Addition of ‘{’ to the next line to Line 5, order: 520
Addition of ‘}’ to the next line to Line 7, order: 720”, and
a second correction information (diff 2) may include, as shown in
“Addition of ‘{’ to the next line to Line 6, order: 610
Addition of ‘}’ to the next line to Line 7, order 710”.
In the correction information merging step 150 shown in
Specifically, in the correction information merging step 150, in accordance with the rule (1) of the above-described predetermined rule, the first and second pieces of the correction information (diff1 and diff2) are arranged by the order of the correction start line. Since the correction start lines of the first correction information (diff1) is Line 5 and the correction start lines of the second correction information (diff2) is Line 6, the pieces of the correction information are arranged as follows.
{circle around (1)} Addition of ‘{’ to the next line to Line 5, order: 520
{circle around (2)} Addition of ‘}’ to the next line to Line 7, order: 720
{circle around (3)} Addition of ‘{’ to the next line to Line 6, order: 610
{circle around (4)} Addition of ‘}’ to the next line to Line 7, order 710
Next, the pieces of the correction information are arranged in the order of Modify-Delete-Add by the rule (2) of the predetermined rule. Since the correction type of this example is addition, the arrangement order is not changed.
However, since there are two or more pieces of the correction information ({circle around (2)} and {circle around (4)}) on the addition to Line 7, the pieces of the correction information are arranged as follows according to the order included in each correction information by the rule (3).
Addition of ‘{’ to the next line to Line 5, order: 520
Addition of ‘{’ to the next line to Line 6, order: 610
Addition of ‘}’ to the next line to Line 7, order 710
Addition of ‘}’ to the next line to Line 7, order: 720
In the correction step 170 shown in
Referring to the corrected source code on the right side of
First, as shown in
Rule 1: An if statement must have a brace.
Rule 2: An if statement must have an else statement.
In the violation detection step 110 shown in
In the correction information generation step 130 shown in
For example, a first correction information (diff 1) may include, as shown in
“Addition of ‘{’ to the next line to Line 3, order: 320
Addition of ‘}’ to the next line to Line 4, order: 420”, and
a second correction information (diff 2) may include, as shown in
“Addition of ‘else’, ‘{’, ‘}’ to the next line to Line 4, order: 421”.
In the correction information merging step 150 shown in
Specifically, in the correction information merging step 150, in accordance with the rule (1) of the above-described predetermined rule, the first and second pieces of the correction information (diff1 and diff2) are arranged by the order of the correction start line. Since the correction start lines of the first correction information (diff1) is Line 3 and the correction start lines of the second correction information (diff2) is Line 4, the pieces of the correction information are arranged as follows.
{circle around (1)} Addition of ‘{’ to the next line to Line 3, order: 320
{circle around (2)} Addition of ‘}’ to the next line to Line 4, order: 420
{circle around (3)} Addition of ‘else’, ‘{’, ‘}’ to the next line to Line 4, order: 421
Next, the pieces of the correction information are arranged in the order of Modify-Delete-Add by the rule (2) of the predetermined rule. Since the correction type of this example is addition, the arrangement order is not changed.
However, since there are two or more pieces of the correction information ({circle around (2)} and {circle around (3)}) on the addition to Line 4, the pieces of the correction information are arranged according to the order included in each correction information by the rule (3). Here, since {circle around (2)} has a higher order than that of {circle around (3)}, the arrangement order is not changed.
In the correction step 170 shown in
Referring to the corrected source code on the right side of
Referring to
The violation detector 3210 performs the violation detection step 110 of
The method for correcting violation of a source code in accordance with the embodiment of the present invention described in
The program instruction which is recorded in the computer readable recording medium may be specially designed and configured for the present invention or may be well-known and available to those skilled in the field of computer software.
The example of the computer readable recording medium includes a magnetic medium such as a hard disk, a floppy disk, and a magnetic tape, an optical recording medium such as a CD-ROM and DVD, a magneto-optical medium such as a floptical disk, and a hardware device which is specially configured to store and execute program instructions such as ROM, RAM, flash memory, etc. The example of the program instruction includes an advanced language code which can be executed by using an interpreter, etc., by a computer as well as a machine language code which is created by a compiler. The hardware device may be configured to operate as at least one software module in order to perform the processes according to the present invention, and vice versa.
While the embodiment of the present invention has been described with reference to the accompanying drawings, these are just examples and do not limit the present invention. Further, the present invention may be changed and modified in various ways, without departing from the essential features of the present invention, by those skilled in the art. For example, the components described in detail in the embodiments of the present invention may be modified. Further, differences due to the modification and application should be construed as being included in the scope and spirit of the present invention, which is described in the accompanying claims.
Number | Date | Country | Kind |
---|---|---|---|
10-2016-0118171 | Sep 2016 | KR | national |
Number | Name | Date | Kind |
---|---|---|---|
7707552 | Schmidt | Apr 2010 | B2 |
7962832 | Bae | Jun 2011 | B2 |
8572583 | Bae | Oct 2013 | B2 |
8875110 | Lee | Oct 2014 | B2 |
9792443 | Sheridan | Oct 2017 | B1 |
20070089092 | Schmidt | Apr 2007 | A1 |
20120167060 | Landwehr | Jun 2012 | A1 |
20130014093 | Lee | Jan 2013 | A1 |
20130179863 | Vangala | Jul 2013 | A1 |
20130339929 | Logozzo | Dec 2013 | A1 |
20140196010 | Balachandran | Jul 2014 | A1 |
20150135166 | Tarlow | May 2015 | A1 |
20170212829 | Bales | Jul 2017 | A1 |
20180074939 | Bae | Mar 2018 | A1 |
Number | Date | Country |
---|---|---|
20040096259 | Nov 2004 | KR |
20160025426 | Mar 2016 | KR |
Entry |
---|
Office Action for Korean Patent Application No. KR 10-2016-0118171, Jul. 3, 2017, 6 Pages (With Concise Explanation of Relevance). |
Number | Date | Country | |
---|---|---|---|
20180074939 A1 | Mar 2018 | US |