![]() Ptr = (unsigned char *)realloc(ptr, capacity) ![]() )" pattern may cause losing the ptr pointer to this data block.įor example, see the following incorrect code taken from a real-life application: void buffer::resize(unsigned int newSize) The main problem is that using a construct of the "ptr = realloc(ptr. ) returns a null pointer, the data block at the ptr address won't change in size. This third scenario is just what makes it potentially dangerous: if realloc(ptr. This situation may occur when allocating a large data array whose size is comparable to RAM size, and also when the memory is highly segmented. But when changing a memory block's size is currently impossible at all even with moving it, the function will return a null pointer. When changing a memory block's size is impossible without moving it, the function will return the pointer to the new block while the old one will be freed. ![]() When it succeeds to do so without moving the data, the resulting pointer will coincide with the source ptr. ) function is used to change the size of some memory block. This expression is potentially dangerous: it is recommended to save the result of the realloc function into a different variable. The analyzer has detected an expression of the 'foo = realloc(foo.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |