From a3ef623d49824ba2ab90ede71ca2551fb8c57d70 Mon Sep 17 00:00:00 2001 From: Ning Yu Date: Mon, 10 Aug 2020 09:13:58 +0800 Subject: [PATCH] ic-proxy: type checking in ic_proxy_new() A typical mistake on allocating typed memory is as below: int64 *ptr = malloc(sizeof(int32)); To prevent this, now we make ic_proxy_new() a typed allocator, it always return a pointer of the specified type, for example: int64 *p1 = ic_proxy_new(int64); /* good */ int64 *p2 = ic_proxy_new(int32); /* bad, gcc will raise a warning */ Reviewed-by: Hubert Zhang --- src/backend/cdb/motion/ic_proxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/cdb/motion/ic_proxy.h b/src/backend/cdb/motion/ic_proxy.h index a25a2f0252..f827159c61 100644 --- a/src/backend/cdb/motion/ic_proxy.h +++ b/src/backend/cdb/motion/ic_proxy.h @@ -31,7 +31,7 @@ #define ic_proxy_alloc(size) palloc(size) #define ic_proxy_free(ptr) pfree(ptr) -#define ic_proxy_new(type) ic_proxy_alloc(sizeof(type)) +#define ic_proxy_new(type) ((type *) ic_proxy_alloc(sizeof(type))) #define ic_proxy_log(elevel, msg...) do { \ if (elevel >= IC_PROXY_LOG_LEVEL) \ -- GitLab