Code automatic repair method, device and electronic equipment
By determining the defect location and type in the automatic code repair method and using parsing functions and multiple repair strategies to repair code snippets, the problem of traditional manual repair being time-consuming, labor-intensive and inaccurate is solved, and efficient and accurate code repair is achieved.
Patent Information
- Application Number
- CN202411571601.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2044-11-05
AI Technical Summary
Traditional manual code inspection to discover and repair defects is time-consuming and labor-intensive, and it is difficult to ensure the accuracy of the repairs.
By determining the location and type of defective code in the target program, using the parsing function associated with the defect type to intercept code fragments, and calling the corresponding repair strategy to repair it, combined with large models and example guidance, correction scripts and other repair strategies, the accuracy and efficiency of the repair are ensured.
It improves the accuracy and efficiency of code repair, reduces the interference of redundant code, ensures that the repaired code meets the integrity constraints and preset results, and improves the reliability and availability of code repair.
Smart Images

Figure CN119597293B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, in particular to technical fields such as large models, 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 a major threat to network security. A defect, also known as an error, bug, or problem, refers to any problem in the code that does not conform to expected behavior or standards. Examples include syntax errors, logical flaws, and security vulnerabilities. Traditional methods of manually reviewing code to discover and fix defects are not only time-consuming and labor-intensive, but also difficult to guarantee the accuracy of the fixed code.
[0003] Therefore, there is an urgent need for an automatic code repair method with high accuracy. Summary of the Invention
[0004] The present disclosure provides a code automatic repair method, device and electronic device.
[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 the type of defect 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] Call the repair strategy associated with the defect type to repair the defective code snippet and obtain the repaired target code snippet.
[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 location of defective code and defect type in the target program;
[0011] An interception module is 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 to enable the at least one processor to perform 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 contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings are provided to facilitate a better understanding of the present invention 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 an automatic code repair device provided by an embodiment of the present disclosure;
[0025] Figure 6 4 is a block diagram of an electronic device for automatically repairing electronic devices using code according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] The following description of exemplary embodiments of the present disclosure is made in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding. These details should be considered as merely exemplary. Therefore, those skilled in the art will recognize 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 (AI) is the study of how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, and big data processing. AI software technologies encompass computer vision, speech recognition, natural language processing, as well as deep learning, big data processing, and knowledge graphs.
[0028] The following describes in detail the automatic code repair method, device, electronic device, and storage medium according to 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 automatic code repair provided by an embodiment of the present disclosure.
[0032] like Figure 1 As shown, the method includes:
[0033] Step 101: Determine the location and type of defect code in the target program.
[0034] In this application, the target program can be analyzed using static code analysis tools to determine the location and type of defective code in the target program. Defect types include source code defect types, configuration defect types, etc., and the location of the defective code can be any information indicating the specific location of the defective code in the target program, such as the line number of the code, which is not limited in this application.
[0035] Step 102: Using the parsing function associated with the defect type, intercept the defect code fragment at the defect code location.
[0036] Generally, programs contain program files such as source code files and configuration files, and both source code files and configuration files may contain defects. For defects that appear in source code files, their defect type is determined to be a source code defect type. For defects that appear in configuration files, their defect type is determined to be a configuration defect type. Parsing functions associated with each defect type are pre-set in the system. The parsing functions associated with each defect type can then be used to intercept the defective code fragment at the defective code location. This allows different parsing functions to be used for different program files to accurately intercept the defective code fragment. This allows defects to be accurately repaired based on the defective code fragment. Furthermore, configuration defect types can be further subdivided into combined configuration defect types, independent configuration defect types, and other types, with parsing functions associated with each subdivided type. This allows for more targeted interception of defective code fragments, thereby improving the accuracy of intercepted 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: Invoke the repair strategy associated with the defect type to repair the defective code snippet and obtain a repaired target code snippet.
[0039] In this application, the effectiveness of each repair strategy for each defect type can be pre-tested. Then, based on the repair results, the repair strategies associated with each defect type are integrated. When a defect of a certain defect type occurs, the repair strategy associated with that defect type can be invoked to repair the defective code fragment and obtain the repaired target code fragment.
[0040] For example, if the large model's defect repair accuracy for a certain defect type exceeds a preset threshold, that defect type can be associated with the large model. The large model can then be called upon to repair the defective code snippet of that defect type, and the large model will output the repaired target code snippet.
[0041] Alternatively, when the large model's defect repair accuracy for a certain defect type is less than or equal to a preset threshold, an example associated with that defect type can be pre-set in the system. This example is then fed into the large model as a prompt, guiding it to parse the defective code snippet and outputting the corrected target code snippet. This improves the accuracy of code corrections.
[0042] Alternatively, for simple defects like syntax errors, a correction script can be designed. This script can then be called to fix the defective code snippet. This ensures the accuracy of code correction while improving its efficiency.
[0043] Therefore, by setting up multiple repair strategies, accessing multiple repair capabilities, and using different repair strategies to repair defective code fragments for different defect types, it is beneficial to improve the accuracy of code repair and enhance the repair effect.
[0044] In this application, the location and type of defective code in the target program are determined. A parsing function associated with the defect type is then used to extract a defective code snippet at the defective code location. The defective code snippet is then repaired using a repair strategy associated with the defect type, resulting in a repaired target code snippet. Thus, using different parsing functions to extract defective code snippets for different defect types improves the accuracy of locating the defective code snippet, thereby reducing interference from redundant code. Furthermore, using different repair strategies for different defect types to repair the defective code snippet improves the accuracy of code repair.
[0045] Figure 2 A flowchart of a method for automatic code repair provided by an embodiment of the present disclosure.
[0046] like Figure 2 As shown, the method includes:
[0047] Step 201: Determine the location and type of defect code 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 location.
[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 : Detect the intermediate code snippet based on the preset exception rule, and determine whether to further repair the intermediate code snippet based on the detection result to obtain the final target code snippet.
[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 this application, when the intermediate code fragment is 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 satisfies the integrity constraint. If the integrity constraint is satisfied, the intermediate code fragment is determined as the target code fragment. If the integrity constraint is not satisfied, the missing preset characters can be supplemented to obtain the target code fragment. This ensures the accuracy of the code repair.
[0054] Alternatively, the output of the intermediate code snippet can be checked to see if it matches a preset result. If so, the intermediate code snippet is determined as the target code snippet. If not, the intermediate code snippet can be displayed and manually modified for it to obtain the final target code snippet. This ensures the accuracy of the 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. A static code scan is then performed on the repaired target program to determine whether it contains defects. This improves the reliability of the code repair process.
[0056] In this application, the location and type of defective code in the target program are determined. Then, the parsing function associated with the defective type is used to intercept the defective code fragment at the defective code location. Then, the repair strategy associated with the defective type is called to repair the defective code fragment, obtaining a repaired intermediate code fragment. The intermediate code fragment is then tested based on preset exception rules to determine whether to further repair the intermediate code fragment based on the test results, thereby obtaining the final target code fragment. Thus, by further testing the repaired intermediate code fragment using exception rules, 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 automatic code repair provided by an embodiment of the present disclosure.
[0058] like Figure 3 As shown, the method includes:
[0059] Step 301: Determine the location and type of defect code in the target program.
[0060] In this application, the specific implementation process of step 301 can be found in the detailed description of any embodiment of this application and will not be repeated here.
[0061] Step 302: When the defect type is a combined configuration defect type, the preceding and following nodes of the defect code position are determined by keyword matching, and the configuration information between the preceding and following nodes is determined as a defect code fragment.
[0062] Typically, programs consist of source code files and configuration files, both of which may contain defects. Different parsing functions can be used for different program files to accurately identify defective code snippets. This allows for accurate repair of defects based on these snippets.
[0063] When multiple configuration items in a configuration file interact with each other, they can be referred to as combined configuration items (for example, SQL (Structured Query Language) injection-related configuration). When a configuration item does not interact with other configuration items, it can be referred to as an independent item (for example, a password set in a login scenario). Combined configuration items and independent items can be pre-identified in the configuration file.
[0064] When the defect code location is a combination configuration item, the defect type can be determined to be a combination configuration defect. Because defects caused by the configuration of combination configuration items depend on the preceding and following code logic, or are the result of a series of operations corresponding to these configuration items, repairing the defect requires combining relevant code segments to determine a repair solution. Therefore, in the case of a combination configuration defect, keyword matching is used to determine the preceding and following nodes of the defect code location, and the configuration information between the preceding and following nodes is determined as the defective code segment.
[0065] Step 303: When the defect type is an independent configuration defect type, the row where the defective code is located is determined as a defective code fragment.
[0066] In this application, when the defect code location is an independent item, the defect type can be determined to be an independent configuration defect. Because the defect caused by the configuration of an independent item does not depend on the state or logic of other configuration items, it can be directly corrected in the row where the defect is located. Therefore, if the defect type is an independent configuration defect, the row where the defect code location 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 source code files, their defect type is determined to be a source code defect type. In the case of a source code defect type, the function code to which the defective code location belongs is determined to be a defective code fragment. Subsequently, the code error at the defective code location is repaired based on this defective code fragment, avoiding interference from other codes while taking into account the overall logic involved in the code error, thereby facilitating 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 this application, the specific implementation process of step 305 can be found in the detailed description of any embodiment of this application and will not be repeated here.
[0071] In this 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 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 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 source code defect type, the code involved is intercepted as the defect code snippet, thereby avoiding interference from other codes while taking into account the overall logic involved in the code error, which is beneficial to the accuracy of code repair.
[0072] Figure 4 A flowchart of a method for automatic code repair provided by an embodiment of the present disclosure.
[0073] like Figure 4 As shown, the method includes:
[0074] Step 401: Determine the location and type of defect code 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 location.
[0076] Step 403: Invoke the repair strategy associated with the defect type to repair the defective code fragment and obtain the repaired intermediate code fragment.
[0077] In this application, the specific implementation process of steps 401 to 403 can be found in the detailed description of any embodiment of this application and will not be repeated here.
[0078] Step 404: align the target code fragment to obtain the aligned target code fragment.
[0079] In this application, the target code snippet can be formatted and aligned to obtain the aligned target code snippet. For example, the target code snippet can be indented so that the repaired target code snippet is not indented the same as the original code. Alternatively, during the repair process, an identifier may be added, such as an identifier corresponding to the starting line where the defect was triggered, or an identifier for key line information. Identifiers in the target code snippet can be removed.
[0080] In this application, the location of the defective code and the defect type in the target program are determined, and then the parsing function associated with the defect type is used to intercept the defective code fragment at the defective code location, and the repair strategy associated with the defect type is called to repair the defective 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 embodiment, the embodiment of the present disclosure 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] Determination module 510, for determining the location and type of defective code in the target program;
[0084] The interception module 520 is used to intercept the defect code fragment at the defect code location by using the parsing function associated with the defect type;
[0085] The repair module 530 is configured to call the repair strategy defect associated with the defect type to repair the code snippet and obtain a repaired target code snippet.
[0086] In a possible implementation of the embodiment of the present disclosure, the interception module 520 is configured to:
[0087] If the defect type is a combined configuration defect type, the previous and next nodes of the defect code location are determined through 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 line where the defective code is located is determined as the defective code fragment.
[0089] In a possible implementation of the embodiment of the present disclosure, the interception module 520 is configured to:
[0090] 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 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, the large model is called to parse the defective code snippet and obtain the repaired code snippet output by the large 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 configured 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 embodiment of the automatic code repair method is also applicable to the device of this embodiment, so it will not be repeated here.
[0104] In this application, the location and type of defective code in the target program are determined. A parsing function associated with the defect type is then used to extract a defective code snippet at the defective code location. The defective code snippet is then repaired using a repair strategy associated with the defect type, resulting in a repaired target code snippet. Thus, using different parsing functions to extract defective code snippets for different defect types improves the accuracy of locating the defective code snippet, thereby reducing interference from redundant code. Furthermore, using different repair strategies for different defect types to repair the defective code snippet improves the accuracy of code repair.
[0105] According to an embodiment of the present disclosure, the present disclosure further 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 embodiments 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 assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are provided as examples only and are not intended to limit the implementation of the present disclosure described and / or claimed 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 into a RAM (Random Access Memory) 603. Various programs and data required for the operation of the device 600 can also be stored in the RAM 603. 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] Various components in device 600 are connected to I / O interface 605, including an input unit 606, such as a keyboard, mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a magnetic disk, optical disk, etc.; and a communication unit 609, such as a network card, modem, wireless communication transceiver, etc. The communication unit 609 allows device 600 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0109] The computing unit 601 can be a variety of general-purpose and / or specialized 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 Unit), various specialized AI (Artificial Intelligence) computing chips, various computing units that run machine learning model algorithms, a 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 can be implemented as a computer software program that is tangibly contained in a machine-readable medium, such as the storage unit 608. In some embodiments, part or all of the computer program can 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 can 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 herein can 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 can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that can 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 can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, 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 apparatus. 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 apparatus, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), an optical storage device, a magnetic storage device, 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 can 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 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 can 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 server are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host, a host product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosts and VPS (Virtual Private Server) services. The server may also be a server in a distributed system or a server integrated with blockchain.
[0116] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved. This is not limited herein.
[0117] The above specific embodiments do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure shall be included within the scope of protection of this disclosure.
Claims
1. A code automatic repair method, wherein: include: Determine the location of defective code and the type of defect 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 obtain a repaired target code fragment.
2. The method according to 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 location 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 a case where the defect type is an independent configuration defect type, the row where the defective code position is located is determined as a defective code segment.
3. The method according to 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 location 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 according to claim 1, wherein The repair strategy includes at least one of the following: Calling the large model to parse the defective code snippet and obtain the repaired code snippet output by the large model; Based on the example of the defect type association, calling the large model to parse the defective code snippet, and obtaining the repaired code snippet output by the large 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 according to 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: Invoking the repair strategy associated with the defect type to repair the defective code fragment and obtain a repaired intermediate code fragment; The intermediate code fragment is detected based on a preset exception rule, so as to determine whether to further repair the intermediate code fragment based on the detection result, and obtain a final target code fragment.
6. The method according to 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 location of defective code and defect type in the target program; An interception module, configured to intercept a defective code fragment at the defective code location by utilizing a 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 according to claim 8, wherein The interception module is used to: 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 a case where the defect type is an independent configuration defect type, the row where the defective code position is located is determined as a defective code segment.
10. The device according to claim 8, wherein The interception module is used to: 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 according to claim 8, wherein The repair strategy includes at least one of the following: Calling the large model to parse the defective code snippet and obtain the repaired code snippet output by the large model; Based on the example of the defect type association, calling the large model to parse the defective code snippet, and obtaining the repaired code snippet output by the large model; A correction script is called to repair the defective code fragment, wherein the correction script is used to correct syntax errors.
12. The apparatus of claim 8, wherein: The repair module is used to: Invoking the repair strategy associated with the defect type to repair the defective code fragment and obtain a repaired intermediate code fragment; The intermediate code fragment is detected based on a preset exception rule, so as to determine whether to further repair the intermediate code fragment based on the detection result, and obtain a final target code fragment.
13. The device of claim 12, 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 apparatus 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 to 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
Code vulnerability checking method and device, electronic equipment and storage medium
CN117195225A