Skip to content

Commit

Permalink
convert more allocation calls to stdfil API; as usual, the regex I us…
Browse files Browse the repository at this point in the history
…ed is included in fixalloc.rb for posterity.
  • Loading branch information
Filip Pizlo committed Mar 2, 2024
1 parent 9e5aa03 commit aa9f986
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
14 changes: 9 additions & 5 deletions fixalloc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand All @@ -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)
}
3 changes: 1 addition & 2 deletions mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions openbsd-compat/glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions readconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion scp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)++;
Expand Down

0 comments on commit aa9f986

Please sign in to comment.