Method and device for checking null pointer in code, electronic equipment and storage medium

By identifying unit functions and traversing the code segments, and using preset null null rules to determine null pointers, the problem of not being able to identify null pointers in the existing technology is solved, ensuring that the pointer correctly nulls when dereferences, reducing the risk of software crashes.

CN120428979APending Publication Date: 2025-08-05TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410163711.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-02-05
Publication Date
2025-08-05

AI Technical Summary

Technical Problem

The prior art cannot accurately identify all null pointer access, resulting in the risk of software crash and cannot give effective warnings and prompts.

Method used

By identifying unit functions of the preset code segment, traversal and analyze the statements to be judged, including assignment statements, three types of expression statements and conditional statements, use the preset null rule to judge the null pointer, and determine the comprehensive result of the null pointer.

Benefits of technology

Significantly reduce the empty-number process, ensure that the pointer has been correctly judged and empty-numbered when dereferenced, and reduce the risk of software crash.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120428979A_ABST
    Figure CN120428979A_ABST
Patent Text Reader

Abstract

The invention discloses a null pointer checking method and device in a code, electronic equipment and a storage medium, and the method comprises the steps: carrying out the unit function recognition of a preset code segment, obtaining at least one to-be-traversed function, carrying out the traversal analysis of a current function in the at least one to-be-traversed function, and obtaining a null pointer of the current function; at least one to-be-judged statement is obtained from the current function, the to-be-judged statement comprises an assignment statement, three types of expression statements and / or conditional statements, null pointer judgment is conducted on each to-be-judged statement according to a preset null judgment rule, and a null pointer judgment result corresponding to each to-be-judged statement is obtained, and determining a null pointer comprehensive result corresponding to the current function according to the null pointer judgment result corresponding to each to-be-judged statement and the position of each to-be-judged statement in the current function. According to the embodiment of the invention, the process of null judgment can be greatly reduced and optimized, and whether null judgment processing is correctly performed or not when the pointer is de-referenced is confirmed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for checking a null pointer in a code. Background Art

[0002] Directly using a property or function of a null pointer variable in a software program can cause a software crash. A null pointer is a type of pointer. A pointer is a variable whose value is a memory address. A null pointer is a pointer variable whose memory address is NULL. To prevent software crashes, null protection is often used.

[0003] Currently, the CPPcheck tool is used for null protection. Its logic is as follows: when encountering a line of code where a function returns a pointer variable, it determines whether that line of code has a null protection. If not, a null pointer crash code alert is generated for that line of code. However, existing solutions cannot accurately identify all null pointer accesses. This is prone to the following issues: Some code that accesses null pointers and causes exceptions fails to provide prompts or warnings, which can lead to runtime exceptions or system crashes. Summary of the Invention

[0004] To solve the problems of the prior art, the present invention provides a method, device, electronic device, and storage medium for checking for null pointers in code. The technical solution is as follows:

[0005] In one aspect, a method for checking a null pointer in code is provided, the method comprising:

[0006] Performing unit function identification on a preset code segment to obtain at least one function to be traversed;

[0007] Performing traversal analysis on a current function in at least one to-be-traversed function, and obtaining at least one to-be-judged statement from the current function; wherein the to-be-judged statement in the at least one to-be-judged statement is associated with a preset pointer; the to-be-judged statement includes an assignment statement, three types of expression statements, and / or a conditional statement;

[0008] Perform null pointer judgment on each statement to be judged according to the preset null judgment rule, and obtain the null pointer judgment result corresponding to each statement to be judged;

[0009] The null pointer comprehensive result corresponding to the current function is determined according to the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function.

[0010] On the other hand, a device for checking a null pointer in a code is provided, the device comprising:

[0011] A code recognition module is used to perform unit function recognition on a preset code segment to obtain at least one function to be traversed;

[0012] A function traversal module is configured to perform traversal analysis on a current function in at least one to-be-traversed function, and obtain at least one to-be-judged statement from the current function; wherein the to-be-judged statement in the at least one to-be-judged statement is associated with a preset pointer; the to-be-judged statement includes an assignment statement, three types of expression statements, and / or a conditional statement;

[0013] The statement null judgment module is used to perform null pointer judgment on each statement to be judged according to the preset null judgment rules, and obtain the null pointer judgment result corresponding to each statement to be judged;

[0014] The function null judgment module is used to determine the null pointer comprehensive result corresponding to the current function based on the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function.

[0015] In some possible embodiments, when the statement to be judged is an assignment statement, the preset empty judgment rule includes a first empty judgment statement;

[0016] Statement empty detection module, used for:

[0017] If the assignment statement is on the execution path of the preset pointer dereference, determining the null status of the value on the right side of the assignment operator in the assignment statement based on the first null judgment statement;

[0018] If the null judgment state of the value on the right indicates that the value on the right has been null pointer judged, the null judgment state of the variable on the left side of the assignment operator is marked as having been null pointer judged, and the null pointer judgment result of the value on the right is determined as the null pointer judgment result of the variable on the left; the variable on the left is related to the preset pointer.

[0019] In some possible embodiments, the statement empty detection module is used to:

[0020] If the result of the assignment statement on the execution path of the preset pointer dereference is unknown, and the variable on the left side is not equal to the preset pointer, determine the null state of the value on the right side;

[0021] If the null judgment state of the value on the right indicates that the value on the right has been null pointer judged, the null judgment state of the variable on the left is marked as having been null pointer judged, and the null pointer judgment result of the value on the right is determined as the null pointer judgment result of the variable on the left.

[0022] In some possible embodiments, the statement empty detection module is used to:

[0023] If the result of whether the assignment statement is on the execution path of the preset pointer dereference is unknown, and the variable on the left side is equal to the preset pointer, determine the null state of the variable on the left side;

[0024] If the null status of the variable on the left indicates that the variable on the left has been null-pointer checked, determine the null status of the value on the right;

[0025] If the null judgment state of the value on the right indicates that the value on the right has been null pointer judged, the null judgment state of the variable on the left side of the update mark is updated to indicate that a null pointer judgment has been performed, and the null pointer judgment result of the value on the right is determined as the null pointer judgment result of the preset pointer.

[0026] In some possible embodiments, the statement empty detection module is used to:

[0027] If the null judgment state of the value on the right indicates that the value on the right has not yet been null-pointer-judged, the null judgment state of the variable on the left is marked as not having been null-pointer-judged, and the variable on the left is associated with the value on the right.

[0028] In some possible embodiments, when the statement to be judged is a third-category expression statement, the preset empty judgment rule includes a second empty judgment statement;

[0029] Statement empty detection module, used for:

[0030] Determine the preset pointer dereference and the position of the preset pointer dereference according to the second null judgment statement;

[0031] If the parent node of the preset pointer dereference is an AND or OR expression statement, and the preset pointer dereference is located on the right side of an operator in the AND or OR expression statement, determining the null state of the preset pointer located on the left side of the operator in the AND or expression statement; the AND or expression statement includes an AND expression statement or an OR expression statement;

[0032] If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and the null pointer judgment result of the preset pointer is non-null, it is determined that the null pointer judgment result of the AND or expression statement is non-null.

[0033] In some possible embodiments, the statement empty detection module is used to:

[0034] Determine the preset pointer dereference and the position of the preset pointer dereference according to the second null judgment statement;

[0035] If the parent node of the preset pointer dereference is a ternary expression statement, determine the position of the preset pointer dereference in the ternary expression statement;

[0036] If the preset pointer dereferences the correct expression in the ternary expression statement, determining the null state of the preset pointer in the conditional expression in the ternary expression statement; if the null state of the preset pointer indicates that the preset pointer has been null-pointer-checked, and the null-pointer-check result of the preset pointer is non-null, determining that the null-pointer-check result of the ternary expression statement is non-null;

[0037] or;

[0038] If the preset pointer dereferences an erroneous expression in a ternary expression statement, determine the null judgment state of the preset pointer in the conditional expression in the ternary expression statement; when the null judgment state of the preset pointer indicates that the preset pointer has been null pointer judged, and the null pointer judgment result of the preset pointer is null, determine that the null pointer judgment result of the ternary expression statement is non-null.

[0039] In some possible embodiments, when the statement to be judged is a conditional statement, the preset empty judgment rule includes a third empty judgment statement;

[0040] Statement empty detection module, used for:

[0041] Get the conditional expression of the conditional statement;

[0042] If the conditional expression is a basic expression, the basic expression is a preset pointer, the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and the judgment position of the preset pointer dereference is determined;

[0043] The null pointer judgment result of the conditional statement is determined according to the null judgment state of the preset pointer and the judgment position of the preset pointer dereference.

[0044] In some possible embodiments, the statement empty detection module is used to:

[0045] Get the conditional expression of the conditional statement;

[0046] The conditional expression is disassembled to obtain multiple basic expressions; the multiple basic expressions include preset pointers;

[0047] Determine the null state of the preset pointer based on the null state of the conditional expression;

[0048] If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, determining a judgment position for dereferencing the preset pointer;

[0049] The null pointer judgment result of the conditional statement is determined according to the null judgment state of the preset pointer and the judgment position of the preset pointer dereference.

[0050] In some possible embodiments, the statement empty detection module is used to:

[0051] If the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is non-null, the null pointer judgment result of the conditional statement is determined to be non-null;

[0052] Or; if the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is null, it is determined that the null pointer judgment result of the conditional statement is null.

[0053] In some possible embodiments, the statement empty detection module is used to:

[0054] If the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is non-null, the null pointer judgment result of the conditional statement is determined to be null;

[0055] Or; if the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is null, it is determined that the null pointer judgment result of the conditional statement is non-null.

[0056] In some possible embodiments, the statement empty detection module is used to:

[0057] If the preset pointer is null-pointer checked before the preset pointer is dereferenced, the null-pointer check state of the preset pointer is that the null-pointer check has been performed, and the null-pointer check result of the preset pointer is non-null.

[0058] On the other hand, an electronic device is provided, including a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the above-mentioned null pointer checking method in the code.

[0059] On the other hand, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored. The at least one instruction or at least one program is loaded and executed by a processor to implement the null pointer checking method in the above code.

[0060] In another aspect, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the null pointer check method in the above code.

[0061] The embodiment of the present invention obtains at least one function to be traversed by performing unit function identification on a preset code segment, performs traversal analysis on the current function in the at least one function to be traversed, obtains at least one statement to be judged from the current function, wherein the statement to be judged in the at least one statement to be judged is associated with a preset pointer, and the statement to be judged includes an assignment statement, three types of expression statements and / or a conditional statement, performs a null pointer judgment on each statement to be judged according to a preset null judgment rule, obtains a null pointer judgment result corresponding to each statement to be judged, and determines a null pointer comprehensive result corresponding to the current function according to the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function. The embodiment of the present application can greatly reduce and optimize the null judgment process by analyzing the assignment statements, three types of expression statements, conditional statements, processing judgment positions and other details of the code, and confirm whether the pointer has been correctly judged to be null when dereferencing. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0063] Figure 1 is a schematic diagram of an implementation environment provided by an embodiment of the present invention;

[0064] Figure 2 1 is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention;

[0065] Figure 3 1 is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention;

[0066] Figure 4 1 is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention;

[0067] Figure 5 1 is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention;

[0068] Figure 6 1 is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention;

[0069] Figure 7 This is a structural block diagram of a device for checking a null pointer in a code provided by an embodiment of the present invention;

[0070] Figure 8This is a hardware structure block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0071] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0072] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way are interchangeable where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0073] It is understandable that in the specific implementation of this application, related data such as user information is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0074] In order to facilitate understanding of the above-mentioned technical solutions and the technical effects produced by the embodiments of the present disclosure, a brief introduction is given to the terms involved in the embodiments of the present disclosure:

[0075] Artificial Intelligence (AI) refers to the theories, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that seeks to understand the essence of intelligence and produce new intelligent machines that can respond in a manner similar to human intelligence. AI also involves studying the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.

[0076] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, and machine learning / deep learning.

[0077] Computer vision (CV) is the science of making machines "see." Specifically, it refers to machine vision, where cameras and computers replace the human eye in identifying and measuring objects, performing further image processing to create images more suitable for human observation or transmission to instruments. As a scientific discipline, computer vision studies related theories and technologies, attempting to build artificial intelligence systems capable of extracting information from images or multidimensional data. Computer vision technologies typically include image processing, image recognition, image semantic understanding, image retrieval, optical character recognition (OCR), video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous localization and mapping, and common biometric recognition technologies such as facial recognition and fingerprint recognition.

[0078] Natural language processing (NLP) is a key area of research in computer science and artificial intelligence. It studies the theories and methods that enable effective communication between humans and computers using natural language. Natural language processing (NLP) integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language we use in everyday life—and is closely linked to the study of linguistics. Natural language processing technologies typically include text processing, semantic understanding, machine translation, robotic question answering, and knowledge graphs.

[0079] Machine learning (ML) is a multidisciplinary field that encompasses probability theory, statistics, approximation theory, convex analysis, and algorithmic complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is at the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications span all areas of AI. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.

[0080] Autonomous driving technology usually includes high-precision maps, environmental perception, behavioral decision-making, path planning, motion control and other technologies. Autonomous driving technology has broad application prospects.

[0081] With the research and advancement of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, autonomous driving, drones, robots, smart medical care, smart customer service, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.

[0082] The embodiments of the present invention can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.

[0083] Cloud technology refers to a hosting technology that unifies hardware, software, and network resources within a wide area network (WAN) or local area network (LAN) to enable data computing, storage, processing, and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, and application technology based on the cloud computing business model. It can form a resource pool that can be used on demand with flexibility and convenience. Cloud computing technology will become a crucial support. Backend services for technical network systems, such as video websites, image websites, and more portals, require extensive computing and storage resources. With the rapid development and application of the internet industry, every item will likely have its own unique identification mark and will need to be transmitted to backend systems for logical processing. Data of varying levels will be processed separately, and data from all industries will require a strong system backend, which can only be achieved through cloud computing.

[0084] Cloud storage is a new concept that has evolved from the concept of cloud computing. A distributed cloud storage system (hereafter referred to as a storage system) is a storage system that uses cluster applications, grid technology, and distributed storage file systems to bring together a large number of different types of storage devices (also known as storage nodes) on a network through application software or application interfaces to work together and provide data storage and service access. Currently, storage systems create logical volumes. When creating a logical volume, physical storage space is allocated for each logical volume. This physical storage space may consist of disks on a single storage device or several storage devices. When a client stores data on a logical volume, it stores the data on a file system. The file system divides the data into multiple parts, each of which is an object. An object contains not only the data but also additional information such as the data identifier (ID). The file system writes each object to the physical storage space of the logical volume and records the storage location of each object. When a client requests data access, the file system can provide access based on the storage location information of each object. The storage system allocates physical storage space to logical volumes by pre-dividing the physical storage space into stripes based on the estimated capacity of the objects to be stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the Redundant Array of Independent Disks (RAID) groupings. A logical volume can be understood as a stripe, thereby allocating physical storage space to the logical volume.

[0085] A database, in short, can be thought of as a digital filing cabinet—a place where electronic files are stored, allowing users to add, query, update, and delete data. A database is a collection of data stored in a specific way, shared by multiple users, with minimal redundancy, and independent of applications.

[0086] Blockchain is a new application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a series of data blocks linked using cryptographic methods. Each block contains information about a batch of online transactions, used to verify the validity of this information (to prevent counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product and service layer, and the application service layer.

[0087] The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operational testing. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the corresponding relationship between the user's real identity and the blockchain address (authority management), etc., and under authorization, it supervises and audits the transactions of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and records valid requests to storage after consensus is reached. For a new business request, the basic service first adapts the interface for parsing and authentication (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management). The smart contract module is responsible for the registration, issuance, triggering and execution of contracts. Developers can define the contract logic in a programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the contract logic is triggered by calling keys or other events to trigger execution. The contract logic is completed, and the contract upgrade and cancellation functions are also provided. The operation detection module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarms, network status detection, node device health status detection, etc.

[0088] The platform's product service layer provides the basic capabilities and implementation framework for typical applications. Developers can build on these basic capabilities, overlay business features, and complete the blockchain implementation of business logic. The application service layer provides application services based on blockchain solutions for business participants to use.

[0089] See also Figure 1 , which is a schematic diagram of an implementation environment provided by an embodiment of the present invention. The implementation environment may include a client 110, a server 120 and a database 130.

[0090] The client 110 and the server 120 , as well as the server 120 and the database 130 , may be connected and communicated via a network.

[0091] The client 110 includes, but is not limited to, mobile phones, computers, intelligent voice interaction devices, smart home appliances, in-vehicle clients, aircraft, and the like. An application with human-computer interaction functionality can be run on the client 110, and the application can launch virtual item distribution activities for different business scenarios, such as flash sales, raffles, and reward activities for completing tasks. The client 110 can perform unit function recognition on a preset code segment to obtain at least one function to be traversed, perform traversal analysis on the current function in the at least one function to be traversed, and obtain at least one statement to be judged from the current function, wherein the statement to be judged in the at least one statement to be judged is associated with a preset pointer, and the statement to be judged includes an assignment statement, three types of expression statements, and / or a conditional statement. A null pointer judgment is performed on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged, and a comprehensive null pointer result corresponding to the current function is determined based on the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function. The embodiment of the present application can significantly reduce and optimize the process of null judgment by analyzing the assignment statements, three types of expression statements, conditional statements, processing judgment locations and other details of the code, and confirm whether the null judgment has been correctly performed when the pointer is dereferenced.

[0092] The server 120 can identify the unit function of the preset code segment to obtain at least one function to be traversed, perform traversal analysis on the current function in the at least one function to be traversed, and obtain at least one statement to be judged from the current function, wherein the statement to be judged in the at least one statement to be judged is associated with a preset pointer, and the statement to be judged includes an assignment statement, three types of expression statements and / or a conditional statement. According to the preset null judgment rule, a null pointer judgment is performed on each statement to be judged to obtain a null pointer judgment result corresponding to each statement to be judged, and a null pointer judgment result corresponding to each statement to be judged is determined according to the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function. The embodiment of the present application can greatly reduce and optimize the null judgment process by analyzing the assignment statements, three types of expression statements, conditional statements, processing judgment positions and other details of the code, and confirm whether the pointer has been correctly judged to be null when dereferencing.

[0093] The database 130 may include an in-memory database and a relational database. It should be noted that the servers, databases, nodes, etc. of the embodiments of the present invention may be independent physical servers, or they may be server clusters or distributed systems composed of multiple physical servers. They may also be cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0094] In one exemplary embodiment, client 110, server 120, and database 130 may all be node devices in a blockchain system, capable of sharing acquired and generated information with other node devices in the blockchain system, thereby enabling information sharing among multiple node devices. Multiple node devices in a blockchain system may be configured with the same blockchain, which is composed of multiple blocks, with adjacent blocks having an associated relationship. This allows any tampering of data in any block to be detected by the next block, thereby preventing tampering of data in the blockchain and ensuring the security and reliability of the data in the blockchain.

[0095] See also Figure 2 , which is a flow chart of a method for checking a null pointer in a code provided by an embodiment of the present invention, which can be applied to Figure 1 In the implementation environment shown, the execution subject of this method can be Figure 1 The server that performs the null pointer check can also be determined in the client or other server node that performs the null pointer check. It should be noted that this specification provides method operation steps as described in the embodiments or flow charts, but more or fewer operation steps may be included based on conventional or non-creative labor. The order of steps listed in the embodiments is only one way of executing the steps among many steps, and does not represent the only execution order. When the actual system or product is executed, it can be executed sequentially or in parallel according to the method shown in the embodiments or the drawings (for example, in a parallel processor or multi-threaded processing environment). Specifically, Figure 2 As shown, the method may include:

[0096] S201: Perform unit function identification on a preset code segment to obtain at least one function to be traversed.

[0097] In the embodiment of the present application, the preset code end can be a source code or a compiled code, and the preset code segment can be a code written in various languages, such as C, C++, Java, etc.

[0098] Optionally, null pointer checking for pre-defined code can be implemented through static code checking. Static code checking is an analysis and check performed without executing the pre-defined code. It uses static analysis of the code and program structure to identify problems or defects in the code.

[0099] In the embodiments of the present application, a function is one of the most basic units of code organization, which can modularize the functionality of a section of code while also being highly reusable and scalable. Optionally, a unit function identification can be performed on a preset code segment to obtain one or more functions to be traversed. Subsequently, a null pointer check is performed on each of the one or more functions to be traversed to obtain a final null pointer synthesis result.

[0100] Pointers need to be checked for null before use. In the embodiments of the present application, checking for null refers to performing a non-null check on a pointer to confirm that its value is not null or empty. If a pointer is checked for null, then it cannot be null within the scope of the pointer, and it may be null outside the scope of the pointer.

[0101] Pointer dereference is the variable it points to. The dereference operator is *. For example, for a pointer variable p, the dereference is *p, which is the variable pointed to by p. The function of * is to reference the variable value pointed to by the pointer.

[0102] S203, traverse and analyze the current function in at least one to-be-traversed function, and obtain at least one to-be-judged statement from the current function; wherein, the to-be-judged statement in at least one to-be-judged statement is associated with a preset pointer; the to-be-judged statement includes an assignment statement, three types of expression statements and / or a conditional statement.

[0103] In an embodiment of the present application, a traversal analysis can be performed on each of the at least one to-be-traversed functions, and at least one statement to be judged can be obtained from each to-be-traversed function. In order to clearly explain the embodiment of the present application, the processing process of any one of the at least one to-be-traversed functions can be explained. Here, one of the to-be-traversed functions is treated as the current function and explained in detail. The processing process of the other to-be-traversed functions can refer to the processing process of the current function, and will not be repeated here.

[0104] Optionally, the current function can be traversed and analyzed to obtain at least one statement to be judged from the current function. According to the actual situation of the statements contained in the current function, at least one statement among assignment statements, three types of expression statements, and conditional statements can be split. In other words, some current functions can be split into assignment statements; some current functions can be split into three types of expression statements; some current functions can be split into conditional statements; some current functions can be split into assignment statements and three types of expression statements; some current functions can be split into assignment statements and conditional statements; some current functions can be split into three types of expression statements and conditional statements; some current functions can be split into assignment statements, three types of expression statements, and conditional statements.

[0105] Optionally, after the current function is split, at least one of the assignment statements, three-type expression statements, and conditional statements obtained may include multiple statements of the same type. For example, some current functions can be split into 2 assignment statements, and some current functions can be split into 2 assignment statements, 3 three-type expression statements, and 1 conditional statement, etc.

[0106] In the embodiment of the present application, after splitting the current function, not only can at least one statement to be judged be obtained after the split, but also the position of each statement to be judged in the current function can be obtained. For example, the first assignment statement is positioned first in the current function, and the first conditional statement is positioned second in the current function, after the first assignment statement.

[0107] In some possible embodiments, each of the at least one statement to be determined is associated with a preset pointer. In another optional embodiment, some of the at least one statement to be determined are associated with a preset pointer.

[0108] S205 , performing a null pointer judgment on each statement to be judged according to a preset null judgment rule, and obtaining a null pointer judgment result corresponding to each statement to be judged.

[0109] In the embodiments of the present application, there are three types of statements to be judged: assignment statements, three types of expression statements, and conditional statements. Therefore, the preset null judgment rules may include three types of null judgment statements. Optionally, they may include a first null judgment statement corresponding to the assignment statement, a second null judgment statement corresponding to the three types of expression statements, and a third null judgment statement corresponding to the conditional statement.

[0110] The following describes how to perform a null pointer check on each statement to be judged and obtain a null pointer check result corresponding to each statement to be judged, respectively, under different circumstances.

[0111] See also Figure 3 , which is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention, applicable to assignment statements, including:

[0112] S301: Determine the path relationship between the assignment statement and the preset pointer dereference. If the assignment statement is on the execution path of the preset pointer dereference, execute step S302; otherwise, go to step S306.

[0113] In an optional embodiment, the first position of the preset pointer dereference in the current function is first determined, and the second position of the assignment statement in the current function is determined. If it is determined based on the first position and the second position that the assignment statement (A=B) must be executed before executing the preset pointer dereference (*A=1), it can be determined that the assignment statement is on the execution path of the preset pointer dereference.

[0114] Example: Empty fragment statement 1:

[0115]

[0116] The following is an explanation based on the first statement of the null judgment fragment: pointer B is not null, enter the if statement, and assign a value. Since pointer B is not null, the assigned pointer A is also not null, and pointer A is dereferenced, and it is definitely not null.

[0117] S302: Determine the null status of the value on the right side of the assignment operator in the assignment statement based on the first null judgment statement.

[0118] In the embodiments of the present application, each program design has its own assignment statement, so the assigned value can be a constant, such as a number, a variable, such as a pointer, or an expression containing other pointers, etc.

[0119] The following example uses the value (pointer B) on the right side of the assignment operator in an assignment statement as a pointer. If the assignment statement is on the execution path of the preset pointer dereference, the null status of the value (pointer B) on the right side of the assignment operator in the assignment statement can be determined based on the first null judgment statement.

[0120] S303: If the null judgment state of the value on the right side indicates that the value on the right side has been subjected to a null pointer judgment, execute step S304; otherwise, go to step S305.

[0121] S304: Mark the null status of the variable on the left side of the assignment operator as having undergone null pointer judgment, and determine the null pointer judgment result of the value on the right side as the null pointer judgment result of the variable on the left side, and end the process.

[0122] Optionally, if the null judgment status of the value on the right side of the assignment operator in the assignment statement indicates that the null pointer judgment has been performed on the value on the right side (pointer B), the null pointer judgment result of the value on the right side (pointer B) can be reset to the null pointer judgment result of the variable on the left side (pointer A), and pointer B and pointer A can be associated, that is, the null judgment status of the two pointers is the same.

[0123] If the null pointer judgment result of the value on the right (pointer B) is not null, then the null pointer judgment result of the variable on the left (pointer A) is non-null. If the null pointer judgment result of the value on the right (pointer B) is null, then the null pointer judgment result of the variable on the left (pointer A) is null. If the null pointer judgment result of the value on the right (pointer B) is uncertain, then the null pointer judgment result of the variable on the left (pointer A) is uncertain, that is, it may be null or not. In this way, the null pointer judgment result corresponding to the entire assignment statement can be obtained through the variable on the left (pointer A). At this time, if the variable on the left (pointer A) is a preset pointer, the null pointer judgment result of the preset pointer can be obtained.

[0124] S305: Determine that the null judgment state of the value on the right indicates that the value on the right has not yet been null pointer judged, mark the null judgment state of the variable on the left as not having been null pointer judged, and associate the variable on the left with the value on the right, and end the process.

[0125] Optionally, if the null judgment state of the value (pointer B) on the right side of the assignment operator in the assignment statement indicates that the null pointer judgment has not been performed on the value on the right side (pointer B), mark the null judgment state of the variable on the left side as not having been null pointer judgment, and associate the variable on the left side (pointer A) and the value on the right side (pointer B), that is, reset the null judgment state of pointer A so that the null judgment states of the two pointers are the same.

[0126] S306: Determine whether the result of the assignment statement on the execution path of the preset pointer dereference is unknown, and go to step S307; otherwise, go to step S309.

[0127] Example: Empty fragment statement 2:

[0128]

[0129] The following illustrates this with the null check statement in the second snippet: If pointer A is null, the function returns directly. This is because the execution requires dereferencing pointer A, which must not be null. However, the dereferenced value of pointer B may or may not be greater than 1. Therefore, it is unknown whether the assignment statement (A = B) must be executed before the pre-set pointer dereference (*A = 1) is executed.

[0130] S307: Determine whether the variable on the left is equal to the preset pointer. If not, go to step S302; if equal, go to step S308.

[0131] Optionally, it can be determined whether the variable on the left is equal to a preset pointer. If it is not the preset pointer, go to step S302 and reset and associate the state according to the value on the right.

[0132] S308: Determine the null status of the variable on the left. If the null status of the variable on the left indicates that the variable on the left has been null-pointer checked, go to step S302; otherwise, go to step S310.

[0133] Optionally, if the variable on the left is equal to the preset pointer, it is necessary to determine the null status of the variable on the left (this is the preset pointer). If the null status of the variable on the left (this is the preset pointer) indicates that the variable on the left has already been null-pointer checked, go to step S302 and reset and associate the status according to the value on the right. If the null status of the variable on the left (this is the preset pointer) indicates that the variable on the left has not yet been null-pointer checked, return without further processing.

[0134] S309: Determine that the assignment statement is not on the execution path of the preset pointer dereference, and go to step S310.

[0135] Optionally, if the assignment statement is not on the execution path of the preset pointer dereference, return directly without processing.

[0136] Example: Empty fragment statement three:

[0137]

[0138] The following is an explanation of the null-judgment fragment statement three: when pointer B is not null, pointer A is executed equal to pointer B, otherwise pointer dereference is executed. In other words, the assignment statement and pointer reference are mutually exclusive. Therefore, the assignment statement is not on the execution path of the preset pointer dereference.

[0139] S310: Return.

[0140] In this way, through the assignment statement, the values on both sides of the assignment operator can be added to a unified state, laying the foundation for subsequent null judgment.

[0141] Based on the above, please refer to Figure 4 , which is a flow chart of a method for checking a null pointer in a code provided by an embodiment of the present invention, and is applicable to the null pointer judgment of a preset pointer or pointer B. The following is an explanation based on the preset pointer, including:

[0142] S401: Determine whether a preset pointer is null-pointer checked before the preset pointer is dereferenced. If so, execute step S402; otherwise, execute step S403.

[0143] S402: The null pointer judgment state of the preset pointer is that a null pointer judgment has been performed, and the null pointer judgment result of the preset pointer is non-null.

[0144] S403: Determine whether the preset pointer has been null-pointer-checked in other scopes. If so, execute step S404; otherwise, execute step S405.

[0145] S404: The preset pointer may be empty or definitely empty.

[0146] S405: It is uncertain whether the preset pointer is empty.

[0147] Example: Empty fragment statement 4:

[0148]

[0149] The following is an explanation based on the fourth sentence of the empty segment:

[0150] At the beginning, the pointer A is dereferenced without being judged to be null, so pointer A may be null; but in the following code, pointer A is judged to be null, so A may be null, or pointer A is null, entering the if statement and dereferencing, but because pointer A is null, it terminates directly and returns; because it has already returned when pointer A is null, all references to pointer A within the scope of pointer A below cannot be null; pointer B is not judged to be null, so the state of pointer B is uncertain.

[0151] See also Figure 5 , which is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention, and is applicable to three types of expression statements, including:

[0152] S501: Determine the preset pointer dereference and the location of the preset pointer dereference according to the second null judgment statement.

[0153] S502: Determine whether the parent node of the preset pointer dereference is an AND or OR expression statement. If so, execute step S503; otherwise, execute step S505.

[0154] S503: When the preset pointer dereference is located on the right side of the operator in the AND or OR expression statement, determine the null state of the preset pointer located on the left side of the operator in the AND or OR expression statement.

[0155] In an embodiment of the present application, the AND / OR expression statement includes an AND (&&) expression statement or an OR (||) expression statement.

[0156] S504: If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and the null pointer judgment result of the preset pointer is non-null, determine that the null pointer judgment result of the AND / OR expression statement is non-null.

[0157] Example: Empty fragment statement five:

[0158] void f(char*A,char*B){

[0159] A&&*A; / / &&expression

[0160] !A||*A; / / ||expression

[0161] A? *A:0; / / ternary expression

[0162] }

[0163] The following explains this with reference to the null check statement in Section 5: As can be seen in the AND expression statement and the OR expression statement, pointer A is dereferenced on the right side of the AND expression statement or the OR expression statement. Therefore, the null check status of the preset pointer on the left side of the operator in the AND expression statement indicates that the preset pointer has been null-checked, and the result of the null check for the preset pointer is non-null, confirming that the null pointer check result of the AND expression statement is non-null.

[0164] Similarly, the null judgment state of the preset pointer on the left side of the operator in the or expression statement indicates that the preset pointer has been null pointer judged, and the null pointer judgment result of the preset pointer (here! A) is non-null, which determines that the null pointer judgment result of the and expression statement is non-null.

[0165] S505: The parent node of the preset pointer dereference is a ternary expression statement, and the position of the preset pointer dereference in the ternary expression statement is determined.

[0166] S506: If the preset pointer dereferences the correct expression in the ternary expression statement, execute step S507; otherwise, execute step S509.

[0167] S507: Determine the null state of a preset pointer in the conditional expression in the ternary expression statement.

[0168] S508: When the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment and the null pointer judgment result of the preset pointer is non-null, it is determined that the null pointer judgment result of the ternary expression statement is non-null.

[0169] S509: Determine that the preset pointer dereferences the error expression in the ternary expression statement, and determine the null state of the preset pointer in the conditional expression in the ternary expression statement.

[0170] S510: When the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment and the null pointer judgment result of the preset pointer is null, it is determined that the null pointer judgment result of the ternary expression statement is non-null.

[0171] Let's continue to elaborate on the fifth null judgment fragment statement: It can be seen in the ternary expression statement that pointer A dereferences the correct True expression or the incorrect False expression in the ternary expression statement. Therefore, when pointer A dereferences the correct True expression in the ternary expression statement, the null judgment state of the preset pointer in the conditional expression in the ternary expression statement indicates that the preset pointer has been null pointer judged, and the null pointer judgment result of the preset pointer is non-null, and the null pointer judgment result of the ternary expression statement is determined to be non-null. When pointer A dereferences the incorrect False expression in the ternary expression statement, the null judgment state of the preset pointer in the conditional expression in the ternary expression statement indicates that the preset pointer has been null pointer judged, and the null pointer judgment result of the preset pointer is null, and the null pointer judgment result of the ternary expression statement is determined to be non-null.

[0172] In the embodiment of the present application, only the null pointer judgment results of three types of expression statements are non-null and need to be processed, and other cases do not need to be processed.

[0173] See also Figure 6 , which is a flow chart of a method for checking a null pointer in code provided by an embodiment of the present invention, applicable to conditional statements, including:

[0174] S601: Obtain a conditional expression of a conditional statement.

[0175] In some possible embodiments, the conditional statement includes an if statement, a while statement, and a for statement.

[0176] S602: Split the conditional expression. If the conditional expression is a basic expression, execute step S603; otherwise, execute step S604.

[0177] In the embodiment of the present application, the conditional expression can be split into a basic expression or a non-basic expression.

[0178] 603: When the basic expression is a preset pointer and the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, a judgment position for dereferencing the preset pointer is determined; and the process goes to step S607.

[0179] Assuming that the conditional expression is a basic expression, for example, when the basic expression is a preset pointer "A", when the null judgment state of the preset pointer indicates that the preset pointer has performed a null pointer judgment, the judgment position of the preset pointer dereference is determined.

[0180] S604: Obtain multiple basic expressions; the multiple basic expressions include preset pointers.

[0181] Assuming that the conditional expression is a non-basic expression, it can be split into multiple basic expressions. Optionally, the multiple basic expressions including the preset pointer may include: each basic expression in the multiple basic expressions includes the preset pointer, or some expressions in the multiple basic expressions include the preset pointer. Of course, it is also possible that each basic expression in the multiple basic expressions does not include the preset pointer.

[0182] S605: Determine the null state of the preset pointer based on the null state of the conditional expression.

[0183] S606: If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, a judgment position for dereferencing the preset pointer is determined; and the process goes to step S607.

[0184] S607: Determine the null pointer judgment result of the conditional statement according to the null judgment state of the preset pointer and the judgment position of the preset pointer dereference.

[0185] Example: Empty fragment statement six:

[0186]

[0187] The following is an explanation based on the six empty segment sentences:

[0188] Optionally, if the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is non-null, the null pointer judgment result of the conditional statement is determined to be non-null; or; if the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is null, the null pointer judgment result of the conditional statement is determined to be null.

[0189] Optionally, if the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is non-null, then the null pointer judgment result of the conditional statement is determined to be null; or; if the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is null, then the null pointer judgment result of the conditional statement is determined to be non-null.

[0190] Optionally, if the judgment position of the preset pointer dereference is above the conditional statement, and the null pointer judgment result of the preset pointer is non-null or null, the null pointer judgment result of the conditional statement is determined to be null, and in other cases, it is returned as uncertain.

[0191] Optionally, if the judgment position of the preset pointer dereference is below the conditional statement, the null pointer judgment result of the preset pointer is null, and there is an interrupt statement or reassignment, the null pointer judgment result of the conditional statement is determined to be non-null; in other cases, the null pointer judgment result of the preset pointer is null or non-null, the null pointer judgment result of the conditional statement is determined to be null, and the remaining cases return uncertain.

[0192] Example: Empty fragment statement seven:

[0193]

[0194] The following explains the null check statement in Section 7: First, find the if statement and its conditional statement, b, which is a basic expression. However, it is not equal to the pointer reference A, so we search the state. We can replace b with A&&B, which is an && expression. Then, we can decompose it into the basic expressions A and B, where A is equal to the pointer reference A. Because b is non-null, A is also non-null, so we can return non-null.

[0195] S207 , determining a null pointer comprehensive result corresponding to the current function according to the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function.

[0196] In an embodiment of the present application, if the statements to be judged contained in the current function include three types of expression statements and / or conditional statements, and there is at least one non-empty null pointer judgment result of the statements to be judged contained in the current function, then the null pointer comprehensive result corresponding to the current function is non-empty.

[0197] In an embodiment of the present application, if the statements to be judged contained in the current function include assignment statements and other statements, and the other statements include three types of expression statements and / or conditional statements, when the assignment statement is not the last one in the current function, and there is at least one non-empty null pointer judgment result of the statements to be judged contained in the current function, then the null pointer comprehensive result corresponding to the current function is non-empty.

[0198] In an embodiment of the present application, if the statements to be judged contained in the current function include assignment statements and other statements, and the other statements include three types of expression statements and / or conditional statements, when the assignment statement is the last one in the current function, and when the assignment statement causes its null pointer judgment result to be uncertain due to reset, then the null pointer comprehensive result corresponding to the current function is uncertain.

[0199] That is to say, when the statement to be judged contained in the current function includes an assignment statement, it is necessary to look at the position of the assignment statement in the current function, and then combine the position and the null pointer judgment results of each statement to determine the final null pointer comprehensive result.

[0200] See also Figure 7 , which is a schematic diagram of the structure of a device for checking null pointers in code provided by an embodiment of the present invention. The device has the function of implementing the method for checking null pointers in the code in the above method embodiment. The function can be implemented by hardware or by hardware executing corresponding software. Figure 7 As shown, the null pointer checking device 700 in the code may include:

[0201] The code identification module 701 is used to identify the unit function of the preset code segment and obtain at least one function to be traversed;

[0202] Function traversal module 702, configured to traverse and analyze a current function among at least one to-be-traversed function, and obtain at least one to-be-judged statement from the current function; wherein the to-be-judged statement in the at least one to-be-judged statement is associated with a preset pointer; the to-be-judged statement includes an assignment statement, three types of expression statements, and / or a conditional statement;

[0203] The statement null judgment module 703 is used to perform a null pointer judgment on each statement to be judged according to a preset null judgment rule, and obtain a null pointer judgment result corresponding to each statement to be judged;

[0204] The function null judgment module 704 is used to determine the null pointer comprehensive result corresponding to the current function according to the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function.

[0205] In some possible embodiments, when the statement to be judged is an assignment statement, the preset empty judgment rule includes a first empty judgment statement;

[0206] Statement empty detection module, used for:

[0207] If the assignment statement is on the execution path of the preset pointer dereference, determining the null status of the value on the right side of the assignment operator in the assignment statement based on the first null judgment statement;

[0208] If the null judgment state of the value on the right indicates that the value on the right has been null pointer judged, the null judgment state of the variable on the left side of the assignment operator is marked as having been null pointer judged, and the null pointer judgment result of the value on the right is determined as the null pointer judgment result of the variable on the left; the variable on the left is related to the preset pointer.

[0209] In some possible embodiments, the statement empty detection module is used to:

[0210] If the result of the assignment statement on the execution path of the preset pointer dereference is unknown, and the variable on the left side is not equal to the preset pointer, determine the null state of the value on the right side;

[0211] If the null judgment state of the value on the right indicates that the value on the right has been null pointer judged, the null judgment state of the variable on the left is marked as having been null pointer judged, and the null pointer judgment result of the value on the right is determined as the null pointer judgment result of the variable on the left.

[0212] In some possible embodiments, the statement empty detection module is used to:

[0213] If the result of whether the assignment statement is on the execution path of the preset pointer dereference is unknown, and the variable on the left side is equal to the preset pointer, determine the null state of the variable on the left side;

[0214] If the null status of the variable on the left indicates that the variable on the left has been null-pointer checked, determine the null status of the value on the right;

[0215] If the null judgment state of the value on the right indicates that the value on the right has been null pointer judged, the null judgment state of the variable on the left side of the update mark is updated to indicate that a null pointer judgment has been performed, and the null pointer judgment result of the value on the right is determined as the null pointer judgment result of the preset pointer.

[0216] In some possible embodiments, the statement empty detection module is used to:

[0217] If the null judgment state of the value on the right indicates that the value on the right has not yet been null-pointer-judged, the null judgment state of the variable on the left is marked as not having been null-pointer-judged, and the variable on the left is associated with the value on the right.

[0218] In some possible embodiments, when the statement to be judged is a third-category expression statement, the preset empty judgment rule includes a second empty judgment statement;

[0219] Statement empty detection module, used for:

[0220] Determine the preset pointer dereference and the position of the preset pointer dereference according to the second null judgment statement;

[0221] If the parent node of the preset pointer dereference is an AND or OR expression statement, and the preset pointer dereference is located on the right side of an operator in the AND or OR expression statement, determining the null state of the preset pointer located on the left side of the operator in the AND or expression statement; the AND or expression statement includes an AND expression statement or an OR expression statement;

[0222] If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and the null pointer judgment result of the preset pointer is non-null, it is determined that the null pointer judgment result of the AND or expression statement is non-null.

[0223] In some possible embodiments, the statement empty detection module is used to:

[0224] Determine the preset pointer dereference and the position of the preset pointer dereference according to the second null judgment statement;

[0225] If the parent node of the preset pointer dereference is a ternary expression statement, determine the position of the preset pointer dereference in the ternary expression statement;

[0226] If the preset pointer dereferences the correct expression in the ternary expression statement, determining the null state of the preset pointer in the conditional expression in the ternary expression statement; if the null state of the preset pointer indicates that the preset pointer has been null-pointer-checked, and the null-pointer-check result of the preset pointer is non-null, determining that the null-pointer-check result of the ternary expression statement is non-null;

[0227] or;

[0228] If the preset pointer dereferences an erroneous expression in a ternary expression statement, determine the null judgment state of the preset pointer in the conditional expression in the ternary expression statement; when the null judgment state of the preset pointer indicates that the preset pointer has been null pointer judged, and the null pointer judgment result of the preset pointer is null, determine that the null pointer judgment result of the ternary expression statement is non-null.

[0229] In some possible embodiments, when the statement to be judged is a conditional statement, the preset empty judgment rule includes a third empty judgment statement;

[0230] Statement empty detection module, used for:

[0231] Get the conditional expression of the conditional statement;

[0232] If the conditional expression is a basic expression, the basic expression is a preset pointer, the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and the judgment position of the preset pointer dereference is determined;

[0233] The null pointer judgment result of the conditional statement is determined according to the null judgment state of the preset pointer and the judgment position of the preset pointer dereference.

[0234] In some possible embodiments, the statement empty detection module is used to:

[0235] Get the conditional expression of the conditional statement;

[0236] The conditional expression is disassembled to obtain multiple basic expressions; the multiple basic expressions include preset pointers;

[0237] Determine the null state of the preset pointer based on the null state of the conditional expression;

[0238] If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, determining a judgment position for dereferencing the preset pointer;

[0239] The null pointer judgment result of the conditional statement is determined according to the null judgment state of the preset pointer and the judgment position of the preset pointer dereference.

[0240] In some possible embodiments, the statement empty detection module is used to:

[0241] If the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is non-null, the null pointer judgment result of the conditional statement is determined to be non-null;

[0242] Or; if the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is null, it is determined that the null pointer judgment result of the conditional statement is null.

[0243] In some possible embodiments, the statement empty detection module is used to:

[0244] If the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is non-null, the null pointer judgment result of the conditional statement is determined to be null;

[0245] Or; if the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is null, it is determined that the null pointer judgment result of the conditional statement is non-null.

[0246] In some possible embodiments, the statement empty detection module is used to:

[0247] If the preset pointer is null-pointer checked before the preset pointer is dereferenced, the null-pointer check state of the preset pointer is that the null-pointer check has been performed, and the null-pointer check result of the preset pointer is non-null.

[0248] It should be noted that the apparatus provided in the above embodiments, when implementing its functions, is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0249] An embodiment of the present invention provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement a null pointer checking method in the code provided in the above method embodiment.

[0250] The memory can be used to store software programs and modules. The processor executes various functional applications and null pointer checks by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system, application programs required for the functions, etc.; the data storage area can store data created based on the use of the device, etc. In addition, the memory can include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory can also include a memory controller to provide the processor with access to the memory.

[0251] The method embodiments provided in the embodiments of the present invention can be executed in a computer terminal, a server or a similar computing device. Taking running on a server as an example, Figure 8 This is a hardware structure diagram of a server running a method for checking a null pointer in a code provided by an embodiment of the present invention, such as Figure 8 As shown, the server 2000 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 2010 (the processor 2010 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 2030 for storing data, and one or more storage media 2020 (such as one or more mass storage devices) for storing application programs 2023 or data 2022. Among them, the memory 2030 and the storage medium 2020 can be temporary storage or permanent storage. The program stored in the storage medium 2020 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the central processing unit 2010 can be configured to communicate with the storage medium 2020 and execute a series of instruction operations in the storage medium 2020 on the server 2000. The server 2000 may also include one or more power supplies 2060, one or more wired or wireless network interfaces 2050, one or more input and output interfaces 2040, and / or one or more operating systems 2021, such as Windows ServerTM, Mac OSXTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0252] The input / output interface 2040 can be used to receive or send data via a network. Specific examples of the aforementioned network may include a wireless network provided by the communication provider of the server 2000. In one embodiment, the input / output interface 2040 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In another embodiment, the input / output interface 2040 can be a radio frequency (RF) module for wirelessly communicating with the Internet.

[0253] It can be understood by those skilled in the art that Figure 7 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 7 More or fewer components than shown, or with Figure 7 Different configurations shown.

[0254] An embodiment of the present invention also provides a computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a null pointer checking method in a code. The at least one instruction or the at least one program is loaded and executed by the processor to implement the null pointer checking method in the code provided by the above method embodiment.

[0255] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0256] It should be noted that the order in which the embodiments of the present invention are described above is for illustrative purposes only and does not represent the superiority or inferiority of the embodiments. The above description is of specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0257] An embodiment of the present invention further provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the null pointer check method in the above code.

[0258] The various embodiments in this specification are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences from other embodiments. In particular, the device embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.

[0259] Those skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.

[0260] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for checking null pointers in code, characterized in that: The method comprises: Performing unit function identification on a preset code segment to obtain at least one function to be traversed; Performing traversal analysis on a current function in the at least one to-be-traversed function, and obtaining at least one to-be-judged statement from the current function; wherein the to-be-judged statement in the at least one to-be-judged statement is associated with a preset pointer; the to-be-judged statement includes an assignment statement, three types of expression statements, and / or a conditional statement; Performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged; The null pointer comprehensive result corresponding to the current function is determined according to the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function.

2. The method for checking null pointers in code according to claim 1, wherein: When the statement to be judged is the assignment statement, the preset empty judgment rule includes a first empty judgment statement; The performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged includes: If the assignment statement is on the execution path of the preset pointer dereference, determining the null state of the value on the right side of the assignment operator in the assignment statement based on the first null judgment statement; If the null judgment state of the value on the right side indicates that the value on the right side has undergone a null pointer judgment, the null judgment state of the variable on the left side of the assignment operator is marked as having undergone a null pointer judgment, and the null pointer judgment result of the value on the right side is determined as the null pointer judgment result of the variable on the left side; the variable on the left side is related to the preset pointer.

3. The method for checking null pointers in code according to claim 2, wherein: The performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged includes: If the result of whether the assignment statement is on the execution path of the preset pointer dereference is unknown, and the variable on the left side is not equal to the preset pointer, determining the null state of the value on the right side; If the null judgment state of the value on the right side indicates that the value on the right side has been subjected to a null pointer judgment, the null judgment state of the variable on the left side is marked as having been subjected to a null pointer judgment, and the null pointer judgment result of the value on the right side is determined as the null pointer judgment result of the variable on the left side.

4. The method for checking null pointers in code according to claim 2, wherein: The performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged includes: If the result of whether the assignment statement is on the execution path of the preset pointer dereference is unknown, and the variable on the left side is equal to the preset pointer, determining the null state of the variable on the left side; If the null status of the variable on the left indicates that a null pointer check has been performed on the variable on the left, determining the null status of the value on the right; If the null judgment state of the value on the right side indicates that the value on the right side has been subjected to a null pointer judgment, the null judgment state of the variable on the left side is updated to indicate that a null pointer judgment has been performed, and the null pointer judgment result of the value on the right side is determined as the null pointer judgment result of the preset pointer.

5. The method for checking a null pointer in a code according to any one of claims 2 to 4, wherein: The method further comprises: If the null judgment state of the value on the right side indicates that the value on the right side has not yet been null pointer judged, the null judgment state of the variable on the left side is marked as not having been null pointer judged, and the variable on the left side is associated with the value on the right side.

6. The method for checking null pointers in code according to claim 1, wherein: When the statement to be judged is one of the three types of expression statements, the preset empty judgment rule includes a second empty judgment statement; The performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged includes: Determine the preset pointer dereference and the position of the preset pointer dereference according to the second null judgment statement; If the parent node of the preset pointer dereference is an AND or OR expression statement, and the preset pointer dereference is located on the right side of an operator in the AND or OR expression statement, determining a null state of the preset pointer located on the left side of the operator in the AND or expression statement; the AND or expression statement includes an AND expression statement or an OR expression statement; If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and the null pointer judgment result of the preset pointer is non-null, it is determined that the null pointer judgment result of the AND / OR expression statement is non-null.

7. The method for checking null pointers in code according to claim 6, wherein: The performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged includes: Determine the preset pointer dereference and the position of the preset pointer dereference according to the second null judgment statement; If the parent node of the preset pointer dereference is a ternary expression statement, determining the position of the preset pointer dereference in the ternary expression statement; If the preset pointer dereferences a correct expression in the ternary expression statement, determining a null state of the preset pointer in the conditional expression in the ternary expression statement; if the null state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and the null pointer judgment result of the preset pointer is non-null, determining that the null pointer judgment result of the ternary expression statement is non-null; or; If the preset pointer dereferences an erroneous expression in the ternary expression statement, the null judgment state of the preset pointer in the conditional expression in the ternary expression statement is determined; when the null judgment state of the preset pointer indicates that the preset pointer has performed a null pointer judgment, and the null pointer judgment result of the preset pointer is null, the null pointer judgment result of the ternary expression statement is determined to be non-null.

8. The method for checking null pointers in code according to claim 1, wherein: When the statement to be judged is the conditional statement, the preset empty judgment rule includes a third empty judgment statement; The performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged includes: Obtaining a conditional expression of the conditional statement; If the conditional expression is a basic expression, the basic expression is the preset pointer, the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, and a judgment position for dereferencing the preset pointer is determined; The null pointer judgment result of the conditional statement is determined according to the null judgment state of the preset pointer and the judgment position of the dereference of the preset pointer.

9. The method for checking null pointers in code according to claim 8, wherein: The performing a null pointer judgment on each statement to be judged according to a preset null judgment rule to obtain a null pointer judgment result corresponding to each statement to be judged includes: Obtaining a conditional expression of the conditional statement; Decomposing the conditional expression to obtain a plurality of basic expressions; the plurality of basic expressions include the preset pointer; Determining a null state of the preset pointer based on a null state of the conditional expression; If the null judgment state of the preset pointer indicates that the preset pointer has been subjected to a null pointer judgment, determining a judgment position for dereferencing the preset pointer; The null pointer judgment result of the conditional statement is determined according to the null judgment state of the preset pointer and the judgment position of the dereference of the preset pointer.

10. The method for checking a null pointer in a code according to claim 8 or 9, characterized in that: The determining of the null pointer judgment result of the conditional statement according to the null judgment state of the preset pointer and the judgment position of the dereference of the preset pointer includes: If the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is non-null, determine that the null pointer judgment result of the conditional statement is non-null; Or; if the judgment position of the preset pointer dereference is inside the conditional statement, and the null pointer judgment result of the preset pointer is null, it is determined that the null pointer judgment result of the conditional statement is null.

11. The method for checking a null pointer in a code according to claim 8 or 9, wherein: The determining of the null pointer judgment result of the conditional statement according to the null judgment state of the preset pointer and the judgment position of the dereference of the preset pointer includes: If the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is non-null, it is determined that the null pointer judgment result of the conditional statement is null; Or; if the conditional statement is an if conditional statement, the judgment position of the preset pointer dereference is inside the else of the conditional statement, and the null pointer judgment result of the preset pointer is null, it is determined that the null pointer judgment result of the conditional statement is non-null.

12. The method for checking null pointers in code according to claim 1, wherein: The method further comprises: If the preset pointer is subjected to a null pointer judgment before the preset pointer is dereferenced, the null judgment state of the preset pointer is that the null pointer judgment has been performed, and the null pointer judgment result of the preset pointer is non-null.

13. A device for checking null pointers in code, characterized in that: The device comprises: A code recognition module is used to perform unit function recognition on a preset code segment to obtain at least one function to be traversed; a function traversal module, configured to perform traversal analysis on a current function in the at least one to-be-traversed function, and obtain at least one to-be-judged statement from the current function; wherein the to-be-judged statement in the at least one to-be-judged statement is associated with a preset pointer; and the to-be-judged statement includes an assignment statement, three types of expression statements, and / or a conditional statement; A statement null judgment module is used to perform a null pointer judgment on each statement to be judged according to a preset null judgment rule, and obtain a null pointer judgment result corresponding to each statement to be judged; The function null judgment module is used to determine the null pointer comprehensive result corresponding to the current function according to the null pointer judgment result corresponding to each statement to be judged and the position of each statement to be judged in the current function.

14. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the null pointer checking method in the code according to any one of claims 1 to 12.

15. A computer-readable storage medium, characterized in that The computer-readable storage medium stores at least one instruction or at least one program segment, and the at least one instruction or the at least one program segment is loaded and executed by a processor to implement the null pointer checking method in the code according to any one of claims 1 to 12.