hit9 / todo.c

Command line lightweight todo tool with readable storage , written in C.
BSD 2-Clause "Simplified" License
132 stars 23 forks source link

Fix all malloc and other potential memory problem (work-in-process) #10

Closed xuchunyang closed 10 years ago

xuchunyang commented 10 years ago
hit9 commented 10 years ago

It's necessary.

xuchunyang commented 10 years ago

It's necessary.

hmm, necessary for what exactly?

I am new to C programming and I plan to give up this pull request and create my own todo command line tool. Thank you for sharing the code.

nutsi commented 10 years ago

Check the return of malloc is a good practice but the manual says : man malloc(3) section NOTES

By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available.

But It's always a good idea to check if a pointer is valid before using it.

For the cast of malloc's return, I don't know the reason of that, you can read everything about that on internet.

hit9 commented 10 years ago

Thanks @nutsi .