From 1c6c36c44f6e295ba26813d1e633f3972d96f7fb Mon Sep 17 00:00:00 2001 From: Filip Pizlo Date: Thu, 29 Feb 2024 17:44:17 -0800 Subject: [PATCH] more shit --- auth2.c | 3 +-- fixalloc.rb | 12 ++++++++++-- servconf.c | 35 ++++++++--------------------------- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/auth2.c b/auth2.c index 20554b461a50..d5f79d5547d8 100644 --- a/auth2.c +++ b/auth2.c @@ -625,8 +625,7 @@ auth2_setup_methods_lists(Authctxt *authctxt) if (options.num_auth_methods == 0) return 0; debug3_f("checking methods"); - authctxt->auth_methods = xcalloc(options.num_auth_methods, - sizeof(*authctxt->auth_methods)); + authctxt->auth_methods = zalloc(typeof(*authctxt->auth_methods), options.num_auth_methods); authctxt->num_auth_methods = 0; for (i = 0; i < options.num_auth_methods; i++) { if (auth2_methods_valid(options.auth_methods[i], 1) != 0) { diff --git a/fixalloc.rb b/fixalloc.rb index c1c0c53830fd..e7fe57b1230d 100755 --- a/fixalloc.rb +++ b/fixalloc.rb @@ -65,9 +65,17 @@ # | match | # "zalloc(typeof(*#{$2}), #{$1})" #} - contents.gsub!(/xreallocarray\(([^\n]+),\s+([^\n]+),\s+sizeof\(([a-zA-Z0-9_*]+)\)\)/) { + #contents.gsub!(/xreallocarray\(([^\n]+),\s+([^\n]+),\s+sizeof\(([a-zA-Z0-9_*]+)\)\)/) { + # | match | + # "zrealloc(#{$1}, typeof(#{$3}), #{$2})" + #} + #contents.gsub!(/xrecallocarray\(\s*([^\n]+),\s+([^\n]+),\s+([^\n]+),\s+sizeof\(([a-zA-Z0-9_*>-]+)\)\)/) { + # | match | + # "zrealloc(zrestrict(#{$1}, typeof(#{$4}), #{$2}), typeof(#{$4}), #{$3})" + #} + contents.gsub!(/xcalloc\(\s*([^\n]+),\s+sizeof\(([a-zA-Z0-9_*>-]+)\)\)/) { | match | - "zrealloc(#{$1}, typeof(#{$3}), #{$2})" + "zalloc(typeof(#{$2}), #{$1})" } IO::write(filename, contents) } diff --git a/servconf.c b/servconf.c index ccee3c3947df..c25b92c9c99c 100644 --- a/servconf.c +++ b/servconf.c @@ -865,10 +865,7 @@ queue_listen_addr(ServerOptions *options, const char *addr, { struct queued_listenaddr *qla; - options->queued_listen_addrs = xrecallocarray( - options->queued_listen_addrs, - options->num_queued_listens, options->num_queued_listens + 1, - sizeof(*options->queued_listen_addrs)); + options->queued_listen_addrs = zrealloc(zrestrict(options->queued_listen_addrs, typeof(*options->queued_listen_addrs), options->num_queued_listens), typeof(*options->queued_listen_addrs), options->num_queued_listens + 1); qla = &options->queued_listen_addrs[options->num_queued_listens++]; qla->addr = xstrdup(addr); qla->port = port; @@ -1919,18 +1916,9 @@ process_server_config_line_depth(ServerOptions *options, char *line, argv_consume(&ac); break; } - options->subsystem_name = xrecallocarray( - options->subsystem_name, options->num_subsystems, - options->num_subsystems + 1, - sizeof(*options->subsystem_name)); - options->subsystem_command = xrecallocarray( - options->subsystem_command, options->num_subsystems, - options->num_subsystems + 1, - sizeof(*options->subsystem_command)); - options->subsystem_args = xrecallocarray( - options->subsystem_args, options->num_subsystems, - options->num_subsystems + 1, - sizeof(*options->subsystem_args)); + options->subsystem_name = zrealloc(zrestrict(options->subsystem_name, typeof(*options->subsystem_name), options->num_subsystems), typeof(*options->subsystem_name), options->num_subsystems + 1); + options->subsystem_command = zrealloc(zrestrict(options->subsystem_command, typeof(*options->subsystem_command), options->num_subsystems), typeof(*options->subsystem_command), options->num_subsystems + 1); + options->subsystem_args = zrealloc(zrestrict(options->subsystem_args, typeof(*options->subsystem_args), options->num_subsystems), typeof(*options->subsystem_args), options->num_subsystems + 1); options->subsystem_name[options->num_subsystems] = xstrdup(arg); arg = argv_next(&ac, &av); if (!arg || *arg == '\0') { @@ -2259,8 +2247,7 @@ process_server_config_line_depth(ServerOptions *options, char *line, if (strcmp(arg, "any") == 0 || strcmp(arg, "none") == 0) { if (*activep && uvalue == 0) { *uintptr = 1; - *chararrayptr = xcalloc(1, - sizeof(**chararrayptr)); + *chararrayptr = zalloc(typeof(**chararrayptr), 1); (*chararrayptr)[0] = xstrdup(arg); } break; @@ -2685,15 +2672,9 @@ servconf_merge_subsystems(ServerOptions *dst, ServerOptions *src) continue; } debug_f("add \"%s\"", src->subsystem_name[i]); - dst->subsystem_name = xrecallocarray( - dst->subsystem_name, dst->num_subsystems, - dst->num_subsystems + 1, sizeof(*dst->subsystem_name)); - dst->subsystem_command = xrecallocarray( - dst->subsystem_command, dst->num_subsystems, - dst->num_subsystems + 1, sizeof(*dst->subsystem_command)); - dst->subsystem_args = xrecallocarray( - dst->subsystem_args, dst->num_subsystems, - dst->num_subsystems + 1, sizeof(*dst->subsystem_args)); + dst->subsystem_name = zrealloc(zrestrict(dst->subsystem_name, typeof(*dst->subsystem_name), dst->num_subsystems), typeof(*dst->subsystem_name), dst->num_subsystems + 1); + dst->subsystem_command = zrealloc(zrestrict(dst->subsystem_command, typeof(*dst->subsystem_command), dst->num_subsystems), typeof(*dst->subsystem_command), dst->num_subsystems + 1); + dst->subsystem_args = zrealloc(zrestrict(dst->subsystem_args, typeof(*dst->subsystem_args), dst->num_subsystems), typeof(*dst->subsystem_args), dst->num_subsystems + 1); j = dst->num_subsystems++; dst->subsystem_name[j] = xstrdup(src->subsystem_name[i]); dst->subsystem_command[j] = xstrdup(src->subsystem_command[i]);