A method for managing a C language memory block and a terminal

By combining memory block management objects and function groups, the problem of memory out-of-bounds access in C language is solved, realizing safe and flexible memory block management, improving development efficiency and memory access reliability.

CN114942896BActive Publication Date: 2025-11-07FUJIAN CENTM INFORMATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210440122.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-25
Publication Date
2025-11-07
Estimated Expiration
2042-04-25

AI Technical Summary

Technical Problem

In C programming, memory out-of-bounds issues are difficult to monitor and avoid effectively. Existing methods for circumventing and monitoring these issues are prone to oversights and have limited scope, especially in heap memory management.

Method used

It employs memory block management objects and function groups, enables secure access through memory block description objects, and utilizes static or dynamic check flags for out-of-bounds detection, replacing the direct use of pointers, and providing complete memory block information and out-of-bounds monitoring.

Benefits of technology

It enables secure access to memory blocks, avoids out-of-bounds situations, reduces usage costs, improves development efficiency, supports comprehensive management of read-only and read-write memory, and provides a flexible memory operation interface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114942896B_ABST
    Figure CN114942896B_ABST
Patent Text Reader

Abstract

The application discloses a C language memory block management method and a terminal. A management object is established for a memory block, including a memory block description object and a memory block check flag. The memory block is completely described as an object, and the check function is added so as to facilitate the management. The memory block operation is performed through a function group based on the memory block management object. The safety of the memory operation is ensured through the function based on the memory block description object corresponding to the memory block. The memory check is automatically performed through the function, and the memory out-of-bound is monitored. Compared with the direct pointer access to the memory block, the memory out-of-bound and the like are detected in the function group operation stage, the independent module for the memory out-of-bound is omitted, and various common memory operation methods are provided, so that the developer can be more focused on the implementation of the specific function logic, and the development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of memory management, in particular to a C language memory block management method and terminal. BACKGROUND

[0002] In C language programming, memory access out-of-bounds is the most common and most difficult to troubleshoot problem. Out-of-bounds, by access method, is divided into read out-of-bounds and write out-of-bounds; by overflow type, it is divided into cross-memory block access and jump-memory block access.

[0003] In the prior art, memory data is generally accessed directly through a pointer. In normal circumstances, the pointer will only access the internal space of the memory block. Out-of-bounds is generally in two situations, one is that the pointer accesses the space from the memory block to the adjacent memory block, that is, the pointer will pass through the boundary of the memory block; the other is that the pointer directly jumps into other memory blocks, that is, the pointer does not pass through the boundary of the memory block.

[0004] Memory is also divided into read-only and read-write. Among them, read-only memory is generally used to store programs and resources, and read-write memory is generally used to store variables and data. Read-write memory is divided into static area and dynamic area, and dynamic area is divided into heap and stack. When referring to memory out-of-bounds problem, most of the time refers to write out-of-bounds situation.

[0005] To deal with the memory out-of-bounds problem, there are basically two directions. One direction is to avoid, that is, to avoid the occurrence of out-of-bounds problem through some methods; the other direction is to monitor, that is, to set monitoring points so as to issue an alarm in time after the problem occurs.

[0006] In the prior art, avoidance is generally through management type solutions such as programming specifications and code review, but such solutions are easy to overlook and difficult to implement; monitoring is generally to increase a flag on the boundary of the memory block, and to identify whether out-of-bounds occurs by checking the flag. At present, there are two directions in specific implementation, one is to modify the memory allocation function, and the other is to modify the memory pool, but the monitoring effect is limited and the range is limited to heap memory. SUMMARY

[0007] The technical problem to be solved by the present application is to provide a C language memory block management method and terminal, which can avoid memory out-of-bounds situation and improve the reliability of memory block management.

[0008] In order to solve the above technical problems, the technical scheme adopted by the present application is:

[0009] A C language memory block management method, comprising the steps of:

[0010] establishing a memory block management object for the memory block, the memory block management object comprising a memory block description object and a memory block verification flag, the memory block description object being a structure body for describing the memory block;

[0011] A function group based on the memory block management object is established, and the function group is used to perform safe access to the memory block based on the memory block description object and to perform out-of-bound detection of the memory block based on the memory block check flag.

[0012] To solve the above technical problems, another technical solution adopted by the present application is:

[0013] A C language memory block management terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the following steps when executing the computer program:

[0014] A memory block management object is established for a memory block, the memory block management object comprising a memory block description object and a memory block check flag, and the memory block description object being a structure body describing the memory block;

[0015] A function group based on the memory block management object is established, and the function group is used to perform safe access to the memory block based on the memory block description object and to perform out-of-bound detection of the memory block based on the memory block check flag.

[0016] From the above description, the beneficial effects of the present application are that the memory block description object is used to replace the pointer, various problems that may be caused by directly using the pointer are avoided, and safe access to the memory block is achieved. The complete memory block information can be obtained by the function group through the memory block description object, and the occurrence of memory out-of-bound is avoided. The function group can check the incoming memory block, so that an independent module for regularly checking the memory block can be omitted, and the use cost is reduced. The function group can provide common memory access methods and be extended according to actual needs, and provides safety and convenience for programmers, so that they can focus more on the implementation of specific function logic and the development efficiency is improved. BRIEF DESCRIPTION OF DRAWINGS

[0017] Figure 1 A flowchart of a C language memory block management method according to an embodiment of the present application;

[0018] Figure 2 A schematic diagram of a C language memory block management terminal according to an embodiment of the present application;

[0019] Figure 3 An information structure diagram of a memory block in the prior art;

[0020] Figure 4 A flowchart of creating a memory block management object according to an embodiment of the present application;

[0021] Figure 5 An information structure diagram of a memory block according to an embodiment of the present application;

[0022] Figure 6 Figure 1 is a schematic diagram of reading and writing of an item or area in a memory block in an embodiment of the present application;

[0023] Figure 7 Figure 2 is a schematic diagram of adding and popping of an item in a memory block in an embodiment of the present application;

[0024] Label explanation:

[0025] 1. A C language memory block management terminal; 2. A memory; 3. A processor. DETAILED DESCRIPTION

[0026] To explain the technical content, the achieved purposes and effects of the present application in detail, the following will be explained in combination with the embodiments and the accompanying drawings.

[0027] Please refer to Figure 1 The embodiment of the present application provides a C language memory block management method, comprising the steps of:

[0028] establishing a memory block management object for the memory block, wherein the memory block management object comprises a memory block description object and a memory block check flag, and the memory block description object is a structure body for describing the memory block;

[0029] establishing a function group based on the memory block management object, performing safe access of the memory block based on the memory block description object through the function group, and performing out-of-bound detection of the memory block based on the memory block check flag.

[0030] As can be seen from the above description, the memory block description object is used to replace the pointer, avoiding various problems that may be caused by directly using the pointer, and realizing safe access of the memory block. The complete memory block information can be obtained by the function group through the memory block description object, avoiding occurrence of memory out-of-bound. And the function group can check the input memory block, so that an independent module for regularly checking the memory block can be omitted, reducing the use cost. The function group can provide common memory access methods, and can be extended according to actual needs, providing safety and convenience for programmers, so that they can focus more on the implementation of specific function logic, improving the development efficiency.

[0031] Further, the establishing of the memory block management object for the memory block comprises:

[0032] creating a corresponding memory block management object for the memory block according to the memory block management object creation function, and if the memory block is of a read-only type, establishing a memory management object only comprising the memory block description object;

[0033] If the memory block is of the read-write type, it is determined whether the memory block needs to be checked, if yes, a memory block management object containing a memory block description object and a memory block check flag is established, otherwise, a memory management object containing only the memory block description object is established.

[0034] From the above description, when creating a memory block management object, read-only and read-write memories are supported, and comprehensive support for various memories is achieved. As long as the corresponding memory block is included in the management through the memory block management object creation function, it can be managed.

[0035] Further, the memory block check flag includes a static check flag or a dynamic check flag:

[0036] According to the check requirement, it is determined whether to generate a static check flag, if yes, a fixed value or a feature value generated by an algorithm is selected as the static check flag;

[0037] According to the check requirement, it is determined whether to generate a dynamic check flag, if yes, a check value is generated according to the storage content of the memory block.

[0038] From the above description, read-write memory includes static memory and dynamic memory, so static check flags or dynamic check flags can be generated according to the check requirements of static memory and dynamic memory, so as to facilitate subsequent adaptive out-of-bound detection.

[0039] Further, the out-of-bound detection of the memory block based on the memory block check flag includes:

[0040] If the memory block check flag includes a static check flag, it is determined whether the static check flag changes, if yes, the memory block has cross-memory block out-of-bound;

[0041] If the memory block check flag includes a dynamic check flag, a test checksum is generated according to the current storage content of the memory block, it is determined whether the check value in the dynamic check flag is consistent with the test checksum, if not, the memory block to be operated has jump-memory block out-of-bound.

[0042] From the above description, the check flag is stored at the boundary of the memory block, and can be selected in static or dynamic mode. The static flag mode can monitor the cross-memory block out-of-bound, and the dynamic flag mode can monitor the jump-memory block out-of-bound, thereby realizing complete memory block out-of-bound monitoring.

[0043] Further, the safe access to the memory block based on the memory block description object through the function set includes:

[0044] The memory block description object includes the start address, size, and type of the memory block, and also includes the number of storage items and the size of the storage items of the memory block;

[0045] The memory block description object is passed into a function function in the function group, the effective boundary of the memory block is obtained through the function function, and safe access to the memory block is performed based on the effective boundary;

[0046] When the memory block is passed to a module that needs to access the memory through a pointer, the memory block description object is updated after the storage content of the memory block is modified.

[0047] As can be seen from the above description, support for accessing the memory block in a direct pointer mode is still retained. The memory block start address is a member item of the memory block description object, and can be used as a parameter to seamlessly connect to other modules that still use the direct pointer mode.

[0048] Please refer to Figure 2 Another embodiment of the present application provides a C language memory block management terminal, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor implements the following steps when executing the computer program:

[0049] A memory block management object is established for the memory block, the memory block management object comprises a memory block description object and a memory block check flag, and the memory block description object is a structure body for describing the memory block.

[0050] A function group based on the memory block management object is established, safe access to the memory block is performed based on the memory block description object through the function group, and out-of-bound detection of the memory block is performed based on the memory block check flag.

[0051] As can be seen from the above description, the memory block description object is used instead of the pointer, various problems that may be caused by directly using the pointer are avoided, and safe access to the memory block is realized. The complete memory block information can be obtained by the function group through the memory block description object, and the occurrence of memory out-of-bound is avoided. Moreover, the function group can check the passed-in memory block, so that an independent module for regularly checking the memory block can be omitted, and the use cost is reduced. The function group can provide common memory access methods, and can be extended according to actual needs, so as to provide safety and convenience for programmers, make them more focused on the implementation of specific function logic, and improve the development efficiency.

[0052] Further, the memory block management object comprises:

[0053] The memory block management object is created according to the memory block management object creation function, if the memory block is a read-only type, a memory management object containing only the memory block description object is established;

[0054] If the memory block is of the read-write type, it is determined whether the memory block needs to be checked, if yes, a memory block management object containing a memory block description object and a memory block check flag is established, otherwise, a memory management object containing only the memory block description object is established.

[0055] From the above description, when creating a memory block management object, read-only and read-write memories are supported, and comprehensive support for various memories is achieved. As long as the corresponding memory block is included in the management through the memory block management object creation function, it can be managed.

[0056] Further, the memory block check flag includes a static check flag or a dynamic check flag:

[0057] According to the check requirement, it is determined whether to generate a static check flag, if yes, a fixed value or a feature value generated by an algorithm is selected as the static check flag;

[0058] According to the check requirement, it is determined whether to generate a dynamic check flag, if yes, a check value is generated according to the storage content of the memory block.

[0059] From the above description, read-write memory includes static memory and dynamic memory, so static check flags or dynamic check flags can be generated according to the check requirements of static memory and dynamic memory, so as to adaptively perform boundary detection later.

[0060] Further, the boundary detection of the memory block based on the memory block check flag includes:

[0061] If the memory block check flag includes a static check flag, it is determined whether the static check flag changes, if yes, the memory block has cross-memory block boundary crossing;

[0062] If the memory block check flag includes a dynamic check flag, a test checksum is generated according to the current storage content of the memory block, it is determined whether the check value in the dynamic check flag is consistent with the test checksum, if not, the memory block to be operated has jump-memory block boundary crossing.

[0063] From the above description, the check flag is stored in the boundary of the memory block, and can be selected in static or dynamic mode. The static flag mode can monitor the cross-memory block boundary crossing, and the dynamic flag mode can monitor the jump-memory block boundary crossing, thereby realizing complete memory block boundary monitoring.

[0064] Further, the safe access to the memory block based on the memory block description object through the function set includes:

[0065] The memory block description object includes the start address, size, and type of the memory block, and also includes the number of storage items and the size of the storage items of the memory block;

[0066] The memory block description object is passed into a function function in the function group, the effective boundary of the memory block is obtained through the function function, and safe access of the memory block is performed based on the effective boundary;

[0067] When the memory block is passed to a module that needs to access memory through a pointer, the memory block description object is updated after the storage content of the memory block is modified.

[0068] From the above description, support for accessing the memory block in a direct pointer mode is still retained. The memory block start address is a member item of the memory block description object, and can be used as a parameter to seamlessly connect with other modules that still use the direct pointer mode.

[0069] The above-mentioned C language memory block management method and terminal of the application are suitable for managing memory blocks in C language, avoiding memory out-of-bound situations, and the following specific embodiments are described:

[0070] Embodiment one

[0071] Please refer to Figure 1 , Figures 3 to 5 A C language memory block management method includes the following steps:

[0072] S1, a memory block management object is established for a memory block, the memory block management object includes a memory block description object and a memory block check flag, the memory block description object is a structure variable for describing the memory block; the memory block check flag has static and dynamic types, and is stored at the memory block boundary.

[0073] S11, a memory block management object creation function is used to create a corresponding memory block management object for the memory block, if the type of the memory block is a read-write type, it is further determined whether it is a heap memory, if yes, it is directly applied, otherwise the memory block is passed in from the outside; it is determined whether the memory block needs to be checked, if yes, a static or dynamic check flag is added at the memory block boundary, and the memory block description object is returned, otherwise, the memory block description object is directly returned.

[0074] Specifically, please refer to Figure 3 In the prior art, the information of the memory block includes the start address and size of the memory block, wherein the start address and size information are independent information and are scattered in the code.

[0075] Please refer to Figure 4In this embodiment, the memory block management object is created for the memory block. Specifically, if the memory block is a read-write type memory block, if there is a specified initial value, the memory block is initialized using the specified value, and if there is no specified initial value, the memory block is initialized using a default value. It is judged whether the read-write type memory block needs to be checked. If yes, a static or dynamic check flag is added at the boundary of the memory block, and the memory block description object is returned, otherwise, the memory block description object is directly returned.

[0076] S12, if the type of the memory block is a read-only type, the memory block description object is directly returned.

[0077] Specifically, please refer to Figure 4 , if the memory block is a read-only type memory block, since the read-only memory block does not need to be written, only the safety of memory access needs to be ensured through the legality judgment, and therefore the memory block description object is directly returned.

[0078] S2, a function group based on the memory block management object is established, and the function functions in the group include memory block safe access and memory overflow monitoring. The safe access depends on the complete memory block description information provided by the memory block description object, and the memory overflow monitoring depends on the check flag of the memory block.

[0079] Specifically, step S2 includes:

[0080] The function performs safe access of the memory block based on the memory block description object, and performs overflow detection of the memory block based on the check flag of the memory block.

[0081] Among them, please refer to Figure 5 , the member items of the memory block description object include the start address, size and type of the memory block, in this embodiment, the type of the memory block is shown in table 1; the check mode includes static check flag and dynamic check flag, and the dynamic check flag is updated synchronously with the memory block storage content.

[0082] Table 1 type of memory block

[0083]

[0084] Among them, the function group includes but is not limited to the necessary functions for creating and deleting memory blocks, the basic functions for memory block copying and value setting, and the check functions.

[0085] In this embodiment, the creation function of the memory block object is:

[0086] mem_t MemNew(void*ptr,int size,int count,int len,unsigned int type);

[0087] The parameters at the time of creation directly correspond to the member variables of the structure. When the memory block is of the MEM_TYPE_VAR type, memory needs to be applied. After creation, the mem_t type structure is returned.

[0088] The deletion function of the memory block object is:

[0089] int MemDel(mem_t mem);

[0090] When the memory block is of the MEM_TYPE_VAR type, memory needs to be released.

[0091] The basic read-write operation function of the memory block is:

[0092] void*MemItem(mem_t*pMem, int index);

[0093] Similar to the array access method, it is very convenient. The index parameter can use negative numbers, such as -1 to represent the index of the last valid item of the memory block.

[0094] S21, the memory block description object is input into the function group of the function function, and the effective boundary of the memory block is obtained through the function function, and the safe access of the memory block is carried out based on the effective boundary.

[0095] Specifically, the function obtains the starting address, size and type of the memory block, compares the above information with the operation planned by the memory block, judges the legality and effectiveness of the memory block operation according to the comparison result, ensures that all memory operations only occur within the effective boundary of the memory block, and avoids the occurrence of memory overflow, that is, the security problem can be solved by accessing memory through the function group.

[0096] S22, judge whether the static check flag of the memory block changes, if yes, the memory block has cross-memory block overflow, otherwise, the memory block does not have cross-memory block overflow.

[0097] Specifically, the function group will detect the static check flag of the memory block to identify whether cross-memory block overflow has occurred.

[0098] In this embodiment, since most of the overflow occurs at the tail of the memory block, a fixed flag is added at the tail of the memory block, and in some embodiments, a fixed flag can also be added at the head of the memory block according to the need. The static flag can adopt a fixed value, or can generate a characteristic value by algorithm. Once the memory block has write overflow, the fixed flag may be modified. That is, by judging whether the value of the fixed flag changes, whether the memory block has write overflow is identified.

[0099] S23, generating a test checksum according to the storage content of the memory block, judging whether the dynamic check flag is consistent with the test checksum, if yes, the memory block does not exist the jump memory block out-of-bound, otherwise, the memory block to be operated exists the jump memory block out-of-bound.

[0100] Specifically, a checksum is generated for the memory block using a check algorithm, for example, LRC check (Longitudinal Redundancy Check). The checksum is updated synchronously with the data in the memory block. In this way, the memory block object is checked before each use, so that the function group can identify whether the jump memory block out-of-bound occurs in time through the checksum.

[0101] The checksum can check only the valid data part of the memory block. If the memory block is accessed through the function group of the module, the checksum is automatically updated after the write operation is completed. If the memory block is not accessed through the function group of the module, a related function needs to be called to update the checksum after the write operation is completed.

[0102] Therefore, the static check flag mode has little effect on programming and low effect on execution efficiency, and can be used as a standard configuration of the check function. The dynamic check flag mode needs to call a function to update the checksum when there is a demand for memory block access that does not go through the function group of the module. Moreover, the checksum needs to be calculated frequently, which affects the execution efficiency to some extent. Therefore, the checksum mode can be used as an optional configuration of the check function, for example, used only during debugging.

[0103] In summary, the embodiment generates a data structure that completely describes and effectively checks the memory block, and a function group that manages and accesses the memory block. The user accesses the memory block through the data structure and the function group provided by the module. A method for safely accessing the memory block is provided, and a practical memory operation means is also provided. At the same time, a complete out-of-bound monitoring mechanism is matched to discover the out-of-bound behavior in time. The memory block management method of the embodiment supports read-only memory and read-write memory, and can monitor cross-memory block out-of-bound and jump memory block out-of-bound.

[0104] Embodiment Two

[0105] Please refer to Figures 5 to 7 The difference between the embodiment and the embodiment one is that the structure of the memory block description object further includes the storage item size and the number of valid storage items.

[0106] Specifically, the dynamic access of the memory and the dynamic allocation of the memory block are performed based on the storage item size and the number of valid storage items of the memory block.

[0107] In the embodiment, the memory block storage item information is introduced, on one hand, to avoid losing the convenience of the original pointer access after the unified management of the memory block, the memory block is generally used to store a group of data of the same type, and with the information of the storage item size, the required position can be conveniently indexed. On the other hand, the unified management of the memory block also has flexibility that the pointer does not have, and with the number of effective data items, the data items can be more conveniently added or deleted.

[0108] In the embodiment, the storage item size is added in the memory block description object, because the pointer not only indicates the memory address, but also indicates the data type of the storage item. When the memory block is described by a unified structure type, the data type information originally expressed by the pointer cannot be recorded. However, no matter which data type, when the memory operation is performed, the space size occupied by the data type is really useful.

[0109] In the embodiment, the number of effective storage items is added in the memory block description object, to facilitate the addition and truncation of data items. Taking a string as an example, the content can be added by using the strcat function, and the string length can be obtained by using the strlen function, but this does not apply to a normal array. Through this parameter, the normal array managed by the module can also be added with new items at any time, and the length can be obtained. The string included in the management can also save the strlen call, and the operation efficiency of the string is improved.

[0110] In addition, through the storage item information, the function of allocating memory space on demand can be realized. In some scenarios, the actual space to be used is not known at the stage of applying for memory, so that the situation of insufficient space or too large waste occurs. Through this parameter, the function group can directly report an error or automatically expand the memory space when the space is insufficient.

[0111] In the embodiment, if the memory block is in the heap space of the dynamic memory, the function group can also automatically expand the memory block size according to the need when identifying that the space is insufficient. In this way, the safety problem of accessing the memory block is solved, and the programming logic is also simplified. If the storage content of the memory block is a string type, because of the ending feature of the string, a set of additional function interfaces can be provided for the string type, to facilitate the use.

[0112] Please refer to Figure 6 After encapsulation, the memory block can not only read and write the specified interval, but also access the specified storage item in the form of an array. Therefore, after encapsulation, the safety of access is ensured without reducing the convenience of access. At the same time, through encapsulation, more convenient and safe memory block access methods can be obtained. For example Figure 7 The addition and pop of the storage item in

[0113] int MemAppend(mem_t *pMem, void *pItem, int count);

[0114] int MemPop(mem_t *pMem, int count);

[0115] Data items are appended to the memory block by MemAppend, and when the memory block is insufficient in space, a larger memory can be automatically reallocated, or an error can be directly reported. Data items at the tail are deleted by MemPop. Users can freely extend the read-write access interface they want according to needs.

[0116] Therefore, storage item information is added in the memory block description object, so as to facilitate the provision of more flexible and convenient memory access methods.

[0117] Embodiment Three

[0118] Please refer to Figure 2 A C language memory block management terminal 1 includes a memory 2, a processor 3, and a computer program stored on the memory and executable on the processor, and the processor implements each step of the C language memory block management method of embodiments one and two when executing the computer program.

[0119] To sum up, the C language memory block management method and terminal provided by the present application establish a management object for the memory block, including a memory block description object and a memory block check flag. The memory block is completely described as an object, and the check function is increased to facilitate management. Memory block operations are performed through a function group based on the memory block management object. The safety of memory operations is ensured through the function based on the memory block description object corresponding to the memory block. The memory is automatically checked by the function to monitor memory out-of-bounds. Compared with direct pointer access to the memory block, the memory out-of-bounds detection is performed during the function group operation stage, independent modules for periodic detection of memory out-of-bounds are saved, and various common memory operation methods are provided, so that developers can focus more on the implementation of specific function logic and improve development efficiency.

[0120] The above description is only an embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent transformation or direct or indirect application in related technical fields based on the content of the specification and drawings is also included in the patent protection scope of the present application.

Claims

1. A method of managing C language memory blocks, characterized by, The method comprises the steps of: establishing a memory block management object for a memory block, the memory block management object comprising a memory block description object and a memory block check flag, the memory block description object being a structure body describing the memory block; establishing a function group based on the memory block management object, the function group being used to perform safe access to the memory block based on the memory block description object and to perform out-of-bound detection of the memory block based on the memory block check flag; the safe access to the memory block based on the memory block description object by the function group comprises: the memory block description object comprises a start address, a size, and a type of the memory block, and further comprises a number of storage items and a size of the storage items in the memory block, the storage items being valid data items in the memory block; the memory block description object is passed into a function function in the function group, the function function being used to obtain valid boundaries of the memory block and to perform safe access to the memory block based on the valid boundaries; when the memory block is passed to a module that needs to access memory through a pointer, the memory block description object is updated after the storage content of the memory block is modified.

2. The method for managing C language memory blocks according to claim 1, wherein, The memory block management object comprises: a corresponding memory block management object is created for the memory block according to a memory block management object creation function, if the memory block is of a read-only type, a memory management object containing only the memory block description object is established; if the memory block is of a read-write type, it is determined whether the memory block needs to be checked, if yes, a memory block management object containing the memory block description object and the memory block check flag is established, otherwise, a memory management object containing only the memory block description object is established.

3. The method for managing C language memory blocks according to claim 1, wherein, The memory block check flag comprises a static check flag or a dynamic check flag: it is determined whether to generate a static check flag according to a check requirement, if yes, a fixed value or a feature value generated by an algorithm is selected as the static check flag; it is determined whether to generate a dynamic check flag according to a check requirement, if yes, a check value is generated according to the storage content of the memory block.

4. The method for managing C language memory blocks according to claim 3, wherein, The out-of-bound detection of the memory block based on the memory block check flag comprises: if the memory block check flag comprises a static check flag, it is determined whether the static check flag changes, if yes, the memory block has cross-memory block out-of-bound; if the memory block check flag comprises a dynamic check flag, a test check sum is generated according to the current storage content of the memory block, it is determined whether the check value in the dynamic check flag is consistent with the test check sum, if not, the memory block has intra-memory block out-of-bound.

5. A terminal for managing C language memory blocks, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the following steps when executing the computer program: establishing a memory block management object for a memory block, the memory block management object comprising a memory block description object and a memory block check flag, the memory block description object being a structure body describing the memory block; establishing a function group based on the memory block management object, the function group being used to perform safe access to the memory block based on the memory block description object and to perform out-of-bound detection of the memory block based on the memory block check flag; the safe access to the memory block based on the memory block description object by the function group comprises: The memory block description object includes a start address, a size, and a type of the memory block, and further includes a number of storage items in the memory block and a size of the storage items, the storage items being valid data items in the memory block; The memory block description object is transmitted into a function function in the function group, and an effective boundary of the memory block is obtained through the function function, and safe access to the memory block is performed based on the effective boundary; When the memory block is transmitted to a module requiring access to memory through a pointer, the memory block description object is updated after the storage content of the memory block is modified.

6. The terminal for managing C language memory blocks according to claim 5, wherein The memory block management object includes: According to the memory block management object creation function, a corresponding memory block management object is created for the memory block, if the memory block is a read-only type, a memory management object only including the memory block description object is established; If the memory block is a read-write type, it is judged whether the memory block needs to be checked, if yes, a memory block management object including the memory block description object and a memory block check flag is established, otherwise, a memory management object only including the memory block description object is established.

7. The terminal for managing C language memory blocks according to claim 5, wherein The memory block check flag includes a static check flag or a dynamic check flag: According to the check requirement, it is judged whether to generate a static check flag, if yes, a fixed value or a characteristic value generated by an algorithm is selected as the static check flag; According to the check requirement, it is judged whether to generate a dynamic check flag, if yes, a check value is generated according to the storage content of the memory block.

8. The terminal for managing C language memory blocks according to claim 7, wherein, The out-of-bound detection of the memory block based on the memory block check flag includes: If the memory block check flag includes a static check flag, it is judged whether the static check flag changes, if yes, the memory block has cross-memory block out-of-bound; If the memory block check flag includes a dynamic check flag, a test check sum is generated according to the current storage content of the memory block, it is judged whether the check value in the dynamic check flag is consistent with the test check sum, if not, the memory block has intra-memory block out-of-bound.