Kouhei Sutou
null+****@clear*****
Wed Nov 23 12:17:25 JST 2016
Kouhei Sutou 2016-11-23 12:17:25 +0900 (Wed, 23 Nov 2016) New Revision: 85b19d9a95697e01e776c50c574da9961e9cc501 https://github.com/groonga/groonga/commit/85b19d9a95697e01e776c50c574da9961e9cc501 Message: Set alloc_size attribute for _FORTIFY_SOURCE Modified files: include/groonga/groonga.h include/groonga/plugin.h lib/grn_alloc.h Modified: include/groonga/groonga.h (+10 -0) =================================================================== --- include/groonga/groonga.h 2016-11-22 18:00:30 +0900 (d08343d) +++ include/groonga/groonga.h 2016-11-23 12:17:25 +0900 (bbeea9c) @@ -1064,6 +1064,16 @@ GRN_API grn_log_level grn_logger_get_max_level(grn_ctx *ctx); # define GRN_ATTRIBUTE_PRINTF(fmt_pos) #endif /* __GNUC__ */ +#ifdef __GNUC__ +# define GRN_ATTRIBUTE_ALLOC_SIZE(size) \ + __attribute__ ((alloc_size(size))) +# define GRN_ATTRIBUTE_ALLOC_SIZE_N(n, size) \ + __attribute__ ((alloc_size(n, size))) +#else +# define GRN_ATTRIBUTE_ALLOC_SIZE(size) +# define GRN_ATTRIBUTE_ALLOC_SIZE_N(n, size) +#endif /* __GNUC__ */ + GRN_API void grn_logger_put(grn_ctx *ctx, grn_log_level level, const char *file, int line, const char *func, const char *fmt, ...) GRN_ATTRIBUTE_PRINTF(6); GRN_API void grn_logger_putv(grn_ctx *ctx, Modified: include/groonga/plugin.h (+16 -6) =================================================================== --- include/groonga/plugin.h 2016-11-22 18:00:30 +0900 (f8fdca6) +++ include/groonga/plugin.h 2016-11-23 12:17:25 +0900 (260714d) @@ -64,12 +64,22 @@ GRN_PLUGIN_EXPORT grn_rc GRN_PLUGIN_FIN(grn_ctx *ctx); Don't call these functions directly. Use GRN_PLUGIN_MALLOC(), GRN_PLUGIN_CALLOC(), GRN_PLUGIN_REALLOC() and GRN_PLUGIN_FREE() instead. */ -GRN_API void *grn_plugin_malloc(grn_ctx *ctx, size_t size, const char *file, - int line, const char *func); -GRN_API void *grn_plugin_calloc(grn_ctx *ctx, size_t size, const char *file, - int line, const char *func); -GRN_API void *grn_plugin_realloc(grn_ctx *ctx, void *ptr, size_t size, - const char *file, int line, const char *func); +GRN_API void *grn_plugin_malloc(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +GRN_API void *grn_plugin_calloc(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +GRN_API void *grn_plugin_realloc(grn_ctx *ctx, + void *ptr, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3); GRN_API void grn_plugin_free(grn_ctx *ctx, void *ptr, const char *file, int line, const char *func); Modified: lib/grn_alloc.h (+53 -14) =================================================================== --- lib/grn_alloc.h 2016-11-22 18:00:30 +0900 (2026c67) +++ lib/grn_alloc.h 2016-11-23 12:17:25 +0900 (8ea98cd) @@ -53,18 +53,31 @@ void grn_alloc_info_free(grn_ctx *ctx); #define GRN_CTX_ALLOC_L(ctx,s) grn_ctx_alloc_lifo(ctx,s,f,__FILE__,__LINE__,__FUNCTION__) #define GRN_CTX_FREE_L(ctx,p) grn_ctx_free_lifo(ctx,p,__FILE__,__LINE__,__FUNCTION__) -void *grn_ctx_malloc(grn_ctx *ctx, size_t size, - const char* file, int line, const char *func); -void *grn_ctx_calloc(grn_ctx *ctx, size_t size, - const char* file, int line, const char *func); -void *grn_ctx_realloc(grn_ctx *ctx, void *ptr, size_t size, - const char* file, int line, const char *func); +void *grn_ctx_malloc(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +void *grn_ctx_calloc(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +void *grn_ctx_realloc(grn_ctx *ctx, + void *ptr, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3); char *grn_ctx_strdup(grn_ctx *ctx, const char *s, const char* file, int line, const char *func); void grn_ctx_free(grn_ctx *ctx, void *ptr, const char* file, int line, const char *func); -void *grn_ctx_alloc_lifo(grn_ctx *ctx, size_t size, - const char* file, int line, const char *func); +void *grn_ctx_alloc_lifo(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); void grn_ctx_free_lifo(grn_ctx *ctx, void *ptr, const char* file, int line, const char *func); @@ -90,9 +103,22 @@ void grn_ctx_set_strdup(grn_ctx *ctx, grn_strdup_func strdup_func); grn_free_func grn_ctx_get_free(grn_ctx *ctx); void grn_ctx_set_free(grn_ctx *ctx, grn_free_func free_func); -void *grn_malloc(grn_ctx *ctx, size_t size, const char* file, int line, const char *func); -void *grn_calloc(grn_ctx *ctx, size_t size, const char* file, int line, const char *func); -void *grn_realloc(grn_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func); +void *grn_malloc(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +void *grn_calloc(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +void *grn_realloc(grn_ctx *ctx, + void *ptr, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3); char *grn_strdup(grn_ctx *ctx, const char *s, const char* file, int line, const char *func); void grn_free(grn_ctx *ctx, void *ptr, const char *file, int line, const char *func); #else @@ -103,9 +129,22 @@ void grn_free(grn_ctx *ctx, void *ptr, const char *file, int line, const char *f # define grn_free grn_free_default #endif -GRN_API void *grn_malloc_default(grn_ctx *ctx, size_t size, const char* file, int line, const char *func); -void *grn_calloc_default(grn_ctx *ctx, size_t size, const char* file, int line, const char *func); -void *grn_realloc_default(grn_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func); +GRN_API void *grn_malloc_default(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +void *grn_calloc_default(grn_ctx *ctx, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2); +void *grn_realloc_default(grn_ctx *ctx, + void *ptr, + size_t size, + const char *file, + int line, + const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3); GRN_API char *grn_strdup_default(grn_ctx *ctx, const char *s, const char* file, int line, const char *func); GRN_API void grn_free_default(grn_ctx *ctx, void *ptr, const char* file, int line, const char *func); -------------- next part -------------- HTML����������������������������...Download