Code detection and program compilation method, device and equipment and computer readable storage medium

By automatically detecting code errors through binary stream and ANSI encoding parsing, it solves the problems of insufficient developer experience and time-consuming manual inspection in code development, and achieves efficient and accurate code detection and compilation, reducing software repair costs.

CN115809090BActive Publication Date: 2025-11-18CONTEMPORARY AMPEREX TECHNOLOGY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210337784.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2025-11-18
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

During code development, developers' lack of experience and non-standard coding practices have led to hidden errors escaping to the market. Existing manual inspection methods are time-consuming, labor-intensive, and have a high error rate.

Method used

It reads files in the configuration directory using binary streams, automatically detects code errors by parsing preset symbols and ANSI encoding, filters out potentially problematic files, and performs checks before compilation.

Benefits of technology

It improves the efficiency and accuracy of code inspection, prevents code errors, comment scope spread and garbled text issues from escaping, reduces software repair costs, and increases customer satisfaction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115809090B_ABST
    Figure CN115809090B_ABST
Patent Text Reader

Abstract

The application provides a code detection and program compiling method, device and equipment and a computer readable storage medium. The code detection method comprises: reading a file of a configuration directory using a binary stream; judging whether a preset symbol is included in first information read, if the preset symbol exists, judging that the file is a problem file, and outputting a file name of the problem file. In the technical scheme of the embodiment of the application, whether the preset symbol is included in the read binary data is judged to automatically check a historical remaining code error, and the code detection efficiency and accuracy are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of code development technology, and in particular to a code inspection and program compilation method, apparatus, device, and computer-readable storage medium. Background Technology

[0002] Currently, in the process of code development and program design, code developers and programmers suffer from insufficient development experience and non-standard coding practices. When these latent code errors escape into the market, they will have a serious impact.

[0003] In existing methods, code errors and non-standard code are usually checked manually, which is time-consuming, labor-intensive, and has a high error rate. Summary of the Invention

[0004] This application aims to address at least one of the technical problems existing in the prior art. To this end, one objective of this application is to provide a code inspection and program compilation method, apparatus, device, and computer-readable storage medium to improve the low efficiency of code error and non-standard code inspection.

[0005] An embodiment of the first aspect of this application provides a code detection method, including: reading files in a configuration directory using a binary stream; determining whether the first information read includes a preset symbol; if the preset symbol exists, determining that the file is a problematic file and outputting the filename of the problematic file.

[0006] In the technical solution of this application embodiment, binary streams are used to read files, and preset symbols are included in the read binary data to check for historical code errors. A large number of files in the configuration directory are automatically checked, and only files with potential problems are manually reviewed and screened, which can improve the efficiency and accuracy of code detection.

[0007] In some embodiments, the preset symbol may include "? / ". By checking that the read binary data includes "? / ", the problem of comment range expansion caused by transcoding can be identified.

[0008] In some embodiments, the code detection method further includes: if the first information does not include a preset symbol, then using ANSI encoding to parse the file; if the parsing fails, then determining the file as an abnormal file and outputting the filename of the abnormal file. By using ANSI encoding to parse the file, garbled text problems caused by inconsistencies in the character sets involved in encoding and decoding can be checked.

[0009] In some embodiments, the code detection method further includes: reading the abnormal file using a binary stream, and splitting the second information line by line using the newline delimiters in the read second information; and parsing the split second information line by line using ANSI encoding to locate and output the line containing the parsing error. Reading the abnormal file using a binary stream and splitting it line by line, then parsing the file line by line using ANSI encoding, can not only detect garbled files caused by inconsistencies in the character sets involved in encoding and decoding, but also locate the line containing the error, improving inspection efficiency.

[0010] An embodiment of the second aspect of this application provides a program compilation method, comprising: using the method of the above embodiment to detect files in a configuration directory; if problematic files and / or abnormal files exist, outputting the filenames of the problematic files and / or the filenames of the abnormal files and the lines of parsing the abnormal files; if no problematic files and parsing abnormal files exist, compiling the files in the configuration directory.

[0011] In the technical solution of this application embodiment, code detection is performed before compilation to prevent historical code errors, the spread of code comments, and garbled text problems caused by inconsistent encoding and decoding character sets from escaping, thereby reducing software repair costs and improving customer satisfaction.

[0012] An embodiment of the third aspect of this application provides a code detection device, comprising: a first unit for reading files in a configuration directory using a binary stream; and a second unit for determining whether the first information read includes a preset symbol; if the preset symbol exists, determining that the file is a problematic file and outputting the filename of the problematic file.

[0013] In some embodiments, the code detection device further includes: a third unit, configured to parse the file using ANSI encoding when the second unit determines that the first information does not contain a preset symbol, and if the parsing is abnormal, determine that the file is an abnormal file and output the filename of the abnormal file.

[0014] In some embodiments, the code detection device further includes: a fourth unit, configured to read the abnormal file using a binary stream and split the second information line by line using the newline delimiter in the read second information; and a fifth unit, configured to parse the split second information line by line using ANSI encoding, locate and output the line of parsing the abnormal information.

[0015] An embodiment of the fourth aspect of this application provides a program compilation apparatus, comprising: a detection unit, configured to detect files in a configuration directory using the detection method described above, and if problematic files and / or abnormal files exist, outputting the filenames of the problematic files and / or abnormal files and the lines parsing the abnormal files; and a compilation unit, configured to compile the files in the configuration directory when the detection unit detects that problematic files and abnormal files do not exist.

[0016] In some embodiments, the program compilation apparatus further includes a controller for controlling whether the program compilation apparatus invokes the detection unit. When the detection unit is not invoked, the compilation unit directly compiles the files in the configuration directory. The controller allows the project to temporarily disable the checks when the files are manually verified not to affect the code's functional execution logic, thereby improving compilation efficiency.

[0017] An embodiment of the fifth aspect of this application provides a code detection device, including: a memory, a processor, and a code detection program stored in the memory and executable on the processor. When the code detection program is executed by the processor, it implements the code detection method of the above embodiments.

[0018] An embodiment of the sixth aspect of this application provides a program compilation device, including: a memory, a processor, and a program compiler stored in the memory and executable on the processor. When the program compiler is executed by the processor, it implements the program compilation method of the above embodiments.

[0019] An embodiment of the seventh aspect of this application provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores a code detection program, which, when executed by a processor, implements the code detection method of the above embodiments.

[0020] An embodiment of the eighth aspect of this application provides a computer-readable storage medium, characterized in that a program compiler is stored on the computer-readable storage medium, and when the program compiler is executed by a processor, it implements the program compilation method of the above embodiments.

[0021] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description

[0022] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the various drawings denote the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings depict only some embodiments disclosed in this application and should not be construed as limiting the scope of this application.

[0023] Figure 1 Here are flowcharts of code detection methods according to some embodiments of this application;

[0024] Figure 2 Here are flowcharts of code detection methods according to some embodiments of this application;

[0025] Figure 3 This is a flowchart illustrating a program compilation method for some embodiments of this application.

[0026] Explanation of reference numerals in the attached figures:

[0027] Code detection method 1000; Code detection method 2000; Program compilation method 3000. Detailed Implementation

[0028] The embodiments of the technical solution of this application will now be described in detail with reference to the accompanying drawings. These embodiments are only used to more clearly illustrate the technical solution of this application and are therefore merely examples, and should not be used to limit the scope of protection of this application.

[0029] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.

[0030] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.

[0031] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0032] In the description of the embodiments in this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.

[0033] Currently, in the process of code development and program design, code developers and program designers suffer from insufficient development experience and non-standard code writing.

[0034] The applicant noted that hidden code errors would have a serious impact on the market, and that manually checking for code errors and non-standard code would be time-consuming, labor-intensive, and have a high error rate.

[0035] Based on the above considerations, in order to improve the problem of insufficient detection of hidden code errors, the applicant has designed a code detection method. This method reads files in the configuration directory using binary streams and determines whether a file is a potential problem file based on whether the read binary data contains preset symbols, thus enabling automatic screening of potential problem files.

[0036] The above methods can improve code detection efficiency and accuracy by automatically filtering a large number of files in the configuration directory and only manually reviewing files with potential problems.

[0037] For ease of explanation, the following embodiments use a code detection method 1000 according to an embodiment of this application as an example.

[0038] Figure 1 This is a flowchart of a code detection method 1000 according to some embodiments of this application. Please refer to... Figure 1 Some embodiments of this application provide a code detection method 1000, including: reading files in a configuration directory using a binary stream; determining whether the first information read includes a preset symbol; if the preset symbol exists, determining that the file is a problematic file and outputting the filename of the problematic file.

[0039] The configuration directory can be a directory excluding static code that is unlikely to cause problems in the project. The first piece of information is the binary data obtained by reading the file using a binary stream. The default symbols can be any garbled characters, "?", " / ", or combinations thereof. The problem file is the file that includes the aforementioned default symbols after being read using a binary stream.

[0040] It's understandable that excluding static code during the review process reduces code review time. Using binary streams instead of other encodings to read files avoids parsing errors caused by specific encodings. Using binary streams to read files and predefined symbols as filtering criteria allows for the programmatic detection of legacy code errors, improving review efficiency.

[0041] According to some embodiments of this application, the preset symbol may include "? / ".

[0042] The symbol "? / " can be an error end identifier indicating a coding conversion error. For example, when there is a Chinese comment line " / *热* / " (the number of characters in the Chinese comment is odd) in the code, and the code is transcoded from UTF-8 encoding to GBK encoding, for example, since the UTF-8 encoding of " / *热* / " is "00101111001010101110011110000011101011010010101000101111", so "00101111" is parsed as " / ", "00101010" is parsed as "*", "1110011110000011" is parsed as a special Chinese character, "1010110100101010" cannot be parsed and is automatically converted to "?", and "00101111" is parsed as " / ". When the file is saved back to UTF-8 encoding, the original comment will become " / *?? / ", which may further cause the function code block after the comment to be mistakenly changed to a comment.

[0043] Therefore, it can be understood that by checking whether the code for reading the binary stream contains "? / ", it is possible to detect functional logic errors caused by the spread of comment ranges due to historical transcoding.

[0044] Specifically, for example, in an example, there is the following code

[0045]

[0046] Its normal output value should be "a = 10, b = 20". However, when there is a parsing error due to transcoding, it will cause the comment range of " / *导入热失控* / " to spread, making the functional code block behind it be mistakenly changed to a comment segment, resulting in a functional logic error. At this time, the output result of the code is "a = 0, b = 0".

[0047] Please continue to refer to Figure 1 , according to some embodiments of the present application, the code detection method 1000 further includes: if the first information does not include a preset symbol, then parse the file using ANSI encoding. If the parsing is abnormal, then determine that the file is an abnormal file and output the file name of the abnormal file.

[0048] Among them, the ANSI encoding can be the same ANSI encoding as that used by the compiler. An abnormal file is a file with an abnormal parsing using ANSI encoding.

[0049] It can be understood that parsing the file using ANSI encoding can check for garbled characters caused by inconsistent character sets involved in encoding and decoding, and can detect code comment range spread caused by garbled characters and code functional execution logic errors caused by the spread of the comment range.

[0050] Please continue to refer to this. Figure 1 According to some embodiments of this application, the code detection method 1000 further includes: reading the abnormal file using a binary stream, and splitting the second information into lines by the newline delimiter in the read second information; and parsing the split second information line by line using ANSI encoding, locating and outputting the lines of the parsed abnormal information.

[0051] The second piece of information is the binary data obtained by reading the exception file using a binary stream. The newline separator is the newline character found in the second piece of information. ANSI encoding can be the same as the ANSI encoding used by the compiler.

[0052] It is understandable that by reading and splitting the abnormal file line by line using binary streams and parsing it line by line using ANSI encoding, not only can files with parsing errors be filtered out, but the lines of code that caused the parsing errors can also be located.

[0053] Figure 2 This is a flowchart of a code detection method 2000 according to some embodiments of this application. Please refer to... Figure 2 In a specific embodiment, for a Simplified Chinese Windows operating system environment where the compiler uses GBK encoding and the configuration directory files are saved in UTF-8 encoding, the configuration directory files can first be read using a binary stream. If the read binary data includes the symbol "? / ", the filename of the problematic file is output for manual review. If it does not include the symbol "? / ", the configuration directory files are parsed using GBK encoding. If the parsing is normal, the check operation ends. If the parsing is abnormal, the abnormal file is read again using a binary stream, and the binary data is split line by line using the newline characters in the read binary data. The split binary data is then parsed line by line using GBK encoding to find all lines where parsing errors occur, and the filename of the abnormal file and the line of code that caused the parsing error are output.

[0054] Using the above methods, we can automatically detect the problem of comment range expansion caused by encoding when the number of Chinese comments in the code is odd. In addition to filtering out problematic files, we can also locate the line of code where the problem is located, thus improving the efficiency of code detection.

[0055] Figure 3 This is a flowchart illustrating the program compilation method for some embodiments of this application. Please refer to... Figure 3Some embodiments of this application provide a program compilation method 3000, including: using the code detection method of the above embodiments to detect files in a configuration directory; if problematic files and / or abnormal files exist, outputting the filenames of the problematic files and / or the filenames of the abnormal files and the lines of parsing the abnormal files; if no problematic files and parsing abnormal files exist, compiling the files in the configuration directory.

[0056] The code detection operation using the above embodiment can be configured to be "enabled" or "disabled" according to the actual needs of the project to improve compilation efficiency.

[0057] Understandably, performing code checks before compilation can prevent legacy code errors, the spread of code comments, and garbled text issues caused by inconsistent encoding and decoding character sets from escaping, thereby reducing software repair costs and improving customer satisfaction.

[0058] Some embodiments of this application provide a code detection device, including: a first unit for reading files in a configuration directory using a binary stream; and a second unit for determining whether the first information read includes a preset symbol, and if the preset symbol exists, determining that the file is a problematic file and outputting the filename of the problematic file.

[0059] According to some embodiments of this application, the code detection device further includes: a third unit, configured to parse the file using the ANSI character set when the second unit determines that the first information does not contain a preset symbol, and if the parsing is abnormal, determine that the file is an abnormal file and output the filename of the abnormal file.

[0060] According to some embodiments of this application, the code detection device further includes: a fourth unit, used to read the abnormal file using a binary stream and split the second information line by line using the newline delimiter in the read second information; and a fifth unit, used to parse the split second information line by line using an ANSI character set, locate and output the line of parsing the abnormal information.

[0061] Some embodiments of this application provide a program compilation apparatus, including: a detection unit, configured to detect files in a configuration directory using the method described above, and if problematic files and / or abnormal files exist, outputting the filenames of the problematic files and / or abnormal files and the lines that parse the abnormal files; and a compilation unit, configured to compile the files in the configuration directory when the detection unit detects that problematic files and abnormal files do not exist.

[0062] According to some embodiments of this application, the program compilation device further includes: a controller, used to control whether the program compilation device calls the detection unit, and when the detection unit is not called, the compilation unit directly compiles the files in the configuration directory.

[0063] The detection unit can be set to be enabled by default, that is, the program compilation device calls the detection unit by default before compiling the file.

[0064] The controller can configure the detection unit to be "enabled" or "disabled" according to the actual needs of the project to improve compilation efficiency.

[0065] Some embodiments of this application provide a code detection device, including: a memory, a processor, and a code detection program stored in the memory and executable on the processor. When the code detection program is executed by the processor, it implements the code detection method of the above embodiments.

[0066] Some embodiments of this application provide a program compilation device, including: a memory, a processor, and a program compiler stored in the memory and executable on the processor. When the program compiler is executed by the processor, it implements the program compilation method of the above embodiments.

[0067] Some embodiments of this application provide a computer-readable storage medium storing a code detection program, which, when executed by a processor, implements the code detection method of the above embodiments.

[0068] Some embodiments of this application provide a computer-readable storage medium storing a program compiler, which, when executed by a processor, implements the program compilation method of the above embodiments.

[0069] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and not to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application, and they should all be covered within the scope of the claims and specification of this application. In particular, as long as there is no structural conflict, the various technical features mentioned in the embodiments can be combined in any way. This application is not limited to the specific embodiments disclosed herein, but includes all technical solutions falling within the scope of the claims.

Claims

1. A code detection method characterized by, The method comprises: reading the files in the configuration directory using a binary stream; the configuration directory is a directory excluding static code in the project that will not cause problems; determining whether the first information read includes a preset symbol, if the preset symbol exists, determining that the file is a problem file, and outputting the file name of the problem file; the first information is binary data obtained by reading the files in the configuration directory using a binary stream, and the preset symbol is an error end identifier of an encoding conversion error; wherein the problem file is a file in which a Chinese comment line in code is incorrectly parsed during a process of converting the code from a first type of encoding to a second type of encoding and then back to the first type of encoding, a placeholder for an unparsed character sequence is inserted before the last character in a comment end symbol in the Chinese character comment of an odd number of bytes in the Chinese comment line, the preset symbol at the end of the comment causes subsequent functional code that should be outside the comment range to be incorrectly included in the comment, and a functional logic error occurs; if the first information does not include the preset symbol, the file is parsed using ANSI encoding, if an exception occurs during parsing, the file is determined to be an abnormal file, and the file name of the abnormal file is output; reading the abnormal file using a binary stream, and dividing the second information read into lines by a line feed delimiter in the second information; and parsing the divided second information line by line using the ANSI encoding, locating and outputting the line with the parsing exception.

2. The code detection method of claim 1, wherein, The preset symbol includes "? / ".

3. A program compiling method characterized by comprising: The method comprises: detecting the files in the configuration directory using the method of any one of claims 1-2, if the problem file and / or the abnormal file exist, outputting the file name of the problem file and / or the file name of the abnormal file and the line with the parsing exception, and if the problem file and the line with the parsing exception do not exist, compiling the files in the configuration directory.

4. A code detection apparatus characterized by comprising: The method comprises: a first unit for reading the files in the configuration directory using a binary stream; the configuration directory is a directory excluding static code in the project that will not cause problems; and a second unit for determining whether the first information read includes a preset symbol, if the preset symbol exists, determining that the file is a problem file, and outputting the file name of the problem file; the first information is binary data obtained by reading the files in the configuration directory using a binary stream, and the problem file is a file in which a Chinese comment line in code is incorrectly parsed during a process of converting the code from a first type of encoding to a second type of encoding and then back to the first type of encoding, a placeholder for an unparsed character sequence is inserted before the last character in a comment end symbol in the Chinese character comment of an odd number of bytes in the Chinese comment line, the preset symbol at the end of the comment causes subsequent functional code that should be outside the comment range to be incorrectly included in the comment, and a functional logic error occurs. The third unit is configured to parse the file using ANSI encoding when it is determined by the second unit that the preset symbol is not included in the first information, and determine the file as an abnormal file and output the file name of the abnormal file if the parsing is abnormal. The fourth unit is configured to read the abnormal file using a binary stream and split the second information by line according to a line feed delimiter in the read second information. The fifth unit is configured to parse the split second information by line using the ANSI encoding, locate and output the line with the parsing abnormality. The device comprises a memory, a processor, and a code detection program stored on the memory and executable on the processor, and the code detection program is executed by the processor to implement the code detection method according to any one of claims 1-2.

5. A program compiling apparatus characterized by comprising: The device comprises a memory, a processor, and a program compilation program stored on the memory and executable on the processor, and the program compilation program is executed by the processor to implement the program compilation method according to claim 3. The computer readable storage medium stores a code detection program, and the code detection program is executed by the processor to implement the code detection method according to any one of claims 1-2. The computer readable storage medium stores a program compilation program, and the program compilation program is executed by the processor to implement the program compilation method according to claim 3. ​ 6. The program compiling apparatus according to claim 5, wherein ​ ​ ​ 7. A code detection device, characterized by ​ 8. A program compiling apparatus characterized by comprising: ​ 9. A computer-readable storage medium, characterized in that, ​ 10. A computer-readable storage medium, characterized in that, ​

Citation Information

Patent Citations

  • Checking method and equipment for source code format

    CN109471634A

  • Character verification method and device, equipment and storage medium

    CN113705167A

  • Code annotation detection method and device

    CN113867783A