CN102855183A - Static test method and device for misquotation of inner variables by outer pointers - Google Patents

Static test method and device for misquotation of inner variables by outer pointers Download PDF

Info

Publication number
CN102855183A
CN102855183A CN2012101153433A CN201210115343A CN102855183A CN 102855183 A CN102855183 A CN 102855183A CN 2012101153433 A CN2012101153433 A CN 2012101153433A CN 201210115343 A CN201210115343 A CN 201210115343A CN 102855183 A CN102855183 A CN 102855183A
Authority
CN
China
Prior art keywords
variable
module
processed
address
function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2012101153433A
Other languages
Chinese (zh)
Other versions
CN102855183B (en
Inventor
王瑀屏
白杨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tsinghua University
Original Assignee
Tsinghua University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tsinghua University filed Critical Tsinghua University
Priority to CN201210115343.3A priority Critical patent/CN102855183B/en
Publication of CN102855183A publication Critical patent/CN102855183A/en
Application granted granted Critical
Publication of CN102855183B publication Critical patent/CN102855183B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a static test method for misquotation of inner variables by outer pointers. The method includes that a source code is preprocessed, whether functions which are not processed exist or not is searched, if the functions which are not processed exist, whether address operational statements which are not processed exist or not is searched in the functions which are not processed, if the address operational statements which are not processed exist, whether first variables which addresses in the address operational statements correspond to are inner variables of the functions which are not processed or not is determined according to a variable table, if the first variables are inner variables of the functions which are not processed, whether second variables with values which are identical to addresses in the address operational statements exist or not is searched in statements after the address operational statements and between exits of the functions which are not processed, if the second variables with values which are identical to addresses in the address operational statements exist, whether the second variables are the inner variables of the functions which are not processed or not is determined, if the second variables are the inner variables of the functions which are not processed, the searching is continued, and otherwise corresponding error message is output. By means of the method, the manpower cost can be effectively saved, the efficiency is increased, the object code stability is improved, and the test accuracy is good. A static test device for misquotation of the inner variables by the outer pointers is further disclosed.

Description

The internal layer variable is by outer pointer misquotation static detection method and device
Technical field
The present invention relates to computing machine and electronic information technical field, particularly a kind of internal layer variable is by outer pointer misquotation static detection method and device.
Background technology
Take the territory of function body as the boundary, the internal layer variable refers to the variable of action scope in this function body, outer variable refers to that action scope is in the invoked territory of this function or the variable in the territory, upper strata more, for example in by another function body of recursive call, and the perhaps variable in global field.The concept of " internal layer " and " skin " is relative, shown in the following code,
Figure BDA0000154728330000011
Called func2 among the function f unc1, variable b is relative, and variable c is outer variable, and func1 is called by func0, so variable b then is the internal layer variable with respect to variable a.Because variable p is in the global field, and variable a, variable b, variable c be all in the local field in certain function body, so variable p is the outer variable of variable a, variable b, variable c.
According to the compiling rule of program, when the program operation entered certain function, the variable in this domain of function was assigned on the stack, and along with withdrawing from of this function, corresponding stack space can be released, and also can be destroyed with variations per hour.If but before this function finishes, an outer field pointer record address of certain variable in this function, so after this function withdraws from, this pointer still can be accessed the residing address of that variable, but can't obtain the right value of above-mentioned variable this moment by this pointer, and when program runs to herein, the internal storage access mistake might occur, cause program crashing.
Present compiler or other static check instruments on the market can't detect this class problem in the compilation phase, also do not have relevant algorithm or research.Because programmer's carelessness all can not be avoided this type of wrong generation in a lot of programs.The manual detection cost is high, and accuracy rate is low, human negligence and inefficiency easily occur.And the size of code of some engineering is huge, can't utilize manually one by one code to be checked.
Summary of the invention
Purpose of the present invention is intended to solve at least one of above-mentioned technological deficiency.
For this reason, first purpose of the present invention is to provide a kind of internal layer variable by outer pointer misquotation static detection method, the method is passed to outer field behavior to the internal layer address of variable and automatically detects, can effectively save human cost, raise the efficiency, lifting object code stability, detection accuracy is good, and effect is more obvious in large-scale code detection.
Second purpose of the present invention is to provide a kind of internal layer variable by outer pointer misquotation static detection device.
For achieving the above object, the embodiment of first aspect present invention proposes a kind of internal layer variable by outer pointer misquotation static detection method, comprise the steps: S1: source code is carried out pre-service be converted to predetermined form with the rreturn value that the function of pointer type rreturn value will be had in the described source code, wherein, pretreated result comprises the generation abstract syntax tree, and described abstract syntax tree has argument table; S2: search whether there is not processed function at described abstract syntax tree; S3: if exist, then in described not processed function, search whether have a not processed mistake get the location action statement; S4: if exist, then judge described corresponding the first variable in the address internal layer variable of described not processed function whether of getting in the action statement of location according to described argument table; S5: if, then described get the location action statement after and search whether existence value and described the second identical variable of address in the action statement of location of getting in the statement between the outlet of described not processed function; And S6: if there is described the second variable, judge that then whether described the second variable is the internal layer variable of described not processed function, if it is continues to search, otherwise judges described the second type of variables and export corresponding error message.
Internal layer variable according to the present invention can be realized by computer programming by outer pointer misquotation static detection method, and as the additional of existing compiler or as independent checking tool, the internal layer address of variable be passed to outer field mistake automatically detect.In the code compilation stage, by being passed to outer field behavior, the internal layer address of variable detects, can effectively save human cost, raise the efficiency, find object code (code) mistake by detecting, after correcting mistakes, the stability of code is improved, and detection accuracy is good.
In one embodiment of the invention, described step S1 further comprises: described source code is carried out lexical analysis, grammatical analysis and semantic analysis; And the transcode that generates described source code.
In one embodiment of the invention, the described predetermined form character string that is global property.
In one embodiment of the invention, described judgement the second type of variables is also exported corresponding error message, further comprises:
Judge described the second type of variables, if described the second type of variables is described predetermined form, then error message is returned in output;
If described the second variable is the parameter of described not processed function, then exporting has two-dimentional pointer parameter to quote the error message of the address in the described not processed function in the described not processed function;
Otherwise be output as the error message that outer pointer has directly been quoted the address in the described not processed function.
The embodiment of second aspect present invention proposes a kind of internal layer variable by outer pointer misquotation static detection device, comprise: pretreatment module, described pretreatment module is used for source code is carried out pre-service, wherein, pretreated result comprises the generation abstract syntax tree, described abstract syntax tree has argument table, described pretreatment module comprises rreturn value type setting module, and described rreturn value type setting module is converted to predetermined form for the rreturn value that described source code is had the function of pointer type rreturn value; Not processed function is searched module, and described not processed function is searched module and is used for searching whether there is not processed function at described abstract syntax tree; The first address search module, described the first address search module are used for when there is not processed function in described abstract syntax tree, in described not processed function, search whether have a not processed mistake get the location action statement; The first address judgment module, described the first address judgment module be used for described not processed function exist not processed mistake get the location action statement time, judge described corresponding the first variable in the address internal layer variable of described not processed function whether of getting in the action statement of location according to described argument table; The second address search module, described the second address search module is used for when described corresponding the first variable in address of getting the location action statement is the internal layer variable of described not processed function, described get the location action statement after and search whether existence value and described the second identical variable of address in the action statement of location of getting in the statement of described not processed function between exporting; The second variable judge module, described the second variable judge module are used for judging that whether described the second variable is the internal layer variable of described not processed function, if it is continue to search; And the error message module, described error message module is used for when described the second variable is not the internal layer variable of described not processed function, and the misjudgment type is also exported corresponding error message.
Internal layer variable according to the present invention is by outer pointer misquotation static detection device, and this device can be used as replenishing of existing compiler or as independent checking tool, the internal layer address of variable is passed to outer field mistake automatically detects.In the code compilation stage, by program the internal layer address of variable is passed to outer field behavior and detects, can effectively save human cost, raise the efficiency, find object code (code) mistake by detecting, after correcting mistakes, the stability of code is improved, and detection accuracy is good.
In one embodiment of the invention, described pretreatment module also comprises: analysis module, described analysis module are used for described source code being carried out lexical analysis, grammatical analysis and semantic analysis; And the transcode module, described transcode module is used for generating the transcode of described source code.
In one embodiment of the invention, the described predetermined form character string that is global property.
In one embodiment of the invention, the error message module comprises: the type of error judge module, described type of error judge module is used for judging described type of error, if described the second type of variables is described predetermined form, then described type of error is that function returns mistake, if described the second variable is the parameter of described not processed function, then described type of error is that two-dimentional pointer parameter is quoted the address in the described not processed function, directly quotes address in the described not processed function otherwise described type of error is outer pointer; Error message output module, described error message output module are used for exporting described error message, and wherein said error message comprises described type of error.
The aspect that the present invention adds and advantage in the following description part provide, and part will become obviously from the following description, or recognize by practice of the present invention.
Description of drawings
Above-mentioned and/or the additional aspect of the present invention and advantage are from obviously and easily understanding becoming the description of embodiment below in conjunction with accompanying drawing, wherein:
Fig. 1 is that internal layer variable according to the embodiment of the invention is by the process flow diagram of outer pointer misquotation static detection method; And
Fig. 2 is that internal layer variable according to the embodiment of the invention is by the structural representation of outer pointer misquotation static detection device.
Embodiment
The below describes embodiments of the invention in detail, and the example of described embodiment is shown in the drawings, and wherein same or similar label represents same or similar element or the element with identical or similar functions from start to finish.Be exemplary below by the embodiment that is described with reference to the drawings, only be used for explaining the present invention, and can not be interpreted as limitation of the present invention.
With reference to following description and accompanying drawing, these and other aspects of embodiments of the invention will be known.These describe and accompanying drawing in, specifically disclose some specific implementations in the embodiments of the invention, represent to implement some modes of the principle of embodiments of the invention, still should be appreciated that the scope of embodiments of the invention is not limited.On the contrary, embodiments of the invention comprise spirit and interior all changes, modification and the equivalent of intension scope that falls into additional claims.
Before describing embodiments of the invention, need understand the present invention be based on the hypothesis all the behavior that the internal layer address of variable passes is all belonged to risky operation, therefore do not need to classify according to variable transmission form, problem reduction is carried out miscue or warning for the behavior that is passed away for all internal layer address of variable.And just hope for some and to obtain interim internal layer address of variable, and do not need the internal layer variable itself is conducted interviews or the special processing revised is not analyzed.
Based on above-mentioned hypothesis, the behavior stipulations that the internal layer address of variable is passed arrive following six classes:
(1) the internal layer variable is directly quoted by outer pointer.Example function foo1 is as follows, and wherein a is the internal layer variable, and p is outer pointer.
Figure BDA0000154728330000051
(2) the internal layer address of variable is by the two-dimentional pointer parameter of assignment to function.Example function foo2 is as follows, and wherein, a is the internal layer variable, and p is a two-dimentional pointer parameter of function.
Figure BDA0000154728330000052
(3) address of internal layer variable is taken as function return value and returns.Example function foo3 is as follows, and wherein, a is the internal layer variable.
Figure BDA0000154728330000053
Figure BDA0000154728330000061
(4) to the internal layer pointer, this pointer assignment is given another outer pointer to the internal layer address of variable simultaneously by assignment.Shown in example function foo4, wherein, a is the internal layer variable, and b is the internal layer pointer, and p is outer pointer.
Figure BDA0000154728330000062
(5) the internal layer variable is quoted by the internal layer pointer, and this pointer is by the two-dimentional pointer parameter of assignment to function simultaneously.Shown in example function foo5, wherein, a is the internal layer variable, and b is the internal layer pointer, and p is the two-dimentional pointer in the function parameter.
void?foo5(int**p){
Figure BDA0000154728330000063
(6) the internal layer variable is quoted by the internal layer pointer, and this pointer is taken as function return value and returns simultaneously.Shown in example foo6, wherein, a is the internal layer variable, and b is the internal layer pointer.
Figure BDA0000154728330000064
(4), (5), (6) are respectively the mutation to the form of (1), (2), (3).(4), the pointer in (5), (6) the three kinds of situations transmits indirectly, namely the internal layer variable is quoted by the internal layer pointer first, and then the internal layer pointer is given the two-dimentional pointer parameter of outer pointer, function or as the rreturn value of function the address of internal layer variable indirectly passed to skin by assignment again.Be understandable that, the internal layer pointer can be through repeatedly transmitting, and be not limited to shown in the embodiment of the invention once.For example, 1 internal layer variable a and N internal layer pointer are arranged, the internal layer pointer is denoted as respectively b1, b2, and b3..., bN, and the statement of following effect is arranged in the function:
b1=&a;
bN=....=b3=b2=b1;
At last bN is delivered to skin, also belongs to above-mentioned (4), (5), (6) described situation.
Internal layer variable according to the embodiment of the invention is described by outer pointer misquotation static detection method below with reference to Fig. 1 and table 1.
Table 1
As shown in table 1, program the situation that outer pointer p quotes internal layer variable a address occurred at eighth row; Accessed p content pointed at the 14th row, variable a just has been released because the 13rd line function func finishes afterwards, so the internal storage access mistake can occur when the 14th row moves.Be understandable that, table 1 only for illustrative purposes, the embodiment of the invention is not limited to this.
Step S1: source code is carried out pre-service be converted to predetermined form with the rreturn value that will have the function of pointer type rreturn value in the described source code, wherein, pretreated result comprises the generation abstract syntax tree, and described abstract syntax tree has argument table.In one embodiment of the invention, in fact pretreated result is exactly the machine recognizable abstract syntax tree that is used for indicating programmed logic, and argument table (function table) belongs to the part of this abstract syntax tree.Wherein, abstract syntax tree is a kind of intermediate representation form of program, and this intermediate structure is beneficial to Computer Processing.Similarly, argument table also is the general concept in Fundamentals of Compiling the inside, its objective is to indicate to comprise which variable in certain function, and the action scope of variable.In the present embodiment, specifically comprise:
S11: source code is carried out lexical analysis, grammatical analysis and semantic analysis.In fact, the lexical analysis in the present embodiment, grammatical analysis, semantic analysis is consistent with the behavior in the general compiled device.
S12: the rreturn value that has the function of pointer type rreturn value in the source code is converted to predetermined form.Predetermined form is the character string of global property.In one embodiment of the invention, the form of being scheduled to is made as _ LXXXX, XXXX is indefinite length, the unique numeral of the overall situation.Be understandable that, above-mentioned preset kind the invention is not restricted to this only for illustrative purposes.With all statement return ﹠amp; A;
Change to:
_LXXXX=&a;
return_LXXXX。
In this example, indication _ LXXXX can be understood as the global variable of (void*) type, and XXXX is numbering, may be return ﹠amp because the return statement of a lot of functions may be arranged; The form of a is for the unity of form of return statement just, simultaneously in order to distinguish different return statements, so this quasi-sentence is changed.Final result is different return ﹠amp; The a statement is converted into _ LXXXX=﹠amp; Two statements of a and return_LXXXX.LXXXX can add when the compiling pre-service.Specifically, the rreturn value that has the function of pointer type rreturn value in the source code is converted to predetermined form and has following advantage: return for example; A; An address can be passed out function, detect the mistake that the internal layer variable is quoted by outer pointer and the objective of the invention is needs, at first catch this address therefore use a global pointer (outer pointer), then this global pointer variable is returned, so just with six kinds of situations unifications be " the second variable=﹠amp; The first variable " form, be beneficial to inspection.
Wherein a represents variable, only for illustrative purposes, the invention is not restricted to this herein, and a place can be any variable name.
S13: the transcode that generates source code.
Drawing func after the pre-service is that a rreturn value is empty overall situation function for empty, parameter list.
Step S2: search whether there is not processed function at abstract syntax tree, if there is no, then detect and finish.One section executable C++ code as shown in table 1, supposing to find not processed function is func.
Step S3: if exist, then in not processed function, search whether have a not processed mistake get the location action statement, if do not inquire, then return step S2.What in one embodiment of the invention, inquire not processed mistake in the function body of the func in table 1 gets location operation ﹠amp; A.
Step S4: if exist, then judge the whether internal layer variable of not processed function of corresponding the first variable in address got in the action statement of location according to argument table, if not, then return step S3.
In one embodiment of the invention, search the argument table of function f unc, judge to draw p=﹠amp; The first corresponding among a variable a is the internal layer variable of func.
Step S5: if the second identical variable of address in then searching whether existence value and get the location action statement after getting the location action statement and in the statement between the outlet of not processed function if there is no, then returns step S3.
In one embodiment of the invention, from p=﹠amp; A begins to func function detection of end second variable identical with the address in getting the location action statement, and can draw p is the second variable.
Step S6: if there is the second variable, judge that then whether the second variable is the internal layer variable of not processed function, if it is continue to search, otherwise judge the second type of variables and export corresponding error message, if not, then return step S5.
Judge the second type of variables and export corresponding error message, further comprise:
Step S61: judge the second type of variables, if the second type of variables is predetermined form, then error message is returned in output;
Step S62: if the second variable is the parameter of not processed function, then exporting has two-dimentional pointer parameter to quote the error message of the address in the not processed function in the not processed function;
Step S63: otherwise export the error message that outer pointer has directly been quoted the address in the not processed function.
In one embodiment of the invention, the second variable p is outer variable, meets the description of step S6, so output error message is that outer pointer has directly been quoted the address in the not processed function, and the program eighth row is warned.
Internal layer variable according to the embodiment of the invention can be realized by computer programming by outer pointer misquotation static detection method, and as the additional of existing compiler or as independent checking tool, the internal layer address of variable be passed to outer field mistake automatically detect.In the code compilation stage, by being passed to outer field behavior, the internal layer address of variable detects, can effectively save human cost, raise the efficiency, find object code (code) mistake by detecting, after correcting mistakes, the stability of code is improved, and detection accuracy is good.
As shown in Figure 2, the embodiment of the invention provides the internal layer variable by outer pointer misquotation static detection device, comprises that pretreatment module 100, not processed function search module 200, the first address search module 300, the first address judgment module 400, the second address search module 500, the second variable judge module 600 and error message module 700.Wherein:
Pretreatment module 100 is used for source code is carried out pre-service, wherein, pretreated result comprises the generation abstract syntax tree, described abstract syntax tree has argument table, pretreatment module 100 comprises rreturn value type setting module 110, and rreturn value type setting module 110 is converted to predetermined form for the rreturn value that source code is had the function of pointer type rreturn value.Not processed function is searched module 200 and is used for searching whether there is not processed function at abstract syntax tree.The first address search module 300 is used for when there is not processed function in described abstract syntax tree, in not processed function, search whether have a not processed mistake get the location action statement.The first address judgment module 400 be used for described not processed function exist not processed mistake get the location action statement time, judge the whether internal layer variable of not processed function of corresponding the first variable in address got in the action statement of location according to the argument table of not processed function.The second address search module 500 is used for when described corresponding the first variable in address of getting the location action statement is the internal layer variable of described not processed function, the second identical variable of address in searching whether existence value and get the location action statement getting the location action statement after and in the statement of not processed function between exporting.The second variable judge module 600 is used for judging that whether the second variable is the internal layer variable of not processed function, if it is continues to search, otherwise call error information module 700.Error message module 700 is used for when described the second variable is not the internal layer variable of described not processed function, and the misjudgment type is also exported corresponding error message.
Pretreatment module 100 further comprises: analysis module 120 and transcode module 130.Wherein,
Analysis module 120 is used for source code being carried out lexical analysis, grammatical analysis and semantic analysis.Transcode module 130 is used for generating the transcode of source code.
Rreturn value type setting module 110 will the form of being scheduled to be made as the character string _ LXXXX of global property, and XXXX is indefinite length, the unique numeral of the overall situation.Be understandable that, above-mentioned preset kind the invention is not restricted to this only for illustrative purposes.Rreturn value type setting module 110 is with all statement return ﹠amp; A;
Change to:
_LXXXX=&a;
return_LXXXX。
Wherein a represents variable, only for illustrative purposes, the invention is not restricted to this herein, and a place can be any variable name.
Error message module 700 further comprises: type of error judge module 710, type of error judge module 710 is used for the misjudgment type, if the second type of variables is predetermined form, then type of error is that function returns mistake, if the second variable is the parameter of not processed function, then type of error is that two-dimentional pointer parameter is quoted the address in the not processed function, directly quotes the address in the not processed function otherwise type of error is outer pointer; Error message output module 720, error message output module 720 is used for exporting described error message, and wherein said error message comprises described type of error.
Internal layer variable according to the embodiment of the invention is described by outer pointer misquotation static detection device error detection process below with reference to table 1.Suppose that not processed function searches module 200 and find that not processed function is func in the table 1, and call to search and get location operational module 300.The first address search module 300 inquires not processed mistake in the function body of func the location of getting operates ﹠amp; A, and call the first address judgment module 400.The first address judgment module 400 is searched the argument table of function f unc, judges to draw p=﹠amp; The first corresponding among a variable a is the internal layer variable of func, then calls the second address search module 500.The second address search module 500 is from p=﹠amp; It is p that a begins to func function detection of end second variable identical with the address in getting the location action statement, and calls the second variable judge module 600.The second variable judge module 600 judges that p is not the internal layer variable of function.Type of error judge module 710 misjudgment types are that outer pointer has directly been quoted the address in the not processed function, and error message output module 720 output error messages comprise type of error and the information that program the 8th is warned.
Be can be used as replenishing of existing compiler by outer pointer misquotation static detection device or as independent checking tool, the internal layer address of variable is passed to outer field mistake automatically detects according to the internal layer variable of the embodiment of the invention.In the code compilation stage, by being passed to outer field behavior, the internal layer address of variable detects, can effectively save human cost, raise the efficiency, find object code (code) mistake by detecting, after correcting mistakes, the stability of code is improved, and detection accuracy is good.
Describe and to be understood in the process flow diagram or in this any process of otherwise describing or method, expression comprises module, fragment or the part of code of the executable instruction of the step that one or more is used to realize specific logical function or process, and the scope of preferred implementation of the present invention comprises other realization, wherein can be not according to order shown or that discuss, comprise according to related function by the mode of basic while or by opposite order, carry out function, this should be understood by the embodiments of the invention person of ordinary skill in the field.
In process flow diagram the expression or in this logic of otherwise describing and/or step, for example, can be considered to the sequencing tabulation for the executable instruction that realizes logic function, may be embodied in any computer-readable medium, use for instruction execution system, device or equipment (such as the computer based system, comprise that the system of processor or other can and carry out the system of instruction from instruction execution system, device or equipment instruction fetch), or use in conjunction with these instruction execution systems, device or equipment.With regard to this instructions, " computer-readable medium " can be anyly can comprise, storage, communication, propagation or transmission procedure be for instruction execution system, device or equipment or the device that uses in conjunction with these instruction execution systems, device or equipment.The more specifically example of computer-readable medium (non-exhaustive list) comprises following: the electrical connection section (electronic installation) with one or more wirings, portable computer diskette box (magnetic device), random access memory (RAM), ROM (read-only memory) (ROM), the erasable ROM (read-only memory) (EPROM or flash memory) of editing, fiber device, and portable optic disk ROM (read-only memory) (CDROM).In addition, computer-readable medium even can be paper or other the suitable media that to print described program thereon, because can be for example by paper or other media be carried out optical scanning, then edit, decipher or process to obtain described program in the electronics mode with other suitable methods in case of necessity, then it is stored in the computer memory.
Should be appreciated that each several part of the present invention can realize with hardware, software, firmware or their combination.In the above-described embodiment, a plurality of steps or method can realize with being stored in the storer and by software or firmware that suitable instruction execution system is carried out.For example, if realize with hardware, the same in another embodiment, can realize with the combination of each or they in the following technology well known in the art: have for the discrete logic of data-signal being realized the logic gates of logic function, special IC with suitable combinational logic gate circuit, programmable gate array (PGA), field programmable gate array (FPGA) etc.
Those skilled in the art are appreciated that and realize that all or part of step that above-described embodiment method is carried is to come the relevant hardware of instruction to finish by program, described program can be stored in a kind of computer-readable recording medium, this program comprises step of embodiment of the method one or a combination set of when carrying out.
In addition, each functional unit in each embodiment of the present invention can be integrated in the processing module, also can be that the independent physics of unit exists, and also can be integrated in the module two or more unit.Above-mentioned integrated module both can adopt the form of hardware to realize, also can adopt the form of software function module to realize.If described integrated module realizes with the form of software function module and during as independently production marketing or use, also can be stored in the computer read/write memory medium.
The above-mentioned storage medium of mentioning can be ROM (read-only memory), disk or CD etc.
In the description of this instructions, the description of reference term " embodiment ", " some embodiment ", " example ", " concrete example " or " some examples " etc. means to be contained at least one embodiment of the present invention or the example in conjunction with specific features, structure, material or the characteristics of this embodiment or example description.In this manual, the schematic statement of above-mentioned term not necessarily referred to identical embodiment or example.And the specific features of description, structure, material or characteristics can be with suitable mode combinations in any one or more embodiment or example.
Although illustrated and described embodiments of the invention, for the ordinary skill in the art, be appreciated that without departing from the principles and spirit of the present invention and can carry out multiple variation, modification, replacement and modification to these embodiment, scope of the present invention is by claims and be equal to and limit.

Claims (8)

1. an internal layer variable be is characterized in that by outer pointer misquotation static detection method, comprises the steps:
S1: source code is carried out pre-service be converted to predetermined form with the rreturn value that will have the function of pointer type rreturn value in the described source code, wherein, pretreated result comprises the generation abstract syntax tree, and described abstract syntax tree has argument table;
S2: search whether there is not processed function at described abstract syntax tree;
S3: if exist, then in described not processed function, search whether have a not processed mistake get the location action statement;
S4: if exist, then judge described corresponding the first variable in the address internal layer variable of described not processed function whether of getting in the action statement of location according to described argument table;
S5: if, then described get the location action statement after and search whether existence value and described the second identical variable of address in the action statement of location of getting in the statement between the outlet of described not processed function; And
S6: if there is described the second variable, judge that then whether described the second variable is the internal layer variable of described not processed function, if it is continues to search, otherwise judges described the second type of variables and export corresponding error message.
2. internal layer variable as claimed in claim 1 be is characterized in that by outer pointer misquotation static detection method, and described step S1 further comprises:
Described source code is carried out lexical analysis, grammatical analysis and semantic analysis; And
Generate the transcode of described source code.
3. internal layer variable as claimed in claim 1 be is characterized in that by outer pointer misquotation static detection method, and described predetermined form is the character string of global property.
4. internal layer variable as claimed in claim 1 be is characterized in that by outer pointer misquotation static detection method, and described judgement the second type of variables is also exported corresponding error message, further comprises:
Judge described the second type of variables, if described the second type of variables is described predetermined form, then error message is returned in output;
If described the second variable is the parameter of described not processed function, then exporting has two-dimentional pointer parameter to quote the error message of the address in the described not processed function in the described not processed function;
Otherwise export the error message that outer pointer has directly been quoted the address in the described not processed function.
5. an internal layer variable be is characterized in that by outer pointer misquotation static detection device, comprising:
Pretreatment module, described pretreatment module is used for source code is carried out pre-service, wherein, pretreated result comprises the generation abstract syntax tree, described abstract syntax tree has argument table, described pretreatment module comprises rreturn value type setting module, and described rreturn value type setting module is converted to predetermined form for the rreturn value that described source code is had the function of pointer type rreturn value;
Not processed function is searched module, and described not processed function is searched module and is used for searching whether there is not processed function at described abstract syntax tree;
The first address search module, described the first address search module are used for when there is not processed function in described abstract syntax tree, in described not processed function, search whether have a not processed mistake get the location action statement;
The first address judgment module, described the first address judgment module be used for described not processed function exist not processed mistake get the location action statement time, judge described corresponding the first variable in the address internal layer variable of described not processed function whether of getting in the action statement of location according to described argument table;
The second address search module, described the second address search module is used for when described corresponding the first variable in address of getting the location action statement is the internal layer variable of described not processed function, described get the location action statement after and search whether existence value and described the second identical variable of address in the action statement of location of getting in the statement of described not processed function between exporting;
The second variable judge module, described the second variable judge module are used for judging that whether described the second variable is the internal layer variable of described not processed function, if it is continue to search; And
Error message module, described error message module are used for when described the second variable is not the internal layer variable of described not processed function, and the misjudgment type is also exported corresponding error message.
6. internal layer variable as claimed in claim 5 be is characterized in that by outer pointer misquotation static detection device, and described pretreatment module also comprises:
Analysis module, described analysis module are used for described source code being carried out lexical analysis, grammatical analysis and semantic analysis; And
The transcode module, described transcode module is used for generating the transcode of described source code.
7. internal layer variable as claimed in claim 5 be is characterized in that by outer pointer misquotation static detection device, and described predetermined form is the character string of global property.
8. internal layer variable as claimed in claim 5 be is characterized in that by outer pointer misquotation static detection device, and the error message module comprises:
The type of error judge module, described type of error judge module is used for judging described type of error, if described the second type of variables is described predetermined form, then described type of error is that function returns mistake, if described the second variable is the parameter of described not processed function, then described type of error is that two-dimentional pointer parameter is quoted the address in the described not processed function, directly quotes address in the described not processed function otherwise described type of error is outer pointer;
Error message output module, described error message output module are used for exporting described error message, and wherein said error message comprises described type of error.
CN201210115343.3A 2012-04-18 2012-04-18 Static test method and device for misquotation of inner variables by outer pointers Active CN102855183B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210115343.3A CN102855183B (en) 2012-04-18 2012-04-18 Static test method and device for misquotation of inner variables by outer pointers

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210115343.3A CN102855183B (en) 2012-04-18 2012-04-18 Static test method and device for misquotation of inner variables by outer pointers

Publications (2)

Publication Number Publication Date
CN102855183A true CN102855183A (en) 2013-01-02
CN102855183B CN102855183B (en) 2015-04-15

Family

ID=47401786

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210115343.3A Active CN102855183B (en) 2012-04-18 2012-04-18 Static test method and device for misquotation of inner variables by outer pointers

Country Status (1)

Country Link
CN (1) CN102855183B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103914382A (en) * 2014-03-25 2014-07-09 北京邮电大学 Method for completely recognizing pointer quotation detection object
CN104281519A (en) * 2013-07-08 2015-01-14 华为技术有限公司 Method and equipment for detecting errors of program

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101017458A (en) * 2007-03-02 2007-08-15 北京邮电大学 Software safety code analyzer based on static analysis of source code and testing method therefor
CN101286132A (en) * 2008-06-02 2008-10-15 北京邮电大学 Test method and system based on software defect mode

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101017458A (en) * 2007-03-02 2007-08-15 北京邮电大学 Software safety code analyzer based on static analysis of source code and testing method therefor
CN101286132A (en) * 2008-06-02 2008-10-15 北京邮电大学 Test method and system based on software defect mode

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
GARCIARELAX: "《http://wenku.baidu.com/view/018b5a35a32d7375a41780ab.html》", 13 September 2011, 百度文库 *
夏玉辉等: "基于变量使用的静态测试方法研究", 《计算机工程与设计》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104281519A (en) * 2013-07-08 2015-01-14 华为技术有限公司 Method and equipment for detecting errors of program
WO2015003555A1 (en) * 2013-07-08 2015-01-15 华为技术有限公司 Error detection method and device for program
CN103914382A (en) * 2014-03-25 2014-07-09 北京邮电大学 Method for completely recognizing pointer quotation detection object
CN103914382B (en) * 2014-03-25 2016-06-29 北京邮电大学 A kind of abundant identification pointer quotes the method for detection object

Also Published As

Publication number Publication date
CN102855183B (en) 2015-04-15

Similar Documents

Publication Publication Date Title
Kim et al. MeCC: memory comparison-based clone detector
US8381194B2 (en) Methods and apparatuses for selective code coverage
US10915422B2 (en) Automatic setting of multitasking configurations for a code-checking system
US8954939B2 (en) Extending a development environment
Leino et al. Trigger selection strategies to stabilize program verifiers
Ivannikov et al. Static analyzer Svace for finding defects in a source program code
Prähofer et al. Static code analysis of IEC 61131-3 programs: Comprehensive tool support and experiences from large-scale industrial application
US20080313616A1 (en) Methods and systems for testing tool with comparative testing
Bond et al. Tracking bad apples: reporting the origin of null and undefined value errors
WO2009089294A2 (en) Methods and systems for generating software quality index
Reder et al. Model/analyzer: a tool for detecting, visualizing and fixing design errors in UML
US9304893B1 (en) Integrated software development and test case management system
Rodriguez-Prieto et al. An efficient and scalable platform for Java source code analysis using overlaid graph representations
CN102662825B (en) Method for detecting memory leakage of heap operational program
CN103294596A (en) Early warning method for contract-type software fault based on program invariants
CN102855183B (en) Static test method and device for misquotation of inner variables by outer pointers
Singer et al. Exploiting the correspondence between micro patterns and class names
Arndt et al. Let this graph be your witness! an attestor for verifying Java pointer programs
Rocha et al. Memory management test-case generation of C programs using bounded model checking
CN112783736B (en) Method and device for monitoring running body time of software component and electronic equipment
Zhao et al. A survey on research of code comment auto generation
Giet et al. Towards zero alarms in sound static analysis of finite state machines
Novikov et al. Detecting the use of unsafe data in software of embedded systems by means of static analysis methodology
MaIm et al. Static flow analysis of the Action Language for Foundational UML
Wong et al. Change impact analysis with stochastic dependencies

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant