From 96021689c87ea2f05a44fc2cd07e69ba0e8f42f8 Mon Sep 17 00:00:00 2001 From: Vinh Truong Date: Sat, 1 Jun 2019 12:07:19 +0300 Subject: [PATCH] hmlen and hmlenu now returns 0 on NULL pointer --- stb_ds.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stb_ds.h b/stb_ds.h index 411f8a8..54a31b4 100644 --- a/stb_ds.h +++ b/stb_ds.h @@ -491,8 +491,8 @@ extern void * stbds_shmode_func(size_t elemsize, int mode); #define stbds_hmgets(t, k) (*stbds_hmgetp(t,k)) #define stbds_hmget(t, k) (stbds_hmgetp(t,k)->value) -#define stbds_hmlen(t) (stbds_arrlen((t)-1)-1) -#define stbds_hmlenu(t) (stbds_arrlenu((t)-1)-1) +#define stbds_hmlen(t) ((t) ? (ptrdiff_t) stbds_header((t)-1)->length-1 : 0) +#define stbds_hmlenu(t) ((t) ? stbds_header((t)-1)->length-1 : 0) #define stbds_shput(t, k, v) \ ((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_HM_STRING), \