From aa9f986130cf6e46b3f8b5c493892dc479893902 Mon Sep 17 00:00:00 2001 From: Filip Pizlo Date: Fri, 1 Mar 2024 16:31:22 -0800 Subject: [PATCH] convert more allocation calls to stdfil API; as usual, the regex I used is included in fixalloc.rb for posterity. --- fixalloc.rb | 14 +++++++++----- mux.c | 3 +-- openbsd-compat/glob.c | 4 ++-- readconf.c | 8 ++------ scp.c | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/fixalloc.rb b/fixalloc.rb index ff347418daf2..1288d48fb531 100755 --- a/fixalloc.rb +++ b/fixalloc.rb @@ -52,7 +52,7 @@ # | match | # "zrealloc(zrestrict(#{$1}, typeof(#{$4}), #{$2}), typeof(#{$4}), #{$3})" #} - #contents.gsub!(/xzrealloc/) { | match | "zrealloc" } + contents.gsub!(/xzrealloc/) { | match | "zrealloc" } #contents.gsub!(/calloc\(([^\n]+), sizeof\(([a-zA-Z0-9_ *]+)\)\)/) { # | match | # "zalloc(#{$2}, #{$1})" @@ -73,9 +73,13 @@ # | match | # "zrealloc(zrestrict(#{$1}, typeof(#{$4}), #{$2}), typeof(#{$4}), #{$3})" #} - contents.gsub!(/xcalloc\(\s*([^\n]+),\s+sizeof\(([ a-zA-Z0-9_*>-]+)\)\)/) { - | match | - "zalloc(typeof(#{$2}), #{$1})" - } + #contents.gsub!(/xcalloc\(\s*([^\n]+),\s+sizeof\(([ a-zA-Z0-9_*>-]+)\)\)/) { + # | match | + # "zalloc(typeof(#{$2}), #{$1})" + #} + #contents.gsub!(/reallocarray\(\s*([^\n]+),\s+([^\n]+),\s+sizeof\(([a-zA-Z0-9_*>-]+)\)\)/) { + # | match | + # "zrealloc(#{$1}, typeof(#{$3}), #{$2})" + #} IO::write(filename, contents) } diff --git a/mux.c b/mux.c index 1fae777fa2d7..dae46dafbdf0 100644 --- a/mux.c +++ b/mux.c @@ -373,8 +373,7 @@ mux_master_process_new_session(struct ssh *ssh, u_int rid, free(cp); continue; } - cctx->env = xreallocarray(cctx->env, env_len + 2, - sizeof(*cctx->env)); + cctx->env = zrealloc(cctx->env, typeof(*cctx->env), env_len + 2); cctx->env[env_len++] = cp; cctx->env[env_len] = NULL; if (env_len > MUX_MAX_ENV_VARS) { diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index fd6729c4c4d6..7c4d58e91090 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c @@ -827,7 +827,7 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, return(GLOB_NOSPACE); } - pathv = reallocarray(pglob->gl_pathv, newn, sizeof(*pathv)); + pathv = zrealloc(pglob->gl_pathv, typeof(*pathv), newn); if (pathv == NULL) goto nospace; if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { @@ -839,7 +839,7 @@ globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, pglob->gl_pathv = pathv; if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0) { - statv = reallocarray(pglob->gl_statv, newn, sizeof(*statv)); + statv = zrealloc(pglob->gl_statv, typeof(*statv), newn); if (statv == NULL) goto nospace; if (pglob->gl_statv == NULL && pglob->gl_offs > 0) { diff --git a/readconf.c b/readconf.c index be65a74fb4c5..722b333f8950 100644 --- a/readconf.c +++ b/readconf.c @@ -385,9 +385,7 @@ add_local_forward(Options *options, const struct Forward *newfwd) if (forward_equals(newfwd, options->local_forwards + i)) return; } - options->local_forwards = xreallocarray(options->local_forwards, - options->num_local_forwards + 1, - sizeof(*options->local_forwards)); + options->local_forwards = zrealloc(options->local_forwards, typeof(*options->local_forwards), options->num_local_forwards + 1); fwd = &options->local_forwards[options->num_local_forwards++]; fwd->listen_host = newfwd->listen_host; @@ -414,9 +412,7 @@ add_remote_forward(Options *options, const struct Forward *newfwd) if (forward_equals(newfwd, options->remote_forwards + i)) return; } - options->remote_forwards = xreallocarray(options->remote_forwards, - options->num_remote_forwards + 1, - sizeof(*options->remote_forwards)); + options->remote_forwards = zrealloc(options->remote_forwards, typeof(*options->remote_forwards), options->num_remote_forwards + 1); fwd = &options->remote_forwards[options->num_remote_forwards++]; fwd->listen_host = newfwd->listen_host; diff --git a/scp.c b/scp.c index 62a73a3c3ae5..52a4d5b35df3 100644 --- a/scp.c +++ b/scp.c @@ -766,7 +766,7 @@ append(char *cp, char ***ap, size_t *np) { char **tmp; - if ((tmp = reallocarray(*ap, *np + 1, sizeof(*tmp))) == NULL) + if ((tmp = zrealloc(*ap, typeof(*tmp), *np + 1)) == NULL) return -1; tmp[(*np)] = cp; (*np)++;