Mercurial > blahgd > fmt4
changeset 1106:ce81b2604b4a
use libjeffpc's mem_reallocarray instead of open-coding it ourselves
This way we avoid multiplication overflow issues and make the code easier to
read.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Fri, 16 Feb 2018 12:02:26 -0500 |
parents | 6d806ee912ac |
children | bb2882be9b2b |
files | config.cmake config.h.in post_nv.c sidebar.c |
diffstat | 4 files changed, 6 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/config.cmake Fri Sep 08 08:48:24 2017 +0300 +++ b/config.cmake Fri Feb 16 12:02:26 2018 -0500 @@ -22,8 +22,6 @@ include(CheckFunctionExists) -check_function_exists(reallocarray HAVE_REALLOCARRAY) - set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") find_package(jeffpc)
--- a/config.h.in Fri Sep 08 08:48:24 2017 +0300 +++ b/config.h.in Fri Feb 16 12:02:26 2018 -0500 @@ -23,8 +23,6 @@ #ifndef __CONFIG_H #define __CONFIG_H -#cmakedefine HAVE_REALLOCARRAY - /* settings */ #cmakedefine DEFAULT_SCGI_PORT ${DEFAULT_SCGI_PORT}
--- a/post_nv.c Fri Sep 08 08:48:24 2017 +0300 +++ b/post_nv.c Fri Feb 16 12:02:26 2018 -0500 @@ -22,6 +22,7 @@ #include <jeffpc/val.h> #include <jeffpc/list.h> +#include <jeffpc/mem.h> #include "iter.h" #include "post.h" @@ -37,11 +38,7 @@ ntags = avl_numnodes(list); -#ifdef HAVE_REALLOCARRAY - tags = reallocarray(NULL, ntags, sizeof(struct nvval)); -#else - tags = malloc(ntags * sizeof(struct nvval)); -#endif + tags = mem_reallocarray(NULL, ntags, sizeof(struct nvval)); if (!tags) return -ENOMEM; @@ -79,11 +76,7 @@ if (!ncomments) return 0; -#ifdef HAVE_REALLOCARRAY - comments = reallocarray(NULL, ncomments, sizeof(struct nvval)); -#else - comments = malloc(ncomments * sizeof(struct nvval)); -#endif + comments = mem_reallocarray(NULL, ncomments, sizeof(struct nvval)); if (!comments) return -ENOMEM; @@ -226,11 +219,7 @@ maxtime = 0; -#ifdef HAVE_REALLOCARRAY - nvposts = reallocarray(NULL, nposts, sizeof(struct nvval)); -#else - nvposts = malloc(nposts * sizeof(struct nvval)); -#endif + nvposts = mem_reallocarray(NULL, nposts, sizeof(struct nvval)); ASSERT(nvposts); nnvposts = 0;
--- a/sidebar.c Fri Sep 08 08:48:24 2017 +0300 +++ b/sidebar.c Fri Feb 16 12:02:26 2018 -0500 @@ -26,6 +26,7 @@ #include <sys/sysmacros.h> #include <jeffpc/error.h> +#include <jeffpc/mem.h> #include "req.h" #include "vars.h" @@ -56,11 +57,7 @@ { struct tagcloud_state *state = arg; -#ifdef HAVE_REALLOCARRAY - state->cloud = reallocarray(NULL, ntags, sizeof(struct nvval)); -#else - state->cloud = malloc(ntags * sizeof(struct nvval)); -#endif + state->cloud = mem_reallocarray(NULL, ntags, sizeof(struct nvval)); state->ntags = 0; return state->cloud ? 0 : -ENOMEM;