troydhanson / uthash

C macros for hash tables and more
Other
4.18k stars 926 forks source link

utstring.h: fix wrong sequence of parameters calling calloc(). #141

Closed silvioprog closed 6 years ago

silvioprog commented 6 years ago

Hello.

According to man 3 calloc, the first parameter of calloc() function is the nmemb of elements:

SYNOPSIS

...

       void *calloc(size_t nmemb, size_t size);

...

DESCRIPTION

...

       The  calloc()  function allocates memory for an array of nmemb elements
       of size bytes each and returns a pointer to the allocated memory.   The
       memory  is  set  to zero.  If nmemb or size is 0, then calloc() returns
       either NULL, or a unique pointer value that can later  be  successfully
       passed to free().

So this PR should fix it.

(notice it was property used here).

Thank you!

Quuxplusone commented 6 years ago

LGTM, but I'd be inclined to merge 1dd1d23 instead, because I don't see why we need calloc at all. Anyone feel like defending calloc here? Otherwise I'll merge 1dd1d23 in a few days.

Issue #94 is tangentially related, btw.

silvioprog commented 6 years ago

Since utstring_init() already zero-initializes the structure, +1 for pure malloc() since . :smiley:

silvioprog commented 6 years ago

Closing to merge https://github.com/troydhanson/uthash/commit/1dd1d2394a5527ae03b4368934c4afc1a8c422d8 as better fixing.

silvioprog commented 6 years ago

Thanks dudes! :+1: :smiley: :+1: