Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data allocated by malloc() is not zero

I use 'malloc()' to allocate memory for a structure in C language. Part of the structure is as below:

struct f2fs_sb_info {
    struct f2fs_fsck *fsck;
    struct f2fs_super_block *raw_super;
    struct f2fs_nm_info *nm_info;
    struct f2fs_sm_info *sm_info;
    struct f2fs_checkpoint *ckpt;
};

I find that the value of raw_super is always zero, while the value of ckpt is always 0x40000050.

I know that malloc() will not initialize the allocated memory. So the allocated memory should has random value. But the value of ckpt is always 0x40000050 and does not change every time I run the program. Why?

like image 670
user1651758 Avatar asked Dec 03 '25 12:12

user1651758


1 Answers

Allocated memory can store any value after allocation, but it does not have to be random - allocation is not random generator at all.

like image 98
FunkyCat Avatar answered Dec 05 '25 02:12

FunkyCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!