Code automatic repairing method and device and electronic equipment
By determining the location and type of defective code in the automatic code repair method, using parsing functions to intercept code snippets, and applying repair strategies to repair, the problem of time-consuming and inaccurate traditional manual repair code is solved, and high accuracy and efficient automatic code repair is achieved.
Patent Information
- Application Number
- CN202411571601.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-11-05
AI Technical Summary
Traditional manual code inspection, the method of discovering and repairing defects is time-consuming and labor-intensive and difficult to ensure the accuracy of repairing codes. It is urgent to require a highly accurate automatic code repair method.
By determining the location and defect type of defect in the target program, the defect code snippet is intercepted by using the analytical function associated with the defect type, and the defect code snippet is called to repair the defect code snippet to obtain the fixed target code snippet.
Improves the accuracy and efficiency of code repair, reduces interference from redundant code, and ensures that the fixed code does not introduce new problems.
Smart Images

Figure CN119597293A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, in particular to the field of large models and other technical fields, and specifically to a method, device and electronic device for automatic code repair. Background Art
[0002] With the rapid development of software development, code defects have become one of the main threats to network security. Among them, defects, also known as errors, bugs or problems, refer to any problems in the code that do not meet expected behaviors or standards. For example, defects include syntax errors, logical defects, security vulnerabilities, etc. The traditional method of manually checking the code to find and fix defects is not only time-consuming and labor-intensive, but also difficult to ensure the accuracy of the repaired code.
[0003] Therefore, there is an urgent need for an automatic code repair method with high accuracy. Summary of the invention
[0004] The present invention provides a method, device and electronic device for automatic code repair.
[0005] According to one aspect of the present disclosure, a method for automatic code repair is provided, comprising:
[0006] Determine the location of defective code and defect type in the target program;
[0007] Using the parsing function associated with the defect type, the defect code fragment at the defect code location is intercepted;
[0008] The repair strategy associated with the defect type is called to repair the defective code fragment and obtain the repaired target code fragment.
[0009] According to another aspect of the present disclosure, there is provided a code automatic repair device, comprising:
[0010] A determination module, used to determine the defect code location and defect type in the target program;
[0011] An interception module, used to intercept the defect code fragment at the defect code location by using the parsing function associated with the defect type;
[0012] The repair module is used to call the repair strategy associated with the defect type to repair the defective code fragment and obtain the repaired target code fragment.
[0013] According to another aspect of the present disclosure, there is provided an electronic device, comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to at least one processor; wherein,
[0016] The memory stores instructions that can be executed by at least one processor. The instructions are executed by the at least one processor so that the at least one processor can execute the method of the above embodiment.
[0017] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute the method according to the above embodiment.
[0018] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0020] Figure 1 A flowchart of a code automatic repair method provided by an embodiment of the present disclosure;
[0021] Figure 2 A flowchart of another automatic code repair method provided by an embodiment of the present disclosure;
[0022] Figure 3 A flowchart of another automatic code repair method provided by an embodiment of the present disclosure;
[0023] Figure 4 A flowchart of another automatic code repair method provided by an embodiment of the present disclosure;
[0024] Figure 5 A schematic diagram of the structure of a code automatic repair device provided by an embodiment of the present disclosure;
[0025] Figure 6 It is a block diagram of a code-automatic repair electronic device for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0027] Artificial intelligence is a discipline that studies the use of computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It includes both hardware-level technical fields and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies include computer vision technology, speech recognition technology, natural language processing technology, as well as deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0028] The following describes in detail the automatic code repair method, device, electronic device and storage medium of the embodiments of the present disclosure with reference to the accompanying drawings.
[0029] It should be noted that the automatic code repair method implemented in the present disclosure is configured in an automatic code repair device (hereinafter referred to as the repair device) for illustration, and the repair device can be applied to any electronic device so that the electronic device can perform the function of automatic code repair.
[0030] Among them, the electronic device can be any device with computing capabilities, such as a personal computer (PC), a mobile terminal, etc. The mobile terminal can be, for example, a mobile phone, a tablet computer, a personal digital assistant, a wearable device, and other hardware devices with various operating systems, touch screens and / or display screens.
[0031] Figure 1 A flowchart of a method for automatically repairing codes provided by an embodiment of the present disclosure.
[0032] like Figure 1 As shown, the method includes:
[0033] Step 101, determine the defect code location and defect type in the target program.
[0034] In this application, the target program can be analyzed by static code analysis tools to determine the location and defect type of the defect code in the target program. The defect type includes source code defect type, configuration defect type, etc. The defect code location can be any information such as code line number that is used to indicate the specific location of the defect code in the target program, and this application does not limit this.
[0035] Step 102: using the parsing function associated with the defect type, intercept the defect code fragment at the defect code position.
[0036] A general program includes program files such as source code files and configuration files, and both source code files and configuration files may have defects. For defects in source code files, the defect type is determined to be a source code defect type. For defects in configuration files, the defect type is determined to be a configuration defect type. And the parsing functions associated with each defect type are pre-set in the system. After that, the parsing function associated with the defect type can be used to intercept the defective code fragment at the defective code location. In this way, different parsing functions can be used for different program files to accurately intercept the defective code fragment. In this way, defects can be accurately repaired based on the defective code fragment. In addition, the configuration defect type can be further subdivided into combined configuration defect type, independent configuration defect type, etc., and the parsing function associated with each subdivided type is set. Further targeted interception of defective code fragments is achieved, thereby improving the accuracy of intercepting defective code fragments.
[0037] Therefore, for different defect types, different parsing methods are used to intercept defective code fragments, which ensures that the intercepted defective code fragments do not contain redundant information and ensures the validity of the information contained in the defective code fragments.
[0038] Step 103: Call the repair strategy associated with the defect type to repair the defective code fragment and obtain the repaired target code fragment.
[0039] In this application, the effect of each repair strategy on the defect repair of each defect type can be tested in advance. Afterwards, the repair strategies associated with each defect type are integrated according to the repair effect. When a defect of a certain defect type occurs, the repair strategy associated with the defect type can be called to repair the defective code fragment and obtain the repaired target code fragment.
[0040] For example, when the big model's defect repair accuracy for a certain defect type is greater than a preset threshold, the defect type can be associated with the big model. After that, the big model can be called to repair the defect code snippet of the defect type, and the big model outputs the repaired target code snippet.
[0041] Alternatively, when the defect repair accuracy of the big model for a certain defect type is less than or equal to a preset threshold, an example associated with the defect type can be pre-set in the system. Afterwards, the example is input into the big model as prompt information to guide the big model to parse the defect code snippet, and the big model outputs the repaired target code snippet. This improves the accuracy of code correction.
[0042] Alternatively, for simple defects such as syntax errors, a correction script for the defect can be designed. Afterwards, the correction script is called to repair the defective code fragment, thereby ensuring the accuracy of code correction and improving the efficiency of code correction.
[0043] Therefore, by setting multiple repair strategies, accessing multiple repair capabilities, and using different repair strategies to repair defective code fragments for different defect types, it is helpful to improve the accuracy of code repair and enhance the repair effect.
[0044] In the present application, the defect code location and defect type in the target program are determined, and then the defect code fragment at the defect code location is intercepted using the parsing function associated with the defect type, and then the repair strategy associated with the defect type is called to repair the defect code fragment to obtain the repaired target code fragment. Therefore, using different parsing functions to intercept defect code fragments for different defect types is conducive to improving the accuracy of defect code fragment location, thereby reducing the interference of redundant code. At the same time, using different repair strategies for different defect types to repair defect code fragments is conducive to improving the accuracy of code repair.
[0045] Figure 2 A flowchart of a method for automatically repairing codes provided by an embodiment of the present disclosure.
[0046] like Figure 2 As shown, the method includes:
[0047] Step 201, determine the defect code location and defect type in the target program.
[0048] Step 202: using the parsing function associated with the defect type, intercept the defect code fragment at the defect code position.
[0049] Step 203: Call the repair strategy associated with the defect type to repair the defective code fragment and obtain the repaired intermediate code fragment.
[0050] In the present application, the specific implementation process of steps 201 to 203 can be found in the detailed description of any embodiment of the present application and will not be repeated here.
[0051] Step 204 , the intermediate code fragment is detected based on the preset exception rule, so as to determine whether to further repair the intermediate code fragment based on the detection result, and obtain the final target code fragment.
[0052] Among them, the exception rules include: when the intermediate code fragment is a function code, the intermediate code fragment satisfies the integrity constraint; and / or the output of the intermediate code fragment meets the preset result.
[0053] In the present application, when the intermediate code fragment is a function code, regular matching can be used to determine whether the intermediate code fragment contains preset characters (such as symmetrical "{}", etc.) to determine whether the intermediate code meets the integrity constraint. If the integrity constraint is met, the intermediate code fragment is determined as the target code fragment. If the integrity constraint is not met, the missing preset characters can be filled to obtain the target code fragment. This ensures the accuracy of code repair.
[0054] Alternatively, it is also possible to check whether the output of the intermediate code snippet is a preset result. If the output is a preset result, the intermediate code snippet is determined as the target code snippet. If the output is not a preset result, the intermediate code snippet can be displayed, and manual correction settings for the intermediate code snippet can be received to obtain the final target code snippet. This ensures the accuracy of code repair.
[0055] Optionally, the target code snippet can be used to replace the defective code snippet in the target program to generate a repaired target program. Afterwards, a static code scan is performed on the repaired target program to determine whether the repaired target program has defects, thereby improving the reliability of code repair.
[0056] In this application, the defect code location and defect type in the target program are determined, and then the defect code fragment at the defect code location is intercepted by using the parsing function associated with the defect type, and then the repair strategy associated with the defect type is called to repair the defect code fragment, and the repaired intermediate code fragment is obtained, and the intermediate code fragment is detected based on the preset exception rules to determine whether to further repair the intermediate code fragment based on the detection results to obtain the final target code fragment. Therefore, the repaired intermediate code fragment is further detected by the exception rules, and a post-processing verification mechanism is introduced to ensure that the repaired code does not introduce new problems, thereby improving the availability and accuracy of code repair.
[0057] Figure 3 A flowchart of a method for automatically repairing codes provided by an embodiment of the present disclosure.
[0058] like Figure 3 As shown, the method includes:
[0059] Step 301, determine the defect code location and defect type in the target program.
[0060] In the present application, the specific implementation process of step 301 can be found in the detailed description of any embodiment of the present application, and will not be repeated here.
[0061] Step 302: When the defect type is a combined configuration defect type, the previous and next nodes of the defect code position are determined by keyword matching, and the configuration information between the previous and next nodes is determined as a defect code fragment.
[0062] Generally, a program includes source code files and configuration files, and both source code files and configuration files may have defects. Different parsing functions can be used for different program files to accurately intercept defective code fragments. In this way, defects can be accurately repaired based on the defective code fragments.
[0063] When multiple configuration items in a configuration file have mutual influences, the multiple configuration items can be called combined configuration items (for example, SQL (Structured Query Language) injection related configuration). When a configuration item does not have mutual influences with other configuration items, the item can be called an independent item (for example, a password set in a login scenario). Combined configuration items and independent items can be identified in the configuration file in advance.
[0064] When the defect location code position is a combined configuration item, the defect type can be determined to be a combined configuration defect type. Since the defect caused by the configuration of the combined configuration item depends on the previous and next code logic, or is caused by the result of a series of operations corresponding to the configuration items, when repairing the defect, it is necessary to combine the relevant code segments to determine the repair plan. Therefore, in the case where the defect type is a combined configuration defect type, the previous and next nodes of the defect code location are determined by keyword matching, and the configuration information between the previous and next nodes is determined as a defect code fragment.
[0065] Step 303: When the defect type is an independent configuration defect type, the row where the defect code position is located is determined as a defect code fragment.
[0066] In this application, when the defect position code position is an independent item, the defect type can be determined to be an independent configuration defect type. Since the defect caused by the configuration of the independent item does not depend on the state or logic of other configuration items, the row where the defect is located can be directly corrected. Therefore, when the defect type is an independent configuration defect type, the row where the defect code position is located is determined to be a defective code fragment.
[0067] Step 304: When the defect type is a source code defect type, the function code to which the defect code position belongs is determined as a defect code fragment.
[0068] In this application, for defects (such as syntax errors, logic defects, security vulnerabilities, etc.) that appear in the source code file, the defect type is determined as a source code defect type. In the case where the defect type is a source code defect type, the function code to which the defective code position belongs is determined as a defective code fragment. Subsequently, the code error at the defective code position is repaired based on the defective code fragment, avoiding interference from other codes while taking into account the overall logic involved in the code error, which is conducive to the accuracy of code repair.
[0069] Step 305: Call the repair strategy associated with the defect type to repair the defective code fragment and obtain the repaired intermediate code fragment.
[0070] In the present application, the specific implementation process of step 305 can be found in the detailed description of any embodiment of the present application, and will not be repeated here.
[0071] In the present application, the defect code location and defect type in the target program are determined. Then, when the defect type is a combined configuration defect type, the front and rear nodes of the defect code location are determined by keyword matching, and the configuration information between the front and rear nodes is determined as a defect code snippet. When the defect type is an independent configuration defect type, the line where the defect code location is located is determined as the defect code snippet, and when the defect type is a source code defect type, the function code to which the defect code location belongs is determined as the defect code snippet. Then, the repair strategy associated with the defect type is called to repair the defect code snippet and obtain the repaired intermediate code snippet. Thus, for defects of the independent configuration defect type, only the line code where the defect code location is located is intercepted as the defect code snippet, and for defects of the combined configuration defect type and the source code defect type, the code involved is intercepted as the defect code snippet, so as to avoid interference from other codes while taking into account the overall logic involved in the code error, thereby facilitating the accuracy of code repair.
[0072] Figure 4 A flowchart of a method for automatically repairing codes provided by an embodiment of the present disclosure.
[0073] like Figure 4 As shown, the method includes:
[0074] Step 401, determine the defect code location and defect type in the target program.
[0075] Step 402: using the parsing function associated with the defect type, intercept the defect code fragment at the defect code position.
[0076] Step 403: Call the repair strategy associated with the defect type to repair the defective code fragment and obtain the repaired intermediate code fragment.
[0077] In the present application, the specific implementation process of steps 401 to 403 can be found in the detailed description of any embodiment of the present application and will not be repeated here.
[0078] Step 404: align the target code fragment to obtain the target code fragment after the alignment.
[0079] In this application, the target code snippet may be format-aligned to obtain the target code snippet after format alignment. For example, the target code snippet may be indented so that the repaired target code snippet is inconsistent with the original code indentation. Alternatively, an identifier may be added during the repair process, such as an identifier corresponding to the starting line that identifies the defect trigger, or an identifier for key line information. The identifier in the target code snippet may be removed.
[0080] In the present application, the defect code location and defect type in the target program are determined, and then the defect code fragment at the defect code location is intercepted by using the parsing function associated with the defect type, and the repair strategy associated with the defect type is called to repair the defect code fragment to obtain the repaired intermediate code fragment, and then the target code fragment is format-aligned to obtain the target code fragment after format alignment. Thus, the format alignment of the repaired target code fragment ensures that the repaired code is not redundant and enhances readability on the one hand, and the repaired code can be used directly without modification on the other hand, which is convenient for upper-level callers and business personnel to adopt at low cost. In order to realize the above-mentioned embodiment, the disclosed embodiment also proposes a code automatic repair device.
[0081] Figure 5 A schematic diagram of the structure of an automatic code repair device provided in an embodiment of the present disclosure.
[0082] like Figure 5 As shown, the automatic code repair device 500 includes: a determination module 510, an interception module 520, and a repair module 530.
[0083] A determination module 510 is used to determine the defect code location and defect type in the target program;
[0084] The interception module 520 is used to intercept the defect code fragment at the defect code position by using the parsing function associated with the defect type;
[0085] The repair module 530 is used to call the repair strategy defect associated with the defect type to repair the code fragment and obtain the repaired target code fragment.
[0086] In a possible implementation of the embodiment of the present disclosure, the interception module 520 is used to:
[0087] When the defect type is a combined configuration defect type, the previous and next nodes of the defect code location are determined by keyword matching, and the configuration information between the previous and next nodes is determined as the defect code fragment;
[0088] When the defect type is an independent configuration defect type, the row where the defect code position is located is determined as the defect code fragment.
[0089] In a possible implementation of the embodiment of the present disclosure, the interception module 520 is used to:
[0090] When the defect type is a source code defect type, the function code to which the defect code position belongs is determined as the defect code fragment.
[0091] In a possible implementation of the embodiment of the present disclosure, the repair strategy includes at least one of the following:
[0092] Call the big model to parse the defective code snippet and obtain the repaired code snippet output by the big model;
[0093] Based on the example of defect type association, call the big model to parse the defect code snippet and obtain the repaired code snippet output by the big model;
[0094] A correction script is called to repair the defective code fragment, wherein the correction script is used to correct syntax errors.
[0095] In a possible implementation of the embodiment of the present disclosure, the repair module 530 is used to:
[0096] Call the repair strategy associated with the defect type to repair the defective code fragment and obtain the repaired intermediate code fragment;
[0097] The intermediate code fragment is detected based on the preset exception rules to determine whether to further repair the intermediate code fragment based on the detection result to obtain the final target code fragment.
[0098] In a possible implementation of the embodiment of the present disclosure, the exception rule includes:
[0099] In the case where the intermediate code fragment is a function code, the intermediate code fragment satisfies the integrity constraint; and / or,
[0100] The output of the intermediate code snippet meets the preset results.
[0101] In a possible implementation of the embodiment of the present disclosure, the following further includes:
[0102] The alignment module is used to perform format alignment on the target code fragment and obtain the target code fragment after format alignment.
[0103] It should be noted that the explanation of the aforementioned code automatic repair method embodiment is also applicable to the device of this embodiment, so it will not be repeated here.
[0104] In the present application, the defect code location and defect type in the target program are determined, and then the defect code fragment at the defect code location is intercepted using the parsing function associated with the defect type, and then the repair strategy associated with the defect type is called to repair the defect code fragment to obtain the repaired target code fragment. Therefore, using different parsing functions to intercept defect code fragments for different defect types is conducive to improving the accuracy of defect code fragment location, thereby reducing the interference of redundant code. At the same time, using different repair strategies for different defect types to repair defect code fragments is conducive to improving the accuracy of code repair.
[0105] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
[0106] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0107] like Figure 6 As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 602 or a computer program loaded from a storage unit 608 to a RAM (Random Access Memory) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An I / O (Input / Output) interface 605 is also connected to the bus 604.
[0108] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0109] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as the automatic code repair method. For example, in some embodiments, the automatic code repair method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the automatic code repair method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to execute the automatic code repair method in any other appropriate manner (for example, by means of firmware).
[0110] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0111] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0112] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0113] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0114] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.
[0115] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business s scalability in traditional physical hosts and VPS services (Virtual Private Server). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0116] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0117] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for automatic code repair, wherein: include: Determine the location of defective code and defect type in the target program; Using the parsing function associated with the defect type, intercepting the defect code fragment at the defect code position; The repair strategy associated with the defect type is called to repair the defective code fragment, and a repaired target code fragment is obtained.
2. The method of claim 1, wherein: The method of utilizing the parsing function associated with the defect type to intercept the defect code fragment at the defect code position includes: In the case where the defect type is a combined configuration defect type, determining the previous and next nodes of the defect code position by keyword matching, and determining the configuration information between the previous and next nodes as a defect code fragment; In the case where the defect type is an independent configuration defect type, the row where the defect code position is located is determined as a defect code fragment.
3. The method of claim 1, wherein: The method of utilizing the parsing function associated with the defect type to intercept the defect code fragment at the defect code position includes: In the case that the defect type is a source code defect type, the function code to which the defect code position belongs is determined as a defect code fragment.
4. The method of claim 1, wherein: The repair strategy includes at least one of the following: Calling the big model to parse the defective code snippet, and obtaining the repaired code snippet output by the big model; Based on the example of the defect type association, calling the big model to parse the defect code snippet, and obtaining the repaired code snippet output by the big model; A correction script is called to repair the defective code fragment, wherein the correction script is used to correct syntax errors.
5. The method of claim 1, wherein: The calling of the repair strategy associated with the defect type to repair the code snippet and obtain a repaired target code snippet includes: Calling the repair strategy associated with the defect type to repair the defective code fragment, and obtaining a repaired intermediate code fragment; The intermediate code fragment is detected based on a preset exception rule to determine whether to further repair the intermediate code fragment based on the detection result to obtain a final target code fragment.
6. The method of claim 5, wherein: The exception rules include: In the case where the intermediate code fragment is a function code, the intermediate code fragment satisfies the integrity constraint; and / or, The output of the intermediate code fragment meets the preset result.
7. The method of claim 1, wherein: Also includes: Perform format alignment on the target code fragment to obtain the target code fragment after format alignment.
8. A code automatic repair device, wherein: include: A determination module, used to determine the defect code location and defect type in the target program; An interception module, used to intercept the defect code fragment at the defect code position by using the parsing function associated with the defect type; The repair module is used to call the repair strategy associated with the defect type to repair the code fragment and obtain a repaired target code fragment.
9. The device of claim 8, wherein: The interception module is used for: In the case where the defect type is a combined configuration defect type, determining the previous and next nodes of the defect code position by keyword matching, and determining the configuration information between the previous and next nodes as a defect code fragment; In the case where the defect type is an independent configuration defect type, the row where the defect code position is located is determined as a defect code fragment.
10. The device of claim 8, wherein: The interception module is used for: In the case that the defect type is a source code defect type, the function code to which the defect code position belongs is determined as a defect code fragment.
11. The device of claim 8, wherein: The repair strategy includes at least one of the following: Calling the big model to parse the defective code snippet, and obtaining the repaired code snippet output by the big model; Based on the example of the defect type association, calling the big model to parse the defect code snippet, and obtaining the repaired code snippet output by the big model; A correction script is called to repair the defective code fragment, wherein the correction script is used to correct syntax errors.
12. The device of claim 8, wherein: The repair module is used to: Calling the repair strategy associated with the defect type to repair the defective code fragment, and obtaining a repaired intermediate code fragment; The intermediate code fragment is detected based on a preset exception rule to determine whether to further repair the intermediate code fragment based on the detection result to obtain a final target code fragment.
13. The device of claim 15, wherein: The exception rules include: In the case where the intermediate code fragment is a function code, the intermediate code fragment satisfies the integrity constraint; and / or, The output of the intermediate code fragment meets the preset result.
14. The device of claim 8, wherein: Also includes: The alignment module is used to perform format alignment on the target code fragment and obtain the target code fragment after format alignment.
15. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.
16. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.
17. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method for automatically repairing program crash defect based on question-answer website analysis
CN105335246A
Method for acquiring data of Githhub open source platform and source code defect repairing system
CN113127339A
Software source code defect detection method and system, electronic equipment and storage medium
CN113641586A
Automatic code defect positioning and repairing method
CN114416421A
Code vulnerability checking method and device, electronic equipment and storage medium
CN117195225A
Cited By
Code defect automatic detection and repair method based on artificial intelligence
CN120407371A