mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-01-10 21:18:35 +01: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
|
||||||
|
|
||||||
Memory allocation of structures can be facilitated by using the
|
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.
|
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
|
#+begin_src c :tangle trexio_private.h
|
||||||
#define MALLOC(T) (T*) malloc (sizeof(T))
|
#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
|
#+end_src
|
||||||
|
|
||||||
When a pointer is freed, it should be set to ~NULL~.
|
When a pointer is freed, it should be set to ~NULL~.
|
||||||
|
Loading…
Reference in New Issue
Block a user