Skip to content

Commit

Permalink
more shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Pizlo committed Feb 22, 2024
1 parent ff905a2 commit 31b5324
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
#endif

*ccp = NULL;
if ((cc = calloc(sizeof(*cc), 1)) == NULL)
if ((cc = zalloc(typeof(*cc), 1)) == NULL)
return SSH_ERR_ALLOC_FAIL;

cc->plaintext = (cipher->flags & CFLAG_NONE) != 0;
Expand Down
13 changes: 9 additions & 4 deletions fixalloc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
# | match |
# "zalloc(typeof(*#{$2}), #{$1})"
#}
contents.gsub!(/calloc\(([^\n]+), sizeof\(\*([a-zA-Z0-9_]+)\)\)/) {
| match |
"zalloc(typeof(*#{$2}), #{$1})"
}
#contents.gsub!(/calloc\(([^\n]+), sizeof\(\*([a-zA-Z0-9_]+)\)\)/) {
# | match |
# "zalloc(typeof(*#{$2}), #{$1})"
#}
#contents.gsub!(/calloc\(sizeof\(\*([a-zA-Z0-9_]+)\), ([^\n]+)\)/) {
# | match |
# "zalloc(typeof(*#{$1}), #{$2})"
#}
contents.gsub!(/xzalloc/) { | match | "zalloc" }
IO::write(filename, contents)
}
2 changes: 1 addition & 1 deletion misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2774,7 +2774,7 @@ subprocess(const char *tag, const char *command,
/* Prepare a minimal environment for the child. */
if ((flags & SSH_SUBPROCESS_PRESERVE_ENV) == 0) {
nenv = 5;
env = xcalloc(sizeof(*env), nenv);
env = zalloc(typeof(*env), nenv);
child_set_env(&env, &nenv, "PATH", _PATH_STDPATH);
child_set_env(&env, &nenv, "USER", pw->pw_name);
child_set_env(&env, &nenv, "LOGNAME", pw->pw_name);
Expand Down
4 changes: 2 additions & 2 deletions monitor_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ mm_getpwnamallow(struct ssh *ssh, const char *username)
}

/* XXX don't like passing struct passwd like this */
pw = xcalloc(sizeof(*pw), 1);
pw = zalloc(typeof(*pw), 1);
GETPW(m, pw_uid);
GETPW(m, pw_gid);
#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
Expand All @@ -311,7 +311,7 @@ mm_getpwnamallow(struct ssh *ssh, const char *username)
fatal_fr(r, "parse opts");
if (len != sizeof(*newopts))
fatal_f("option block size mismatch");
newopts = xcalloc(sizeof(*newopts), 1);
newopts = zalloc(typeof(*newopts), 1);
memcpy(newopts, p, sizeof(*newopts));

#define M_CP_STROPT(x) do { \
Expand Down
2 changes: 1 addition & 1 deletion regress/unittests/test_helper/fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ siginfo(int unused __attribute__((__unused__)))
struct fuzz *
fuzz_begin(u_int strategies, const void *p, size_t l)
{
struct fuzz *ret = calloc(sizeof(*ret), 1);
struct fuzz *ret = zalloc(typeof(*ret), 1);

assert(p != NULL);
assert(ret != NULL);
Expand Down
4 changes: 2 additions & 2 deletions sshbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ sshbuf_new(void)
{
struct sshbuf *ret;

if ((ret = calloc(sizeof(*ret), 1)) == NULL)
if ((ret = zalloc(typeof(*ret), 1)) == NULL)
return NULL;
ret->alloc = SSHBUF_SIZE_INIT;
ret->max_size = SSHBUF_SIZE_MAX;
Expand All @@ -113,7 +113,7 @@ sshbuf_from(const void *blob, size_t len)
struct sshbuf *ret;

if (blob == NULL || len > SSHBUF_SIZE_MAX ||
(ret = calloc(sizeof(*ret), 1)) == NULL)
(ret = zalloc(typeof(*ret), 1)) == NULL)
return NULL;
ret->alloc = ret->size = ret->max_size = len;
ret->readonly = 1;
Expand Down

0 comments on commit 31b5324

Please sign in to comment.