1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-22 20:35:44 +01:00

On some platforms, malloc(0) generates an error. Changed macro to CALLOC(N+1).

This commit is contained in:
Anthony Scemama 2022-05-06 11:08:09 +02:00
parent f00505a763
commit 6edb5a39d7

View File

@ -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~.