mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-08-25 06:31:43 +02:00
On some platforms, malloc(0) generates an error. Changed macro to CALLOC(N+1).
This commit is contained in:
parent
f00505a763
commit
6edb5a39d7
@ -131,12 +131,13 @@ __trexio_path__ = None
|
||||
** Memory allocation
|
||||
|
||||
Memory allocation of structures can be facilitated by using the
|
||||
following macro, which ensures that the size of the allocated
|
||||
following macros, which ensure that the size of the allocated
|
||||
object is the same as the size of the data type pointed by the pointer.
|
||||
For CALLOC, we allocate N+1 to avoid errors when N=0.
|
||||
|
||||
#+begin_src c :tangle trexio_private.h
|
||||
#define MALLOC(T) (T*) malloc (sizeof(T))
|
||||
#define CALLOC(N,T) (T*) calloc ( (N) , sizeof(T) )
|
||||
#define CALLOC(N,T) (T*) calloc ( (N)+1 , sizeof(T) )
|
||||
#+end_src
|
||||
|
||||
When a pointer is freed, it should be set to ~NULL~.
|
||||
|
Loading…
Reference in New Issue
Block a user