malloc functions, which automatically cast to the same type they're
allocating the size of. Should prevent any future errors involving
mallocing the size of the wrong structure type, and will also make
life easier if we ever need to turn the PuTTY core code from real C
into C++-friendly C. I haven't touched the Mac frontend in this
checkin because I couldn't compile or test it.
[originally from svn r3014]
60 files changed:
{
if (saves[pri].nsaved >= saves[pri].savesize) {
saves[pri].savesize = saves[pri].nsaved + 32;
{
if (saves[pri].nsaved >= saves[pri].savesize) {
saves[pri].savesize = saves[pri].nsaved + 32;
- saves[pri].params =
- srealloc(saves[pri].params,
- saves[pri].savesize*sizeof(*saves[pri].params));
+ saves[pri].params = sresize(saves[pri].params, saves[pri].savesize,
+ struct cmdline_saved_param);
}
saves[pri].params[saves[pri].nsaved].p = p;
saves[pri].params[saves[pri].nsaved].value = value;
}
saves[pri].params[saves[pri].nsaved].p = p;
saves[pri].params[saves[pri].nsaved].value = value;
d = 0;
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
d = 0;
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
- command = srealloc(command, cmdsize);
+ command = sresize(command, cmdsize, char);
}
command[cmdlen++] = d;
} while (c != EOF);
}
command[cmdlen++] = d;
} while (c != EOF);
charclass_handler, P(ccd));
ccd->listbox->listbox.multisel = 1;
ccd->listbox->listbox.ncols = 4;
charclass_handler, P(ccd));
ccd->listbox->listbox.multisel = 1;
ccd->listbox->listbox.ncols = 4;
- ccd->listbox->listbox.percentages = smalloc(4*sizeof(int));
+ ccd->listbox->listbox.percentages = snewn(4, int);
ccd->listbox->listbox.percentages[0] = 15;
ccd->listbox->listbox.percentages[1] = 25;
ccd->listbox->listbox.percentages[2] = 20;
ccd->listbox->listbox.percentages[0] = 15;
ccd->listbox->listbox.percentages[1] = 25;
ccd->listbox->listbox.percentages[2] = 20;
environ_handler, P(ed));
ed->listbox->listbox.height = 3;
ed->listbox->listbox.ncols = 2;
environ_handler, P(ed));
ed->listbox->listbox.height = 3;
ed->listbox->listbox.ncols = 2;
- ed->listbox->listbox.percentages = smalloc(2*sizeof(int));
+ ed->listbox->listbox.percentages = snewn(2, int);
ed->listbox->listbox.percentages[0] = 30;
ed->listbox->listbox.percentages[1] = 70;
}
ed->listbox->listbox.percentages[0] = 30;
ed->listbox->listbox.percentages[1] = 70;
}
portfwd_handler, P(pfd));
pfd->listbox->listbox.height = 3;
pfd->listbox->listbox.ncols = 2;
portfwd_handler, P(pfd));
pfd->listbox->listbox.height = 3;
pfd->listbox->listbox.ncols = 2;
- pfd->listbox->listbox.percentages = smalloc(2*sizeof(int));
+ pfd->listbox->listbox.percentages = snewn(2, int);
pfd->listbox->listbox.percentages[0] = 20;
pfd->listbox->listbox.percentages[1] = 80;
ctrl_tabdelay(s, pfd->rembutton);
pfd->listbox->listbox.percentages[0] = 20;
pfd->listbox->listbox.percentages[1] = 80;
ctrl_tabdelay(s, pfd->rembutton);
struct controlbox *ctrl_new_box(void)
{
struct controlbox *ctrl_new_box(void)
{
- struct controlbox *ret = smalloc(sizeof(struct controlbox));
+ struct controlbox *ret = snew(struct controlbox);
ret->nctrlsets = ret->ctrlsetsize = 0;
ret->ctrlsets = NULL;
ret->nctrlsets = ret->ctrlsetsize = 0;
ret->ctrlsets = NULL;
char *path, char *title)
{
char *path, char *title)
{
- struct controlset *s = smalloc(sizeof(struct controlset));
+ struct controlset *s = snew(struct controlset);
int index = ctrl_find_set(b, path, 1);
s->pathname = dupstr(path);
s->boxname = NULL;
int index = ctrl_find_set(b, path, 1);
s->pathname = dupstr(path);
s->boxname = NULL;
s->ctrls = NULL;
if (b->nctrlsets >= b->ctrlsetsize) {
b->ctrlsetsize = b->nctrlsets + 32;
s->ctrls = NULL;
if (b->nctrlsets >= b->ctrlsetsize) {
b->ctrlsetsize = b->nctrlsets + 32;
- b->ctrlsets = srealloc(b->ctrlsets,
- b->ctrlsetsize*sizeof(*b->ctrlsets));
+ b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
}
if (index < b->nctrlsets)
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
}
if (index < b->nctrlsets)
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
return b->ctrlsets[index];
index++;
}
return b->ctrlsets[index];
index++;
}
- s = smalloc(sizeof(struct controlset));
+ s = snew(struct controlset);
s->pathname = dupstr(path);
s->boxname = dupstr(name);
s->boxtitle = boxtitle ? dupstr(boxtitle) : NULL;
s->pathname = dupstr(path);
s->boxname = dupstr(name);
s->boxtitle = boxtitle ? dupstr(boxtitle) : NULL;
s->ctrls = NULL;
if (b->nctrlsets >= b->ctrlsetsize) {
b->ctrlsetsize = b->nctrlsets + 32;
s->ctrls = NULL;
if (b->nctrlsets >= b->ctrlsetsize) {
b->ctrlsetsize = b->nctrlsets + 32;
- b->ctrlsets = srealloc(b->ctrlsets,
- b->ctrlsetsize*sizeof(*b->ctrlsets));
+ b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
}
if (index < b->nctrlsets)
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
}
if (index < b->nctrlsets)
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
void *ctrl_alloc(struct controlbox *b, size_t size)
{
void *p;
void *ctrl_alloc(struct controlbox *b, size_t size)
{
void *p;
+ /*
+ * This is an internal allocation routine, so it's allowed to
+ * use smalloc directly.
+ */
p = smalloc(size);
if (b->nfrees >= b->freesize) {
b->freesize = b->nfrees + 32;
p = smalloc(size);
if (b->nfrees >= b->freesize) {
b->freesize = b->nfrees + 32;
- b->frees = srealloc(b->frees, b->freesize*sizeof(*b->frees));
+ b->frees = sresize(b->frees, b->freesize, void *);
}
b->frees[b->nfrees++] = p;
return p;
}
b->frees[b->nfrees++] = p;
return p;
intorptr helpctx, handler_fn handler,
intorptr context)
{
intorptr helpctx, handler_fn handler,
intorptr context)
{
- union control *c = smalloc(sizeof(union control));
+ union control *c = snew(union control);
if (s->ncontrols >= s->ctrlsize) {
s->ctrlsize = s->ncontrols + 32;
if (s->ncontrols >= s->ctrlsize) {
s->ctrlsize = s->ncontrols + 32;
- s->ctrls = srealloc(s->ctrls, s->ctrlsize * sizeof(*s->ctrls));
+ s->ctrls = sresize(s->ctrls, s->ctrlsize, union control *);
}
s->ctrls[s->ncontrols++] = c;
/*
}
s->ctrls[s->ncontrols++] = c;
/*
} else {
va_list ap;
int i;
} else {
va_list ap;
int i;
- c->columns.percentages = smalloc(ncolumns * sizeof(int));
+ c->columns.percentages = snewn(ncolumns, int);
va_start(ap, ncolumns);
for (i = 0; i < ncolumns; i++)
c->columns.percentages[i] = va_arg(ap, int);
va_start(ap, ncolumns);
for (i = 0; i < ncolumns; i++)
c->columns.percentages[i] = va_arg(ap, int);
va_end(ap);
c->radio.nbuttons = i;
if (c->radio.shortcut == NO_SHORTCUT)
va_end(ap);
c->radio.nbuttons = i;
if (c->radio.shortcut == NO_SHORTCUT)
- c->radio.shortcuts = smalloc(c->radio.nbuttons * sizeof(char));
+ c->radio.shortcuts = snewn(c->radio.nbuttons, char);
else
c->radio.shortcuts = NULL;
else
c->radio.shortcuts = NULL;
- c->radio.buttons = smalloc(c->radio.nbuttons * sizeof(char *));
- c->radio.buttondata = smalloc(c->radio.nbuttons * sizeof(intorptr));
+ c->radio.buttons = snewn(c->radio.nbuttons, char *);
+ c->radio.buttondata = snewn(c->radio.nbuttons, intorptr);
/*
* Second pass along variable argument list to actually fill in
* the structure.
/*
* Second pass along variable argument list to actually fill in
* the structure.
char base64_bit[4];
int base64_chars = 0;
char base64_bit[4];
int base64_chars = 0;
- ret = smalloc(sizeof(*ret));
+ ret = snew(struct openssh_key);
ret->keyblob = NULL;
ret->keyblob_len = ret->keyblob_size = 0;
ret->encrypted = 0;
ret->keyblob = NULL;
ret->keyblob_len = ret->keyblob_size = 0;
ret->encrypted = 0;
if (ret->keyblob_len + len > ret->keyblob_size) {
ret->keyblob_size = ret->keyblob_len + len + 256;
if (ret->keyblob_len + len > ret->keyblob_size) {
ret->keyblob_size = ret->keyblob_len + len + 256;
- ret->keyblob = srealloc(ret->keyblob, ret->keyblob_size);
+ ret->keyblob = sresize(ret->keyblob, ret->keyblob_size,
+ unsigned char);
}
memcpy(ret->keyblob + ret->keyblob_len, out, len);
}
memcpy(ret->keyblob + ret->keyblob_len, out, len);
* Space to create key blob in.
*/
blobsize = 256+key->keyblob_len;
* Space to create key blob in.
*/
blobsize = 256+key->keyblob_len;
- blob = smalloc(blobsize);
+ blob = snewn(blobsize, unsigned char);
PUT_32BIT(blob, 7);
if (key->type == OSSH_DSA)
memcpy(blob+4, "ssh-dss", 7);
PUT_32BIT(blob, 7);
if (key->type == OSSH_DSA)
memcpy(blob+4, "ssh-dss", 7);
* the sanity checks for free.
*/
assert(privptr > 0); /* should have bombed by now if not */
* the sanity checks for free.
*/
assert(privptr > 0); /* should have bombed by now if not */
- retkey = smalloc(sizeof(struct ssh2_userkey));
+ retkey = snew(struct ssh2_userkey);
retkey->alg = (key->type == OSSH_RSA ? &ssh_rsa : &ssh_dss);
retkey->data = retkey->alg->createkey(blob, privptr,
blob+privptr, blobptr-privptr);
retkey->alg = (key->type == OSSH_RSA ? &ssh_rsa : &ssh_dss);
retkey->data = retkey->alg->createkey(blob, privptr,
blob+privptr, blobptr-privptr);
dmp1.bytes = (bignum_bitcount(bdmp1)+8)/8;
dmq1.bytes = (bignum_bitcount(bdmq1)+8)/8;
sparelen = dmp1.bytes + dmq1.bytes;
dmp1.bytes = (bignum_bitcount(bdmp1)+8)/8;
dmq1.bytes = (bignum_bitcount(bdmq1)+8)/8;
sparelen = dmp1.bytes + dmq1.bytes;
- spareblob = smalloc(sparelen);
+ spareblob = snewn(sparelen, unsigned char);
dmp1.start = spareblob;
dmq1.start = spareblob + dmp1.bytes;
for (i = 0; i < dmp1.bytes; i++)
dmp1.start = spareblob;
dmq1.start = spareblob + dmp1.bytes;
for (i = 0; i < dmp1.bytes; i++)
/*
* Now we know how big outblob needs to be. Allocate it.
*/
/*
* Now we know how big outblob needs to be. Allocate it.
*/
- outblob = smalloc(outlen);
+ outblob = snewn(outlen, unsigned char);
/*
* And write the data into it.
/*
* And write the data into it.
char base64_bit[4];
int base64_chars = 0;
char base64_bit[4];
int base64_chars = 0;
- ret = smalloc(sizeof(*ret));
+ ret = snew(struct sshcom_key);
ret->comment[0] = '\0';
ret->keyblob = NULL;
ret->keyblob_len = ret->keyblob_size = 0;
ret->comment[0] = '\0';
ret->keyblob = NULL;
ret->keyblob_len = ret->keyblob_size = 0;
if (ret->keyblob_len + len > ret->keyblob_size) {
ret->keyblob_size = ret->keyblob_len + len + 256;
if (ret->keyblob_len + len > ret->keyblob_size) {
ret->keyblob_size = ret->keyblob_len + len + 256;
- ret->keyblob = srealloc(ret->keyblob, ret->keyblob_size);
+ ret->keyblob = sresize(ret->keyblob, ret->keyblob_size,
+ unsigned char);
}
memcpy(ret->keyblob + ret->keyblob_len, out, len);
}
memcpy(ret->keyblob + ret->keyblob_len, out, len);
* end up feeding them to alg->createkey().
*/
blobsize = cipherlen + 256;
* end up feeding them to alg->createkey().
*/
blobsize = cipherlen + 256;
- blob = smalloc(blobsize);
+ blob = snewn(blobsize, unsigned char);
privlen = 0;
if (type == RSA) {
struct mpint_pos n, e, d, u, p, q;
privlen = 0;
if (type == RSA) {
struct mpint_pos n, e, d, u, p, q;
assert(privlen > 0); /* should have bombed by now if not */
assert(privlen > 0); /* should have bombed by now if not */
- retkey = smalloc(sizeof(struct ssh2_userkey));
+ retkey = snew(struct ssh2_userkey);
retkey->alg = alg;
retkey->data = alg->createkey(blob, publen, blob+publen, privlen);
if (!retkey->data) {
retkey->alg = alg;
retkey->data = alg->createkey(blob, publen, blob+publen, privlen);
if (!retkey->data) {
outlen = 512;
for (i = 0; i < nnumbers; i++)
outlen += 4 + numbers[i].bytes;
outlen = 512;
for (i = 0; i < nnumbers; i++)
outlen += 4 + numbers[i].bytes;
- outblob = smalloc(outlen);
+ outblob = snewn(outlen, unsigned char);
/*
* Create the unencrypted key blob.
/*
* Create the unencrypted key blob.
Backend *back, void *backhandle,
void *frontend)
{
Backend *back, void *backhandle,
void *frontend)
{
- Ldisc ldisc = smalloc(sizeof(*ldisc));
+ Ldisc ldisc = snew(struct ldisc_tag);
ldisc->buf = NULL;
ldisc->buflen = 0;
ldisc->buf = NULL;
ldisc->buflen = 0;
default_case:
if (ldisc->buflen >= ldisc->bufsiz) {
ldisc->bufsiz = ldisc->buflen + 256;
default_case:
if (ldisc->buflen >= ldisc->bufsiz) {
ldisc->bufsiz = ldisc->buflen + 256;
- ldisc->buf = srealloc(ldisc->buf, ldisc->bufsiz);
+ ldisc->buf = sresize(ldisc->buf, ldisc->bufsiz, char);
}
ldisc->buf[ldisc->buflen++] = c;
if (ECHOING)
}
ldisc->buf[ldisc->buflen++] = c;
if (ECHOING)
- widebuffer = smalloc(widesize * sizeof(wchar_t));
+ widebuffer = snewn(widesize, wchar_t);
wclen = mb_to_wc(codepage, 0, buf, len, widebuffer, widesize);
luni_send(ldisc, widebuffer, wclen, interactive);
wclen = mb_to_wc(codepage, 0, buf, len, widebuffer, widesize);
luni_send(ldisc, widebuffer, wclen, interactive);
char *p;
linesize = len * ratio * 2;
char *p;
linesize = len * ratio * 2;
- linebuffer = smalloc(linesize * sizeof(wchar_t));
+ linebuffer = snewn(linesize, char);
if (in_utf(ldisc->term)) {
/* UTF is a simple algorithm */
if (in_utf(ldisc->term)) {
/* UTF is a simple algorithm */
void *log_init(void *frontend, Config *cfg)
{
void *log_init(void *frontend, Config *cfg)
{
- struct LogContext *ctx = smalloc(sizeof(struct LogContext));
+ struct LogContext *ctx = snew(struct LogContext);
ctx->lgfp = NULL;
ctx->frontend = frontend;
ctx->cfg = *cfg; /* STRUCTURE COPY */
ctx->lgfp = NULL;
ctx->frontend = frontend;
ctx->cfg = *cfg; /* STRUCTURE COPY */
char *dupstr(const char *s)
{
int len = strlen(s);
char *dupstr(const char *s)
{
int len = strlen(s);
- char *p = smalloc(len + 1);
+ char *p = snewn(len + 1, char);
strcpy(p, s);
return p;
}
strcpy(p, s);
return p;
}
+ p = snewn(len + 1, char);
strcpy(p, s1);
q = p + strlen(p);
strcpy(p, s1);
q = p + strlen(p);
char *buf;
int len, size;
char *buf;
int len, size;
+ buf = snewn(512, char);
* buffer wasn't big enough, so we enlarge it a bit and hope. */
size += 512;
}
* buffer wasn't big enough, so we enlarge it a bit and hope. */
size += 512;
}
- buf = srealloc(buf, size);
+ buf = sresize(buf, size, char);
while (len > 0) {
int grainlen = min(len, BUFFER_GRANULE);
struct bufchain_granule *newbuf;
while (len > 0) {
int grainlen = min(len, BUFFER_GRANULE);
struct bufchain_granule *newbuf;
- newbuf = smalloc(sizeof(struct bufchain_granule));
+ newbuf = snew(struct bufchain_granule);
newbuf->bufpos = 0;
newbuf->buflen = grainlen;
memcpy(newbuf->buf, buf, grainlen);
newbuf->bufpos = 0;
newbuf->buflen = grainlen;
memcpy(newbuf->buf, buf, grainlen);
return;
}
/* For our purposes we want the blob prefixed with its length */
return;
}
/* For our purposes we want the blob prefixed with its length */
- blob2 = smalloc(bloblen+4);
+ blob2 = snewn(bloblen+4, unsigned char);
PUT_32BIT(blob2, bloblen);
memcpy(blob2 + 4, blob, bloblen);
sfree(blob);
PUT_32BIT(blob2, bloblen);
memcpy(blob2 + 4, blob, bloblen);
sfree(blob);
needs_pass = ssh2_userkey_encrypted(&filename, &comment);
attempts = 0;
if (type == SSH_KEYTYPE_SSH1)
needs_pass = ssh2_userkey_encrypted(&filename, &comment);
attempts = 0;
if (type == SSH_KEYTYPE_SSH1)
- rkey = smalloc(sizeof(*rkey));
+ rkey = snew(struct RSAKey);
pps.passphrase = passphrase;
pps.comment = comment;
original_pass = 0;
pps.passphrase = passphrase;
pps.comment = comment;
original_pass = 0;
ssh1_bignum_length(rkey->q) + 4 + clen /* comment */
;
ssh1_bignum_length(rkey->q) + 4 + clen /* comment */
;
- request = smalloc(reqlen);
+ request = snewn(reqlen, unsigned char);
request[4] = SSH1_AGENTC_ADD_RSA_IDENTITY;
reqlen = 5;
request[4] = SSH1_AGENTC_ADD_RSA_IDENTITY;
reqlen = 5;
- request = smalloc(reqlen);
+ request = snewn(reqlen, unsigned char);
request[4] = SSH2_AGENTC_ADD_IDENTITY;
reqlen = 5;
request[4] = SSH2_AGENTC_ADD_IDENTITY;
reqlen = 5;
}
/* Allocate the buffer. */
}
/* Allocate the buffer. */
- p = ret = smalloc(len);
+ p = ret = snewn(len, unsigned char);
if (length) *length = len;
PUT_32BIT(p, nkeys);
if (length) *length = len;
PUT_32BIT(p, nkeys);
}
/* Allocate the buffer. */
}
/* Allocate the buffer. */
- p = ret = smalloc(len);
+ p = ret = snewn(len, unsigned char);
if (length) *length = len;
/*
if (length) *length = len;
/*
if (resplen < 5 || response[4] != SSH1_AGENT_RSA_IDENTITIES_ANSWER)
return NULL;
if (resplen < 5 || response[4] != SSH1_AGENT_RSA_IDENTITIES_ANSWER)
return NULL;
- ret = smalloc(resplen-5);
+ ret = snewn(resplen-5, unsigned char);
memcpy(ret, response+5, resplen-5);
sfree(response);
} else {
memcpy(ret, response+5, resplen-5);
sfree(response);
} else {
if (resplen < 5 || response[4] != SSH2_AGENT_IDENTITIES_ANSWER)
return NULL;
if (resplen < 5 || response[4] != SSH2_AGENT_IDENTITIES_ANSWER)
return NULL;
- ret = smalloc(resplen-5);
+ ret = snewn(resplen-5, unsigned char);
memcpy(ret, response+5, resplen-5);
sfree(response);
} else {
memcpy(ret, response+5, resplen-5);
sfree(response);
} else {
struct RSAKey *key;
char *comment;
int commentlen;
struct RSAKey *key;
char *comment;
int commentlen;
- key = smalloc(sizeof(struct RSAKey));
+ key = snew(struct RSAKey);
memset(key, 0, sizeof(struct RSAKey));
p += makekey(p, key, NULL, 1);
p += makeprivate(p, key);
memset(key, 0, sizeof(struct RSAKey));
p += makekey(p, key, NULL, 1);
p += makeprivate(p, key);
p += ssh1_read_bignum(p, &key->p); /* p */
p += ssh1_read_bignum(p, &key->q); /* q */
commentlen = GET_32BIT(p);
p += ssh1_read_bignum(p, &key->p); /* p */
p += ssh1_read_bignum(p, &key->q); /* q */
commentlen = GET_32BIT(p);
- comment = smalloc(commentlen+1);
+ comment = snewn(commentlen+1, char);
if (comment) {
memcpy(comment, p + 4, commentlen);
comment[commentlen] = '\0';
if (comment) {
memcpy(comment, p + 4, commentlen);
comment[commentlen] = '\0';
int alglen, commlen;
int bloblen;
int alglen, commlen;
int bloblen;
- key = smalloc(sizeof(struct ssh2_userkey));
+ key = snew(struct ssh2_userkey);
alglen = GET_32BIT(p);
p += 4;
alglen = GET_32BIT(p);
p += 4;
commlen = GET_32BIT(p);
p += 4;
commlen = GET_32BIT(p);
p += 4;
- comment = smalloc(commlen + 1);
+ comment = snewn(commlen + 1, char);
if (comment) {
memcpy(comment, p, commlen);
comment[commlen] = '\0';
if (comment) {
memcpy(comment, p, commlen);
comment[commlen] = '\0';
{
OPENFILENAME of;
char filename[FILENAME_MAX];
{
OPENFILENAME of;
char filename[FILENAME_MAX];
- char *filelist = smalloc(8192);
+ char *filelist = snewn(8192, char);
char *filewalker;
int n, dirlen;
char *filewalker;
int n, dirlen;
}
/* get item indices in an array */
}
/* get item indices in an array */
- selectedArray = smalloc(numSelected * sizeof(int));
+ selectedArray = snewn(numSelected, int);
SendDlgItemMessage(hwnd, 100, LB_GETSELITEMS,
numSelected, (WPARAM)selectedArray);
SendDlgItemMessage(hwnd, 100, LB_GETSELITEMS,
numSelected, (WPARAM)selectedArray);
if (id > 0) {
retlen = 4 + GET_32BIT(p);
debug(("len is %d\n", retlen));
if (id > 0) {
retlen = 4 + GET_32BIT(p);
debug(("len is %d\n", retlen));
+ ret = snewn(retlen, unsigned char);
if (ret) {
memcpy(ret, p, retlen);
*out = ret;
if (ret) {
memcpy(ret, p, retlen);
*out = ret;
while (*p) {
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
while (*p) {
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
- command = srealloc(command, cmdsize);
+ command = sresize(command, cmdsize, char);
}
command[cmdlen++]=*p++;
}
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
}
command[cmdlen++]=*p++;
}
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
- command = srealloc(command, cmdsize);
+ command = sresize(command, cmdsize, char);
}
command[cmdlen++]=' '; /* always add trailing space */
if (--argc) p = *++argv;
}
command[cmdlen++]=' '; /* always add trailing space */
if (--argc) p = *++argv;
/* Expand the buffer if necessary. */
if (i > sksize) {
sksize = i + 16;
/* Expand the buffer if necessary. */
if (i > sksize) {
sksize = i + 16;
- sklist = srealloc(sklist, sksize * sizeof(*sklist));
+ sklist = sresize(sklist, sksize, SOCKET);
}
/* Retrieve the sockets into sklist. */
}
/* Retrieve the sockets into sklist. */
- pr = (struct PFwdPrivate *) smalloc(sizeof(struct PFwdPrivate));
+ pr = snew(struct PFwdPrivate);
pr->fn = &fn_table;
pr->throttled = pr->throttle_override = 0;
pr->ready = 1;
pr->fn = &fn_table;
pr->throttled = pr->throttle_override = 0;
pr->ready = 1;
char *err;
org = (struct PFwdPrivate *)p;
char *err;
org = (struct PFwdPrivate *)p;
- pr = (struct PFwdPrivate *) smalloc(sizeof(struct PFwdPrivate));
+ pr = snew(struct PFwdPrivate);
pr->fn = &fn_table;
pr->c = NULL;
pr->fn = &fn_table;
pr->c = NULL;
- pr = (struct PFwdPrivate *) smalloc(sizeof(struct PFwdPrivate));
+ pr = snew(struct PFwdPrivate);
pr->fn = &fn_table;
pr->c = NULL;
strcpy(pr->hostname, desthost);
pr->fn = &fn_table;
pr->c = NULL;
strcpy(pr->hostname, desthost);
{
DWORD needed, nprinters;
{
DWORD needed, nprinters;
- buffer = srealloc(buffer, offset+512);
+ buffer = sresize(buffer, offset+512, char);
/*
* Exploratory call to EnumPrinters to determine how much space
/*
* Exploratory call to EnumPrinters to determine how much space
if (needed < 512)
needed = 512;
if (needed < 512)
needed = 512;
- buffer = srealloc(buffer, offset+needed);
+ buffer = sresize(buffer, offset+needed, char);
if (EnumPrinters(param, NULL, ENUM_LEVEL, buffer+offset,
needed, &needed, &nprinters) == 0)
if (EnumPrinters(param, NULL, ENUM_LEVEL, buffer+offset,
needed, &needed, &nprinters) == 0)
printer_enum *printer_start_enum(int *nprinters_ptr)
{
printer_enum *printer_start_enum(int *nprinters_ptr)
{
- printer_enum *ret = smalloc(sizeof(printer_enum));
+ printer_enum *ret = snew(printer_enum);
char *buffer = NULL, *retval;
*nprinters_ptr = 0; /* default return value */
char *buffer = NULL, *retval;
*nprinters_ptr = 0; /* default return value */
+ buffer = snewn(512, char);
retval = printer_add_enum(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
buffer, 0, nprinters_ptr);
retval = printer_add_enum(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
buffer, 0, nprinters_ptr);
printer_job *printer_start_job(char *printer)
{
printer_job *printer_start_job(char *printer)
{
- printer_job *ret = smalloc(sizeof(printer_job));
+ printer_job *ret = snew(printer_job);
DOC_INFO_1 docinfo;
int jobstarted = 0, pagestarted = 0;
DOC_INFO_1 docinfo;
int jobstarted = 0, pagestarted = 0;
SockAddr proxy_addr;
char *proxy_canonical_name, *err;
SockAddr proxy_addr;
char *proxy_canonical_name, *err;
- ret = smalloc(sizeof(struct Socket_proxy_tag));
+ ret = snew(struct Socket_proxy_tag);
ret->fn = &socket_fn_table;
ret->cfg = *cfg; /* STRUCTURE COPY */
ret->plug = plug;
ret->fn = &socket_fn_table;
ret->cfg = *cfg; /* STRUCTURE COPY */
ret->plug = plug;
/* create the proxy plug to map calls from the actual
* socket into our proxy socket layer */
/* create the proxy plug to map calls from the actual
* socket into our proxy socket layer */
- pplug = smalloc(sizeof(struct Plug_proxy_tag));
+ pplug = snew(struct Plug_proxy_tag);
pplug->fn = &plug_fn_table;
pplug->proxy_socket = ret;
pplug->fn = &plug_fn_table;
pplug->proxy_socket = ret;
/* get the status line */
len = bufchain_size(&p->pending_input_data);
assert(len > 0); /* or we wouldn't be here */
/* get the status line */
len = bufchain_size(&p->pending_input_data);
assert(len > 0); /* or we wouldn't be here */
+ data = snewn(len, char);
bufchain_fetch(&p->pending_input_data, data, len);
eol = get_line_end(data, len);
bufchain_fetch(&p->pending_input_data, data, len);
eol = get_line_end(data, len);
len = bufchain_size(&p->pending_input_data);
assert(len > 0); /* or we wouldn't be here */
len = bufchain_size(&p->pending_input_data);
assert(len > 0); /* or we wouldn't be here */
+ data = snewn(len, char);
datap = data;
bufchain_fetch(&p->pending_input_data, data, len);
datap = data;
bufchain_fetch(&p->pending_input_data, data, len);
}
length = strlen(p->cfg.proxy_username) + namelen + 9;
}
length = strlen(p->cfg.proxy_username) + namelen + 9;
- command = (char*) smalloc(length);
+ command = snewn(length, char);
strcpy(command + 8, p->cfg.proxy_username);
command[0] = 4; /* version 4 */
strcpy(command + 8, p->cfg.proxy_username);
command[0] = 4; /* version 4 */
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
- ournames =
- srealloc(ournames, namesize * sizeof(*ournames));
+ ournames = sresize(ournames, namesize, struct fxp_name *);
}
for (i = 0; i < names->nnames; i++)
}
for (i = 0; i < names->nnames; i++)
- currdir = smalloc(256);
+ currdir = snewn(256, char);
len = GetCurrentDirectory(256, currdir);
if (len > 256)
len = GetCurrentDirectory(256, currdir);
if (len > 256)
- currdir = srealloc(currdir, len);
+ currdir = sresize(currdir, len, char);
GetCurrentDirectory(len, currdir);
printf("New local directory is %s\n", currdir);
sfree(currdir);
GetCurrentDirectory(len, currdir);
printf("New local directory is %s\n", currdir);
sfree(currdir);
- currdir = smalloc(256);
+ currdir = snewn(256, char);
len = GetCurrentDirectory(256, currdir);
if (len > 256)
len = GetCurrentDirectory(256, currdir);
if (len > 256)
- currdir = srealloc(currdir, len);
+ currdir = sresize(currdir, len, char);
GetCurrentDirectory(len, currdir);
printf("Current local directory is %s\n", currdir);
sfree(currdir);
GetCurrentDirectory(len, currdir);
printf("Current local directory is %s\n", currdir);
sfree(currdir);
- cmd = smalloc(sizeof(struct sftp_command));
+ cmd = snew(struct sftp_command);
cmd->words = NULL;
cmd->nwords = 0;
cmd->wordssize = 0;
cmd->words = NULL;
cmd->nwords = 0;
cmd->wordssize = 0;
char *ret;
linesize += 512;
char *ret;
linesize += 512;
- line = srealloc(line, linesize);
+ line = sresize(line, linesize, char);
ret = fgets(line + linelen, linesize - linelen, fp);
if (!ret || (linelen == 0 && line[0] == '\0')) {
ret = fgets(line + linelen, linesize - linelen, fp);
if (!ret || (linelen == 0 && line[0] == '\0')) {
* containing everything else on the line.
*/
cmd->nwords = cmd->wordssize = 2;
* containing everything else on the line.
*/
cmd->nwords = cmd->wordssize = 2;
- cmd->words = srealloc(cmd->words, cmd->wordssize * sizeof(char *));
+ cmd->words = sresize(cmd->words, cmd->wordssize, char *);
cmd->words[0] = "!";
cmd->words[1] = p+1;
} else {
cmd->words[0] = "!";
cmd->words[1] = p+1;
} else {
*r = '\0';
if (cmd->nwords >= cmd->wordssize) {
cmd->wordssize = cmd->nwords + 16;
*r = '\0';
if (cmd->nwords >= cmd->wordssize) {
cmd->wordssize = cmd->nwords + 16;
- cmd->words =
- srealloc(cmd->words, cmd->wordssize * sizeof(char *));
+ cmd->words = sresize(cmd->words, cmd->wordssize, char *);
}
cmd->words[cmd->nwords++] = q;
}
}
cmd->words[cmd->nwords++] = q;
}
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
- pending = (pending ? srealloc(pending, pendsize) :
- smalloc(pendsize));
- if (!pending)
- fatalbox("Out of memory");
+ pending = sresize(pending, pendsize, unsigned char);
}
memcpy(pending + pendlen, p, len);
pendlen += len;
}
memcpy(pending + pendlen, p, len);
pendlen += len;
int i;
pub_blob = key->alg->public_blob(key->data, &pub_len);
int i;
pub_blob = key->alg->public_blob(key->data, &pub_len);
- buffer = smalloc(strlen(key->alg->name) + 4 * ((pub_len + 2) / 3) +
- strlen(key->comment) + 3);
+ buffer = snewn(strlen(key->alg->name) + 4 * ((pub_len + 2) / 3) +
+ strlen(key->comment) + 3, char);
strcpy(buffer, key->alg->name);
p = buffer + strlen(buffer);
*p++ = ' ';
strcpy(buffer, key->alg->name);
p = buffer + strlen(buffer);
*p++ = ' ';
SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
(LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(200)));
SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
(LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(200)));
- state = smalloc(sizeof(*state));
+ state = snew(struct MainDlgState);
state->generation_thread_exists = FALSE;
state->collecting_entropy = FALSE;
state->entropy = NULL;
state->generation_thread_exists = FALSE;
state->collecting_entropy = FALSE;
state->entropy = NULL;
MAKELPARAM(0, PROGRESSRANGE));
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
MAKELPARAM(0, PROGRESSRANGE));
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
- params = smalloc(sizeof(*params));
+ params = snew(struct rsa_key_thread_params);
params->progressbar = GetDlgItem(hwnd, IDC_PROGRESS);
params->dialog = hwnd;
params->keysize = state->keysize;
params->progressbar = GetDlgItem(hwnd, IDC_PROGRESS);
params->dialog = hwnd;
params->keysize = state->keysize;
int len = GetWindowTextLength(editctl);
if (*state->commentptr)
sfree(*state->commentptr);
int len = GetWindowTextLength(editctl);
if (*state->commentptr)
sfree(*state->commentptr);
- *state->commentptr = smalloc(len + 1);
+ *state->commentptr = snewn(len + 1, char);
GetWindowText(editctl, *state->commentptr, len + 1);
if (state->ssh2) {
setupbigedit2(hwnd, IDC_KEYDISPLAY, IDC_PKSTATIC,
GetWindowText(editctl, *state->commentptr, len + 1);
if (state->ssh2) {
setupbigedit2(hwnd, IDC_KEYDISPLAY, IDC_PKSTATIC,
state->entropy_required = (state->keysize / 2) * 2;
state->entropy_got = 0;
state->entropy_size = (state->entropy_required *
state->entropy_required = (state->keysize / 2) * 2;
state->entropy_got = 0;
state->entropy_size = (state->entropy_required *
- sizeof(*state->entropy));
- state->entropy = smalloc(state->entropy_size);
+ sizeof(unsigned));
+ state->entropy = snewn(state->entropy_required, unsigned);
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
MAKELPARAM(0, state->entropy_required));
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
MAKELPARAM(0, state->entropy_required));
* the user will immediately want to change it, which is
* what we want :-)
*/
* the user will immediately want to change it, which is
* what we want :-)
*/
- *state->commentptr = smalloc(30);
+ *state->commentptr = snewn(30, char);
{
time_t t;
struct tm *tm;
{
time_t t;
struct tm *tm;
void *saferealloc(void *, size_t);
void safefree(void *);
void *saferealloc(void *, size_t);
void safefree(void *);
-
-/* smalloc a thing */
-#define smalloca(type) ((type *) smalloc (sizeof (type)))
-/* smalloc a copy of a thing */
-#define smallocc(ptr) memcpy (smalloc (sizeof (*ptr)), ptr, sizeof (*ptr))
-/* smalloc n things */
-#define smallocn(n,type) ((type *) smalloc ((n) * sizeof (type)))
-
+/*
+ * Direct use of smalloc within the code should be avoided where
+ * possible, in favour of these type-casting macros which ensure
+ * you don't mistakenly allocate enough space for one sort of
+ * structure and assign it to a different sort of pointer.
+ */
+#define snew(type) ((type *)smalloc(sizeof(type)))
+#define snewn(n, type) ((type *)smalloc((n)*sizeof(type)))
+#define sresize(ptr, n, type) ((type *)srealloc(ptr, (n)*sizeof(type)))
- raw = smalloc(sizeof(*raw));
+ raw = snew(struct raw_backend_data);
raw->fn = &fn_table;
raw->s = NULL;
*backend_handle = raw;
raw->fn = &fn_table;
raw->s = NULL;
*backend_handle = raw;
char *err;
Rlogin rlogin;
char *err;
Rlogin rlogin;
- rlogin = smalloc(sizeof(*rlogin));
+ rlogin = snew(struct rlogin_tag);
rlogin->fn = &fn_table;
rlogin->s = NULL;
rlogin->frontend = frontend_handle;
rlogin->fn = &fn_table;
rlogin->s = NULL;
rlogin->frontend = frontend_handle;
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
- pending = (pending ? srealloc(pending, pendsize) :
- smalloc(pendsize));
+ pending = sresize(pending, pendsize, unsigned char);
if (!pending)
fatalbox("Out of memory");
}
if (!pending)
fatalbox("Out of memory");
}
namelen = 0;
if (GetUserName(user, &namelen) == FALSE)
bump("Empty user name");
namelen = 0;
if (GetUserName(user, &namelen) == FALSE)
bump("Empty user name");
- user = smalloc(namelen * sizeof(char));
+ user = snewn(namelen, char);
GetUserName(user, &namelen);
if (verbose)
tell_user(stderr, "Guessing user name: %s", user);
GetUserName(user, &namelen);
if (verbose)
tell_user(stderr, "Guessing user name: %s", user);
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
- ournames =
- srealloc(ournames, namesize * sizeof(*ournames));
+ ournames = sresize(ournames, namesize, struct fxp_name);
}
for (i = 0; i < names->nnames; i++)
}
for (i = 0; i < names->nnames; i++)
* wildcardness comes before the final slash) and arrange
* things so that a dirstack entry will be set up.
*/
* wildcardness comes before the final slash) and arrange
* things so that a dirstack entry will be set up.
*/
- newsource = smalloc(1+strlen(source));
+ newsource = snewn(1+strlen(source), char);
if (!wc_unescape(newsource, source)) {
/* Yes, here we go; it's a wildcard. Bah. */
char *dupsource, *lastpart, *dirpart, *wildcard;
if (!wc_unescape(newsource, source)) {
/* Yes, here we go; it's a wildcard. Bah. */
char *dupsource, *lastpart, *dirpart, *wildcard;
* wildcard escapes from the directory part, throwing
* an error if it contains a real wildcard.
*/
* wildcard escapes from the directory part, throwing
* an error if it contains a real wildcard.
*/
- dirpart = smalloc(1+strlen(dupsource));
+ dirpart = snewn(1+strlen(dupsource), char);
if (!wc_unescape(dirpart, dupsource)) {
tell_user(stderr, "%s: multiple-level wildcards unsupported",
source);
if (!wc_unescape(dirpart, dupsource)) {
tell_user(stderr, "%s: multiple-level wildcards unsupported",
source);
}
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
}
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
- ournames =
- srealloc(ournames, namesize * sizeof(*ournames));
+ ournames = sresize(ournames, namesize, struct fxp_name);
}
for (i = 0; i < names->nnames; i++)
ournames[nnames++] = names->names[i];
}
for (i = 0; i < names->nnames; i++)
ournames[nnames++] = names->names[i];
- newitem = smalloc(sizeof(struct scp_sftp_dirstack));
+ newitem = snew(struct scp_sftp_dirstack);
newitem->next = scp_sftp_dirstack_head;
newitem->names = ournames;
newitem->namepos = 0;
newitem->next = scp_sftp_dirstack_head;
newitem->names = ournames;
newitem->namepos = 0;
bump("Lost connection");
if (i >= bufsize) {
bufsize = i + 128;
bump("Lost connection");
if (i >= bufsize) {
bufsize = i + 128;
- act->buf = srealloc(act->buf, bufsize);
+ act->buf = sresize(act->buf, bufsize, char);
}
act->buf[i++] = ch;
} while (ch != '\n');
}
act->buf[i++] = ch;
} while (ch != '\n');
- cmd = smalloc(4 * strlen(src) + 100);
+ cmd = snewn(4 * strlen(src) + 100, char);
strcpy(cmd, "ls -la '");
p = cmd + strlen(cmd);
for (q = src; *q; q++) {
strcpy(cmd, "ls -la '");
p = cmd + strlen(cmd);
for (q = src; *q; q++) {
int len = strlen(otherbuf) + 1;
if (bufsize < buflen + len) {
bufsize = buflen + len + 2048;
int len = strlen(otherbuf) + 1;
if (bufsize < buflen + len) {
bufsize = buflen + len + 2048;
- list->buffer = srealloc(list->buffer, bufsize);
+ list->buffer = sresize(list->buffer, bufsize, char);
}
strcpy(list->buffer + buflen, otherbuf);
buflen += strlen(list->buffer + buflen) + 1;
}
strcpy(list->buffer + buflen, otherbuf);
buflen += strlen(list->buffer + buflen) + 1;
} while (ret);
enum_settings_finish(handle);
}
} while (ret);
enum_settings_finish(handle);
}
- list->buffer = srealloc(list->buffer, buflen + 1);
+ list->buffer = sresize(list->buffer, buflen + 1, char);
list->buffer[buflen] = '\0';
/*
list->buffer[buflen] = '\0';
/*
- list->sessions = smalloc((list->nsessions + 1) * sizeof(char *));
+ list->sessions = snewn(list->nsessions + 1, char *);
list->sessions[0] = "Default Settings";
p = list->buffer;
i = 1;
list->sessions[0] = "Default Settings";
p = list->buffer;
i = 1;
{
if (pkt->maxlen < length) {
pkt->maxlen = length + 256;
{
if (pkt->maxlen < length) {
pkt->maxlen = length + 256;
- pkt->data = srealloc(pkt->data, pkt->maxlen);
+ pkt->data = sresize(pkt->data, pkt->maxlen, char);
}
}
static void sftp_pkt_adddata(struct sftp_packet *pkt, void *data, int len)
}
}
static void sftp_pkt_adddata(struct sftp_packet *pkt, void *data, int len)
static struct sftp_packet *sftp_pkt_init(int pkt_type)
{
struct sftp_packet *pkt;
static struct sftp_packet *sftp_pkt_init(int pkt_type)
{
struct sftp_packet *pkt;
- pkt = smalloc(sizeof(struct sftp_packet));
+ pkt = snew(struct sftp_packet);
pkt->data = NULL;
pkt->savedpos = -1;
pkt->length = 0;
pkt->data = NULL;
pkt->savedpos = -1;
pkt->length = 0;
if (!sftp_recvdata(x, 4))
return NULL;
if (!sftp_recvdata(x, 4))
return NULL;
- pkt = smalloc(sizeof(struct sftp_packet));
+ pkt = snew(struct sftp_packet);
pkt->savedpos = 0;
pkt->length = pkt->maxlen = GET_32BIT(x);
pkt->savedpos = 0;
pkt->length = pkt->maxlen = GET_32BIT(x);
- pkt->data = smalloc(pkt->length);
+ pkt->data = snewn(pkt->length, char);
if (!sftp_recvdata(pkt->data, pkt->length)) {
sftp_pkt_free(pkt);
if (!sftp_recvdata(pkt->data, pkt->length)) {
sftp_pkt_free(pkt);
static char *mkstr(char *s, int len)
{
static char *mkstr(char *s, int len)
{
- char *p = smalloc(len + 1);
+ char *p = snewn(len + 1, char);
memcpy(p, s, len);
p[len] = '\0';
return p;
memcpy(p, s, len);
p[len] = '\0';
return p;
sftp_pkt_free(pktin);
return NULL;
}
sftp_pkt_free(pktin);
return NULL;
}
- handle = smalloc(sizeof(struct fxp_handle));
+ handle = snew(struct fxp_handle);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
sftp_pkt_free(pktin);
return NULL;
}
sftp_pkt_free(pktin);
return NULL;
}
- handle = smalloc(sizeof(struct fxp_handle));
+ handle = snew(struct fxp_handle);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
handle->hstring = mkstr(hstring, len);
handle->hlen = len;
sftp_pkt_free(pktin);
if (pktin->type == SSH_FXP_NAME) {
struct fxp_names *ret;
int i;
if (pktin->type == SSH_FXP_NAME) {
struct fxp_names *ret;
int i;
- ret = smalloc(sizeof(struct fxp_names));
+ ret = snew(struct fxp_names);
ret->nnames = sftp_pkt_getuint32(pktin);
ret->nnames = sftp_pkt_getuint32(pktin);
- ret->names = smalloc(ret->nnames * sizeof(struct fxp_name));
+ ret->names = snewn(ret->nnames, struct fxp_name);
for (i = 0; i < ret->nnames; i++) {
char *str;
int len;
for (i = 0; i < ret->nnames; i++) {
char *str;
int len;
struct fxp_name *fxp_dup_name(struct fxp_name *name)
{
struct fxp_name *ret;
struct fxp_name *fxp_dup_name(struct fxp_name *name)
{
struct fxp_name *ret;
- ret = smalloc(sizeof(struct fxp_name));
+ ret = snew(struct fxp_name);
ret->filename = dupstr(name->filename);
ret->longname = dupstr(name->longname);
ret->attrs = name->attrs; /* structure copy */
ret->filename = dupstr(name->filename);
ret->longname = dupstr(name->longname);
ret->attrs = name->attrs; /* structure copy */
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
wtlen = GetWindowTextLength(hWnd);
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
wtlen = GetWindowTextLength(hWnd);
- wt = (LPTSTR) smalloc((wtlen + 1) * sizeof(TCHAR));
+ wt = (LPTSTR) snewn(wtlen + 1, TCHAR);
GetWindowText(hWnd, wt, wtlen + 1);
SetTextColor(hdc, tip_text);
GetWindowText(hWnd, wt, wtlen + 1);
SetTextColor(hdc, tip_text);
#define crBegin(v) { int *crLine = &v; switch(v) { case 0:;
#define crState(t) \
struct t *s; \
#define crBegin(v) { int *crLine = &v; switch(v) { case 0:;
#define crState(t) \
struct t *s; \
- if (!ssh->t) ssh->t = smalloc(sizeof(struct t)); \
+ if (!ssh->t) ssh->t = snew(struct t); \
s = ssh->t;
#define crFinish(z) } *crLine = 0; return (z); }
#define crFinishV } *crLine = 0; return; }
s = ssh->t;
#define crFinish(z) } *crLine = 0; return (z); }
#define crFinishV } *crLine = 0; return; }
if (ssh->pktin.maxlen < st->biglen) {
ssh->pktin.maxlen = st->biglen;
if (ssh->pktin.maxlen < st->biglen) {
ssh->pktin.maxlen = st->biglen;
- ssh->pktin.data = srealloc(ssh->pktin.data, st->biglen + APIEXTRA);
+ ssh->pktin.data = sresize(ssh->pktin.data, st->biglen + APIEXTRA,
+ unsigned char);
}
st->to_read = st->biglen;
}
st->to_read = st->biglen;
if (ssh->pktin.maxlen < st->pad + decomplen) {
ssh->pktin.maxlen = st->pad + decomplen;
if (ssh->pktin.maxlen < st->pad + decomplen) {
ssh->pktin.maxlen = st->pad + decomplen;
- ssh->pktin.data = srealloc(ssh->pktin.data,
- ssh->pktin.maxlen + APIEXTRA);
+ ssh->pktin.data = sresize(ssh->pktin.data,
+ ssh->pktin.maxlen + APIEXTRA,
+ unsigned char);
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
}
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
}
if (ssh->pktin.maxlen < st->cipherblk) {
ssh->pktin.maxlen = st->cipherblk;
if (ssh->pktin.maxlen < st->cipherblk) {
ssh->pktin.maxlen = st->cipherblk;
- ssh->pktin.data = srealloc(ssh->pktin.data, st->cipherblk + APIEXTRA);
+ ssh->pktin.data = sresize(ssh->pktin.data, st->cipherblk + APIEXTRA,
+ unsigned char);
*/
if (ssh->pktin.maxlen < st->packetlen + st->maclen) {
ssh->pktin.maxlen = st->packetlen + st->maclen;
*/
if (ssh->pktin.maxlen < st->packetlen + st->maclen) {
ssh->pktin.maxlen = st->packetlen + st->maclen;
- ssh->pktin.data = srealloc(ssh->pktin.data,
- ssh->pktin.maxlen + APIEXTRA);
+ ssh->pktin.data = sresize(ssh->pktin.data,
+ ssh->pktin.maxlen + APIEXTRA,
+ unsigned char);
&newpayload, &newlen)) {
if (ssh->pktin.maxlen < newlen + 5) {
ssh->pktin.maxlen = newlen + 5;
&newpayload, &newlen)) {
if (ssh->pktin.maxlen < newlen + 5) {
ssh->pktin.maxlen = newlen + 5;
- ssh->pktin.data = srealloc(ssh->pktin.data,
- ssh->pktin.maxlen + APIEXTRA);
+ ssh->pktin.data = sresize(ssh->pktin.data,
+ ssh->pktin.maxlen + APIEXTRA,
+ unsigned char);
}
ssh->pktin.length = 5 + newlen;
memcpy(ssh->pktin.data + 5, newpayload, newlen);
}
ssh->pktin.length = 5 + newlen;
memcpy(ssh->pktin.data + 5, newpayload, newlen);
#ifdef MSCRYPTOAPI
/* Allocate enough buffer space for extra block
* for MS CryptEncrypt() */
#ifdef MSCRYPTOAPI
/* Allocate enough buffer space for extra block
* for MS CryptEncrypt() */
- ssh->pktout.data = srealloc(ssh->pktout.data, biglen + 12);
+ ssh->pktout.data = sresize(ssh->pktout.data, biglen + 12,
+ unsigned char);
- ssh->pktout.data = srealloc(ssh->pktout.data, biglen + 4);
+ ssh->pktout.data = sresize(ssh->pktout.data, biglen + 4,
+ unsigned char);
#endif
}
ssh->pktout.body = ssh->pktout.data + 4 + pad + 1;
#endif
}
ssh->pktout.body = ssh->pktout.data + 4 + pad + 1;
len = s_wrpkt_prepare(ssh);
if (ssh->deferred_len + len > ssh->deferred_size) {
ssh->deferred_size = ssh->deferred_len + len + 128;
len = s_wrpkt_prepare(ssh);
if (ssh->deferred_len + len > ssh->deferred_size) {
ssh->deferred_size = ssh->deferred_len + len + 128;
- ssh->deferred_send_data = srealloc(ssh->deferred_send_data,
- ssh->deferred_size);
+ ssh->deferred_send_data = sresize(ssh->deferred_send_data,
+ ssh->deferred_size,
+ unsigned char);
}
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
ssh->deferred_len += len;
}
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
ssh->deferred_len += len;
{
if (ssh->pktout.maxlen < length) {
ssh->pktout.maxlen = length + 256;
{
if (ssh->pktout.maxlen < length) {
ssh->pktout.maxlen = length + 256;
- ssh->pktout.data = srealloc(ssh->pktout.data,
- ssh->pktout.maxlen + APIEXTRA);
+ ssh->pktout.data = sresize(ssh->pktout.data,
+ ssh->pktout.maxlen + APIEXTRA,
+ unsigned char);
if (!ssh->pktout.data)
fatalbox("Out of memory");
}
if (!ssh->pktout.data)
fatalbox("Out of memory");
}
{
unsigned char *p;
int i, n = (bignum_bitcount(b) + 7) / 8;
{
unsigned char *p;
int i, n = (bignum_bitcount(b) + 7) / 8;
+ p = snewn(n + 1, unsigned char);
if (!p)
fatalbox("out of memory");
p[0] = 0;
if (!p)
fatalbox("out of memory");
p[0] = 0;
int len = ssh2_pkt_construct(ssh);
if (ssh->deferred_len + len > ssh->deferred_size) {
ssh->deferred_size = ssh->deferred_len + len + 128;
int len = ssh2_pkt_construct(ssh);
if (ssh->deferred_len + len > ssh->deferred_size) {
ssh->deferred_size = ssh->deferred_len + len + 128;
- ssh->deferred_send_data = srealloc(ssh->deferred_send_data,
- ssh->deferred_size);
+ ssh->deferred_send_data = sresize(ssh->deferred_send_data,
+ ssh->deferred_size,
+ unsigned char);
}
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
ssh->deferred_len += len;
}
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
ssh->deferred_len += len;
- s->vstring = smalloc(s->vstrsize);
+ s->vstring = snewn(s->vstrsize, char);
strcpy(s->vstring, "SSH-");
s->vslen = 4;
s->i = 0;
strcpy(s->vstring, "SSH-");
s->vslen = 4;
s->i = 0;
crReturn(1); /* get another char */
if (s->vslen >= s->vstrsize - 1) {
s->vstrsize += 16;
crReturn(1); /* get another char */
if (s->vslen >= s->vstrsize - 1) {
s->vstrsize += 16;
- s->vstring = srealloc(s->vstring, s->vstrsize);
+ s->vstring = sresize(s->vstring, s->vstrsize, char);
}
s->vstring[s->vslen++] = c;
if (s->i >= 0) {
}
s->vstring[s->vslen++] = c;
if (s->i >= 0) {
s->vstring[strcspn(s->vstring, "\r\n")] = '\0';/* remove EOL chars */
{
char *vlog;
s->vstring[strcspn(s->vstring, "\r\n")] = '\0';/* remove EOL chars */
{
char *vlog;
- vlog = smalloc(20 + s->vslen);
+ vlog = snewn(20 + s->vslen, char);
sprintf(vlog, "Server version: %s", s->vstring);
logevent(vlog);
sfree(vlog);
sprintf(vlog, "Server version: %s", s->vstring);
logevent(vlog);
sfree(vlog);
SockAddr addr;
char *err;
SockAddr addr;
char *err;
- ssh->savedhost = smalloc(1 + strlen(host));
+ ssh->savedhost = snewn(1 + strlen(host), char);
if (!ssh->savedhost)
fatalbox("Out of memory");
strcpy(ssh->savedhost, host);
if (!ssh->savedhost)
fatalbox("Out of memory");
strcpy(ssh->savedhost, host);
s->len = (hostkey.bytes > servkey.bytes ? hostkey.bytes : servkey.bytes);
s->len = (hostkey.bytes > servkey.bytes ? hostkey.bytes : servkey.bytes);
- s->rsabuf = smalloc(s->len);
+ s->rsabuf = snewn(s->len, unsigned char);
if (!s->rsabuf)
fatalbox("Out of memory");
if (!s->rsabuf)
fatalbox("Out of memory");
*/
int len = rsastr_len(&hostkey);
char fingerprint[100];
*/
int len = rsastr_len(&hostkey);
char fingerprint[100];
- char *keystr = smalloc(len);
+ char *keystr = snewn(len, char);
if (!keystr)
fatalbox("Out of memory");
rsastr_fmt(keystr, &hostkey);
if (!keystr)
fatalbox("Out of memory");
rsastr_fmt(keystr, &hostkey);
len += ssh1_bignum_length(s->challenge);
len += 16; /* session id */
len += 4; /* response format */
len += ssh1_bignum_length(s->challenge);
len += 16; /* session id */
len += 4; /* response format */
- agentreq = smalloc(4 + len);
+ agentreq = snewn(4 + len, char);
PUT_32BIT(agentreq, len);
q = agentreq + 4;
*q++ = SSH1_AGENTC_RSA_CHALLENGE;
PUT_32BIT(agentreq, len);
q = agentreq + 4;
*q++ = SSH1_AGENTC_RSA_CHALLENGE;
assert(pwlen >= bottom && pwlen <= top);
assert(pwlen >= bottom && pwlen <= top);
- randomstr = smalloc(top + 1);
+ randomstr = snewn(top + 1, char);
for (i = bottom; i <= top; i++) {
if (i == pwlen)
for (i = bottom; i <= top; i++) {
if (i == pwlen)
dserv, "(", dport, dserv, ")");
} else {
struct ssh_rportfwd *pf;
dserv, "(", dport, dserv, ")");
} else {
struct ssh_rportfwd *pf;
- pf = smalloc(sizeof(*pf));
+ pf = snew(struct ssh_rportfwd);
strcpy(pf->dhost, host);
pf->dport = dport;
if (saddr) {
strcpy(pf->dhost, host);
pf->dport = dport;
if (saddr) {
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
logevent("Rejected X11 connect request");
} else {
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
logevent("Rejected X11 connect request");
} else {
- c = smalloc(sizeof(struct ssh_channel));
+ c = snew(struct ssh_channel);
c->ssh = ssh;
if (x11_init(&c->u.x11.s, ssh->cfg.x11_display, c,
c->ssh = ssh;
if (x11_init(&c->u.x11.s, ssh->cfg.x11_display, c,
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
} else {
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
} else {
- c = smalloc(sizeof(struct ssh_channel));
+ c = snew(struct ssh_channel);
c->ssh = ssh;
c->remoteid = GET_32BIT(ssh->pktin.body);
c->localid = alloc_channel_id(ssh);
c->ssh = ssh;
c->remoteid = GET_32BIT(ssh->pktin.body);
c->localid = alloc_channel_id(ssh);
int hostsize, port;
char host[256], buf[1024];
char *p, *h, *e;
int hostsize, port;
char host[256], buf[1024];
char *p, *h, *e;
- c = smalloc(sizeof(struct ssh_channel));
+ c = snew(struct ssh_channel);
c->ssh = ssh;
hostsize = GET_32BIT(ssh->pktin.body+4);
c->ssh = ssh;
hostsize = GET_32BIT(ssh->pktin.body+4);
if (c->u.a.lensofar == 4) {
c->u.a.totallen =
4 + GET_32BIT(c->u.a.msglen);
if (c->u.a.lensofar == 4) {
c->u.a.totallen =
4 + GET_32BIT(c->u.a.msglen);
- c->u.a.message = smalloc(c->u.a.totallen);
+ c->u.a.message = snewn(c->u.a.totallen,
+ unsigned char);
memcpy(c->u.a.message, c->u.a.msglen, 4);
}
if (c->u.a.lensofar >= 4 && len > 0) {
memcpy(c->u.a.message, c->u.a.msglen, 4);
}
if (c->u.a.lensofar >= 4 && len > 0) {
s->len += 4 + s->pklen; /* key blob */
s->len += 4 + s->siglen; /* data to sign */
s->len += 4; /* flags */
s->len += 4 + s->pklen; /* key blob */
s->len += 4 + s->siglen; /* data to sign */
s->len += 4; /* flags */
- s->agentreq = smalloc(4 + s->len);
+ s->agentreq = snewn(4 + s->len, char);
PUT_32BIT(s->agentreq, s->len);
s->q = s->agentreq + 4;
*s->q++ = SSH2_AGENTC_SIGN_REQUEST;
PUT_32BIT(s->agentreq, s->len);
s->q = s->agentreq + 4;
*s->q++ = SSH2_AGENTC_SIGN_REQUEST;
sigdata_len = ssh->pktout.length - 5 + 4 + 20;
if (ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)
sigdata_len -= 4;
sigdata_len = ssh->pktout.length - 5 + 4 + 20;
if (ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)
sigdata_len -= 4;
- sigdata = smalloc(sigdata_len);
+ sigdata = snewn(sigdata_len, char);
p = 0;
if (!(ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)) {
PUT_32BIT(sigdata+p, 20);
p = 0;
if (!(ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)) {
PUT_32BIT(sigdata+p, 20);
* So now create a channel with a session in it.
*/
ssh->channels = newtree234(ssh_channelcmp);
* So now create a channel with a session in it.
*/
ssh->channels = newtree234(ssh_channelcmp);
- ssh->mainchan = smalloc(sizeof(struct ssh_channel));
+ ssh->mainchan = snew(struct ssh_channel);
ssh->mainchan->ssh = ssh;
ssh->mainchan->localid = alloc_channel_id(ssh);
ssh2_pkt_init(ssh, SSH2_MSG_CHANNEL_OPEN);
ssh->mainchan->ssh = ssh;
ssh->mainchan->localid = alloc_channel_id(ssh);
ssh2_pkt_init(ssh, SSH2_MSG_CHANNEL_OPEN);
dserv, "(", dport, dserv, ")");
} else {
struct ssh_rportfwd *pf;
dserv, "(", dport, dserv, ")");
} else {
struct ssh_rportfwd *pf;
- pf = smalloc(sizeof(*pf));
+ pf = snew(struct ssh_rportfwd);
strcpy(pf->dhost, host);
pf->dport = dport;
pf->sport = sport;
strcpy(pf->dhost, host);
pf->dport = dport;
pf->sport = sport;
if (c->u.a.lensofar == 4) {
c->u.a.totallen =
4 + GET_32BIT(c->u.a.msglen);
if (c->u.a.lensofar == 4) {
c->u.a.totallen =
4 + GET_32BIT(c->u.a.msglen);
- c->u.a.message = smalloc(c->u.a.totallen);
+ c->u.a.message = snewn(c->u.a.totallen,
+ unsigned char);
memcpy(c->u.a.message, c->u.a.msglen, 4);
}
if (c->u.a.lensofar >= 4 && length > 0) {
memcpy(c->u.a.message, c->u.a.msglen, 4);
}
if (c->u.a.lensofar >= 4 && length > 0) {
struct ssh_channel *c;
unsigned remid, winsize, pktsize;
ssh2_pkt_getstring(ssh, &type, &typelen);
struct ssh_channel *c;
unsigned remid, winsize, pktsize;
ssh2_pkt_getstring(ssh, &type, &typelen);
- c = smalloc(sizeof(struct ssh_channel));
+ c = snew(struct ssh_channel);
c->ssh = ssh;
remid = ssh2_pkt_getuint32(ssh);
c->ssh = ssh;
remid = ssh2_pkt_getuint32(ssh);
port = ssh2_pkt_getuint32(ssh);
if (typelen == 3 && !memcmp(type, "x11", 3)) {
port = ssh2_pkt_getuint32(ssh);
if (typelen == 3 && !memcmp(type, "x11", 3)) {
- char *addrstr = smalloc(peeraddrlen+1);
+ char *addrstr = snewn(peeraddrlen+1, char);
memcpy(addrstr, peeraddr, peeraddrlen);
peeraddr[peeraddrlen] = '\0';
memcpy(addrstr, peeraddr, peeraddrlen);
peeraddr[peeraddrlen] = '\0';
- ssh = smalloc(sizeof(*ssh));
+ ssh = snew(struct ssh_tag);
ssh->cfg = *cfg; /* STRUCTURE COPY */
ssh->s = NULL;
ssh->cipher = NULL;
ssh->cfg = *cfg; /* STRUCTURE COPY */
ssh->s = NULL;
ssh->cipher = NULL;
{
Ssh ssh = (Ssh) handle;
struct ssh_channel *c;
{
Ssh ssh = (Ssh) handle;
struct ssh_channel *c;
- c = smalloc(sizeof(struct ssh_channel));
+ c = snew(struct ssh_channel);
static void *aes_make_context(void)
{
static void *aes_make_context(void)
{
- return smalloc(sizeof(AESContext));
+ return snew(AESContext);
}
static void aes_free_context(void *handle)
}
static void aes_free_context(void *handle)
static void *blowfish_make_context(void)
{
static void *blowfish_make_context(void)
{
- return smalloc(sizeof(BlowfishContext));
+ return snew(BlowfishContext);
}
static void *blowfish_ssh1_make_context(void)
{
/* In SSH1, need one key for each direction */
}
static void *blowfish_ssh1_make_context(void)
{
/* In SSH1, need one key for each direction */
- return smalloc(2*sizeof(BlowfishContext));
+ return snewn(2, BlowfishContext);
}
static void blowfish_free_context(void *handle)
}
static void blowfish_free_context(void *handle)
static Bignum newbn(int length)
{
static Bignum newbn(int length)
{
- Bignum b = smalloc((length + 1) * sizeof(unsigned short));
+ Bignum b = snewn(length + 1, unsigned short);
if (!b)
abort(); /* FIXME */
memset(b, 0, (length + 1) * sizeof(*b));
if (!b)
abort(); /* FIXME */
memset(b, 0, (length + 1) * sizeof(*b));
Bignum copybn(Bignum orig)
{
Bignum copybn(Bignum orig)
{
- Bignum b = smalloc((orig[0] + 1) * sizeof(unsigned short));
+ Bignum b = snewn(orig[0] + 1, unsigned short);
if (!b)
abort(); /* FIXME */
memcpy(b, orig, (orig[0] + 1) * sizeof(*b));
if (!b)
abort(); /* FIXME */
memcpy(b, orig, (orig[0] + 1) * sizeof(*b));
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
- m = smalloc(mlen * sizeof(unsigned short));
+ m = snewn(mlen, unsigned short);
for (j = 0; j < mlen; j++)
m[j] = mod[mod[0] - j];
for (j = 0; j < mlen; j++)
m[j] = mod[mod[0] - j];
}
/* Allocate n of size mlen, copy base to n */
}
/* Allocate n of size mlen, copy base to n */
- n = smalloc(mlen * sizeof(unsigned short));
+ n = snewn(mlen, unsigned short);
i = mlen - base[0];
for (j = 0; j < i; j++)
n[j] = 0;
i = mlen - base[0];
for (j = 0; j < i; j++)
n[j] = 0;
n[i + j] = base[base[0] - j];
/* Allocate a and b of size 2*mlen. Set a = 1 */
n[i + j] = base[base[0] - j];
/* Allocate a and b of size 2*mlen. Set a = 1 */
- a = smalloc(2 * mlen * sizeof(unsigned short));
- b = smalloc(2 * mlen * sizeof(unsigned short));
+ a = snewn(2 * mlen, unsigned short);
+ b = snewn(2 * mlen, unsigned short);
for (i = 0; i < 2 * mlen; i++)
a[i] = 0;
a[2 * mlen - 1] = 1;
for (i = 0; i < 2 * mlen; i++)
a[i] = 0;
a[2 * mlen - 1] = 1;
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
- m = smalloc(mlen * sizeof(unsigned short));
+ m = snewn(mlen, unsigned short);
for (j = 0; j < mlen; j++)
m[j] = mod[mod[0] - j];
for (j = 0; j < mlen; j++)
m[j] = mod[mod[0] - j];
pqlen = (p[0] > q[0] ? p[0] : q[0]);
/* Allocate n of size pqlen, copy p to n */
pqlen = (p[0] > q[0] ? p[0] : q[0]);
/* Allocate n of size pqlen, copy p to n */
- n = smalloc(pqlen * sizeof(unsigned short));
+ n = snewn(pqlen, unsigned short);
i = pqlen - p[0];
for (j = 0; j < i; j++)
n[j] = 0;
i = pqlen - p[0];
for (j = 0; j < i; j++)
n[j] = 0;
n[i + j] = p[p[0] - j];
/* Allocate o of size pqlen, copy q to o */
n[i + j] = p[p[0] - j];
/* Allocate o of size pqlen, copy q to o */
- o = smalloc(pqlen * sizeof(unsigned short));
+ o = snewn(pqlen, unsigned short);
i = pqlen - q[0];
for (j = 0; j < i; j++)
o[j] = 0;
i = pqlen - q[0];
for (j = 0; j < i; j++)
o[j] = 0;
o[i + j] = q[q[0] - j];
/* Allocate a of size 2*pqlen for result */
o[i + j] = q[q[0] - j];
/* Allocate a of size 2*pqlen for result */
- a = smalloc(2 * pqlen * sizeof(unsigned short));
+ a = snewn(2 * pqlen, unsigned short);
/* Main computation */
internal_mul(n, o, a, pqlen);
/* Main computation */
internal_mul(n, o, a, pqlen);
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
/* Allocate m of size mlen, copy mod to m */
/* We use big endian internally */
mlen = mod[0];
- m = smalloc(mlen * sizeof(unsigned short));
+ m = snewn(mlen, unsigned short);
for (j = 0; j < mlen; j++)
m[j] = mod[mod[0] - j];
for (j = 0; j < mlen; j++)
m[j] = mod[mod[0] - j];
plen = mlen + 1;
/* Allocate n of size plen, copy p to n */
plen = mlen + 1;
/* Allocate n of size plen, copy p to n */
- n = smalloc(plen * sizeof(unsigned short));
+ n = snewn(plen, unsigned short);
for (j = 0; j < plen; j++)
n[j] = 0;
for (j = 1; j <= p[0]; j++)
for (j = 0; j < plen; j++)
n[j] = 0;
for (j = 1; j <= p[0]; j++)
Bignum ret;
/* mlen space for a, mlen space for b, 2*mlen for result */
Bignum ret;
/* mlen space for a, mlen space for b, 2*mlen for result */
- workspace = smalloc(mlen * 4 * sizeof(unsigned short));
+ workspace = snewn(mlen * 4, unsigned short);
for (i = 0; i < mlen; i++) {
workspace[0 * mlen + i] = (mlen - i <= a[0] ? a[mlen - i] : 0);
workspace[1 * mlen + i] = (mlen - i <= b[0] ? b[mlen - i] : 0);
for (i = 0; i < mlen; i++) {
workspace[0 * mlen + i] = (mlen - i <= a[0] ? a[mlen - i] : 0);
workspace[1 * mlen + i] = (mlen - i <= b[0] ? b[mlen - i] : 0);
i = bignum_bitcount(x);
ndigits = (28 * i + 92) / 93; /* multiply by 28/93 and round up */
ndigits++; /* allow for trailing \0 */
i = bignum_bitcount(x);
ndigits = (28 * i + 92) / 93; /* multiply by 28/93 and round up */
ndigits++; /* allow for trailing \0 */
- ret = smalloc(ndigits);
+ ret = snewn(ndigits, char);
/*
* Now allocate some workspace to hold the binary form as we
* repeatedly divide it by ten. Initialise this to the
* big-endian form of the number.
*/
/*
* Now allocate some workspace to hold the binary form as we
* repeatedly divide it by ten. Initialise this to the
* big-endian form of the number.
*/
- workspace = smalloc(sizeof(unsigned short) * x[0]);
+ workspace = snewn(x[0], unsigned short);
for (i = 0; i < x[0]; i++)
workspace[i] = x[x[0] - i];
for (i = 0; i < x[0]; i++)
workspace[i] = x[x[0] - i];
void *crcda_make_context(void)
{
void *crcda_make_context(void)
{
- struct crcda_ctx *ret = smalloc(sizeof(struct crcda_ctx));
+ struct crcda_ctx *ret = snew(struct crcda_ctx);
ret->h = NULL;
ret->n = HASH_MINSIZE / HASH_ENTRYSIZE;
return ret;
ret->h = NULL;
ret->n = HASH_MINSIZE / HASH_ENTRYSIZE;
return ret;
if (ctx->h == NULL) {
ctx->n = l;
if (ctx->h == NULL) {
ctx->n = l;
- ctx->h = (uint16 *) smalloc(ctx->n * HASH_ENTRYSIZE);
+ ctx->h = snewn(ctx->n, uint16);
} else {
if (l > ctx->n) {
ctx->n = l;
} else {
if (l > ctx->n) {
ctx->n = l;
- ctx->h = (uint16 *) srealloc(ctx->h, ctx->n * HASH_ENTRYSIZE);
+ ctx->h = sresize(ctx->h, ctx->n, uint16);
static void *des3_make_context(void)
{
static void *des3_make_context(void)
{
- return smalloc(3*sizeof(DESContext));
+ return snewn(3, DESContext);
}
static void *des3_ssh1_make_context(void)
{
/* Need 3 keys for each direction, in SSH1 */
}
static void *des3_ssh1_make_context(void)
{
/* Need 3 keys for each direction, in SSH1 */
- return smalloc(6*sizeof(DESContext));
+ return snewn(6, DESContext);
}
static void *des_make_context(void)
{
}
static void *des_make_context(void)
{
- return smalloc(sizeof(DESContext));
+ return snew(DESContext);
}
static void *des_ssh1_make_context(void)
{
/* Need one key for each direction, in SSH1 */
}
static void *des_ssh1_make_context(void)
{
/* Need one key for each direction, in SSH1 */
- return smalloc(2*sizeof(DESContext));
+ return snewn(2, DESContext);
}
static void des3_free_context(void *handle) /* used for both 3DES and DES */
}
static void des3_free_context(void *handle) /* used for both 3DES and DES */
*/
void *dh_setup_group1(void)
{
*/
void *dh_setup_group1(void)
{
- struct dh_ctx *ctx = smalloc(sizeof(struct dh_ctx));
+ struct dh_ctx *ctx = snew(struct dh_ctx);
ctx->p = bignum_from_bytes(P, sizeof(P));
ctx->g = bignum_from_bytes(G, sizeof(G));
dh_init(ctx);
ctx->p = bignum_from_bytes(P, sizeof(P));
ctx->g = bignum_from_bytes(G, sizeof(G));
dh_init(ctx);
*/
void *dh_setup_group(Bignum pval, Bignum gval)
{
*/
void *dh_setup_group(Bignum pval, Bignum gval)
{
- struct dh_ctx *ctx = smalloc(sizeof(struct dh_ctx));
+ struct dh_ctx *ctx = snew(struct dh_ctx);
ctx->p = copybn(pval);
ctx->g = copybn(gval);
dh_init(ctx);
ctx->p = copybn(pval);
ctx->g = copybn(gval);
dh_init(ctx);
unsigned char *buf;
nbytes = ssh1_bignum_length(ctx->qmask);
unsigned char *buf;
nbytes = ssh1_bignum_length(ctx->qmask);
+ buf = snewn(nbytes, unsigned char);
int slen;
struct dss_key *dss;
int slen;
struct dss_key *dss;
- dss = smalloc(sizeof(struct dss_key));
+ dss = snew(struct dss_key);
if (!dss)
return NULL;
getstring(&data, &len, &p, &slen);
if (!dss)
return NULL;
getstring(&data, &len, &p, &slen);
len += 4 * (bignum_bitcount(dss->q) + 15) / 16;
len += 4 * (bignum_bitcount(dss->g) + 15) / 16;
len += 4 * (bignum_bitcount(dss->y) + 15) / 16;
len += 4 * (bignum_bitcount(dss->q) + 15) / 16;
len += 4 * (bignum_bitcount(dss->g) + 15) / 16;
len += 4 * (bignum_bitcount(dss->y) + 15) / 16;
for (i = 0; i < 16; i++)
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
digest[i]);
for (i = 0; i < 16; i++)
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
digest[i]);
- ret = smalloc(strlen(buffer) + 1);
+ ret = snewn(strlen(buffer) + 1, char);
if (ret)
strcpy(ret, buffer);
return ret;
if (ret)
strcpy(ret, buffer);
return ret;
* 27 + sum of lengths. (five length fields, 20+7=27).
*/
bloblen = 27 + plen + qlen + glen + ylen;
* 27 + sum of lengths. (five length fields, 20+7=27).
*/
bloblen = 27 + plen + qlen + glen + ylen;
- blob = smalloc(bloblen);
+ blob = snewn(bloblen, unsigned char);
p = blob;
PUT_32BIT(p, 7);
p += 4;
p = blob;
PUT_32BIT(p, 7);
p += 4;
* mpint x, string[20] the SHA of p||q||g. Total 4 + xlen.
*/
bloblen = 4 + xlen;
* mpint x, string[20] the SHA of p||q||g. Total 4 + xlen.
*/
bloblen = 4 + xlen;
- blob = smalloc(bloblen);
+ blob = snewn(bloblen, unsigned char);
p = blob;
PUT_32BIT(p, xlen);
p += 4;
p = blob;
PUT_32BIT(p, xlen);
p += 4;
char **b = (char **) blob;
struct dss_key *dss;
char **b = (char **) blob;
struct dss_key *dss;
- dss = smalloc(sizeof(struct dss_key));
+ dss = snew(struct dss_key);
* i.e. 4+7 + 4+40 bytes.
*/
nbytes = 4 + 7 + 4 + 40;
* i.e. 4+7 + 4+40 bytes.
*/
nbytes = 4 + 7 + 4 + 40;
- bytes = smalloc(nbytes);
+ bytes = snewn(nbytes, unsigned char);
PUT_32BIT(bytes, 7);
memcpy(bytes + 4, "ssh-dss", 7);
PUT_32BIT(bytes + 4 + 7, 40);
PUT_32BIT(bytes, 7);
memcpy(bytes + 4, "ssh-dss", 7);
PUT_32BIT(bytes + 4 + 7, 40);
static void *md5_make_context(void)
{
static void *md5_make_context(void)
{
- return smalloc(2*sizeof(struct MD5Context));
+ return snewn(2, struct MD5Context);
}
static void md5_free_context(void *handle)
}
static void md5_free_context(void *handle)
i += 4;
if (len - i < j)
goto end;
i += 4;
if (len - i < j)
goto end;
- comment = smalloc(j + 1);
+ comment = snewn(j + 1, char);
if (comment) {
memcpy(comment, buf + i, j);
comment[j] = '\0';
if (comment) {
memcpy(comment, buf + i, j);
comment[j] = '\0';
+ text = snewn(size, char);
len = 0;
text[len] = '\0';
len = 0;
text[len] = '\0';
}
if (len + 1 > size) {
size += 128;
}
if (len + 1 > size) {
size += 128;
- text = srealloc(text, size);
+ text = sresize(text, size, char);
}
text[len++] = c;
text[len] = '\0';
}
text[len++] = c;
text[len] = '\0';
int i, j, k;
/* We expect at most 64 base64 characters, ie 48 real bytes, per line. */
int i, j, k;
/* We expect at most 64 base64 characters, ie 48 real bytes, per line. */
- blob = smalloc(48 * nlines);
+ blob = snewn(48 * nlines, unsigned char);
len = 0;
for (i = 0; i < nlines; i++) {
line = read_body(fp);
len = 0;
for (i = 0; i < nlines; i++) {
line = read_body(fp);
4 + commlen +
4 + public_blob_len +
4 + private_blob_len);
4 + commlen +
4 + public_blob_len +
4 + private_blob_len);
- macdata = smalloc(maclen);
+ macdata = snewn(maclen, unsigned char);
p = macdata;
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
DO_STR(alg->name, namelen);
p = macdata;
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
DO_STR(alg->name, namelen);
/*
* Create and return the key.
*/
/*
* Create and return the key.
*/
- ret = smalloc(sizeof(struct ssh2_userkey));
+ ret = snew(struct ssh2_userkey);
ret->alg = alg;
ret->comment = comment;
ret->data = alg->createkey(public_blob, public_blob_len,
ret->alg = alg;
ret->comment = comment;
ret->data = alg->createkey(public_blob, public_blob_len,
}
priv_encrypted_len = priv_blob_len + cipherblk - 1;
priv_encrypted_len -= priv_encrypted_len % cipherblk;
}
priv_encrypted_len = priv_blob_len + cipherblk - 1;
priv_encrypted_len -= priv_encrypted_len % cipherblk;
- priv_blob_encrypted = smalloc(priv_encrypted_len);
+ priv_blob_encrypted = snewn(priv_encrypted_len, unsigned char);
memset(priv_blob_encrypted, 0, priv_encrypted_len);
memcpy(priv_blob_encrypted, priv_blob, priv_blob_len);
/* Create padding based on the SHA hash of the unpadded blob. This prevents
memset(priv_blob_encrypted, 0, priv_encrypted_len);
memcpy(priv_blob_encrypted, priv_blob, priv_blob_len);
/* Create padding based on the SHA hash of the unpadded blob. This prevents
4 + commlen +
4 + pub_blob_len +
4 + priv_encrypted_len);
4 + commlen +
4 + pub_blob_len +
4 + priv_encrypted_len);
- macdata = smalloc(maclen);
+ macdata = snewn(maclen, unsigned char);
p = macdata;
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
DO_STR(key->alg->name, namelen);
p = macdata;
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
DO_STR(key->alg->name, namelen);
void random_get_savedata(void **data, int *len)
{
void random_get_savedata(void **data, int *len)
{
- void *buf = smalloc(POOLSIZE / 2);
+ void *buf = snewn(POOLSIZE / 2, char);
random_stir();
memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2);
*len = POOLSIZE / 2;
random_stir();
memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2);
*len = POOLSIZE / 2;
length = (ssh1_bignum_length(key->modulus) +
ssh1_bignum_length(key->exponent) + 4);
length = (ssh1_bignum_length(key->modulus) +
ssh1_bignum_length(key->exponent) + 4);
+ ret = snewn(length, unsigned char);
PUT_32BIT(ret, bignum_bitcount(key->modulus));
pos = 4;
PUT_32BIT(ret, bignum_bitcount(key->modulus));
pos = 4;
int slen;
struct RSAKey *rsa;
int slen;
struct RSAKey *rsa;
- rsa = smalloc(sizeof(struct RSAKey));
+ rsa = snew(struct RSAKey);
if (!rsa)
return NULL;
getstring(&data, &len, &p, &slen);
if (!rsa)
return NULL;
getstring(&data, &len, &p, &slen);
int len;
len = rsastr_len(rsa);
int len;
len = rsastr_len(rsa);
rsastr_fmt(p, rsa);
return p;
}
rsastr_fmt(p, rsa);
return p;
}
* (three length fields, 12+7=19).
*/
bloblen = 19 + elen + mlen;
* (three length fields, 12+7=19).
*/
bloblen = 19 + elen + mlen;
- blob = smalloc(bloblen);
+ blob = snewn(bloblen, unsigned char);
p = blob;
PUT_32BIT(p, 7);
p += 4;
p = blob;
PUT_32BIT(p, 7);
p += 4;
* sum of lengths.
*/
bloblen = 16 + dlen + plen + qlen + ulen;
* sum of lengths.
*/
bloblen = 16 + dlen + plen + qlen + ulen;
- blob = smalloc(bloblen);
+ blob = snewn(bloblen, unsigned char);
p = blob;
PUT_32BIT(p, dlen);
p += 4;
p = blob;
PUT_32BIT(p, dlen);
p += 4;
char **b = (char **) blob;
struct RSAKey *rsa;
char **b = (char **) blob;
struct RSAKey *rsa;
- rsa = smalloc(sizeof(struct RSAKey));
+ rsa = snew(struct RSAKey);
if (!rsa)
return NULL;
rsa->comment = NULL;
if (!rsa)
return NULL;
rsa->comment = NULL;
for (i = 0; i < 16; i++)
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
digest[i]);
for (i = 0; i < 16; i++)
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
digest[i]);
- ret = smalloc(strlen(buffer) + 1);
+ ret = snewn(strlen(buffer) + 1, char);
if (ret)
strcpy(ret, buffer);
return ret;
if (ret)
strcpy(ret, buffer);
return ret;
SHA_Simple(data, datalen, hash);
nbytes = (bignum_bitcount(rsa->modulus) - 1) / 8;
SHA_Simple(data, datalen, hash);
nbytes = (bignum_bitcount(rsa->modulus) - 1) / 8;
- bytes = smalloc(nbytes);
+ bytes = snewn(nbytes, unsigned char);
bytes[0] = 1;
for (i = 1; i < nbytes - 20 - ASN1_LEN; i++)
bytes[0] = 1;
for (i = 1; i < nbytes - 20 - ASN1_LEN; i++)
freebn(in);
nbytes = (bignum_bitcount(out) + 7) / 8;
freebn(in);
nbytes = (bignum_bitcount(out) + 7) / 8;
- bytes = smalloc(4 + 7 + 4 + nbytes);
+ bytes = snewn(4 + 7 + 4 + nbytes, unsigned char);
PUT_32BIT(bytes, 7);
memcpy(bytes + 4, "ssh-rsa", 7);
PUT_32BIT(bytes + 4 + 7, nbytes);
PUT_32BIT(bytes, 7);
memcpy(bytes + 4, "ssh-rsa", 7);
PUT_32BIT(bytes + 4 + 7, nbytes);
static void *sha1_make_context(void)
{
static void *sha1_make_context(void)
{
- return smalloc(2*sizeof(SHA_State));
+ return snewn(2, SHA_State);
}
static void sha1_free_context(void *handle)
}
static void sha1_free_context(void *handle)
struct LZ77InternalContext *st;
int i;
struct LZ77InternalContext *st;
int i;
- st = (struct LZ77InternalContext *) smalloc(sizeof(*st));
+ st = snew(struct LZ77InternalContext);
while (out->noutbits >= 8) {
if (out->outlen >= out->outsize) {
out->outsize = out->outlen + 64;
while (out->noutbits >= 8) {
if (out->outlen >= out->outsize) {
out->outsize = out->outlen + 64;
- out->outbuf = srealloc(out->outbuf, out->outsize);
+ out->outbuf = sresize(out->outbuf, out->outsize, unsigned char);
}
out->outbuf[out->outlen++] = (unsigned char) (out->outbits & 0xFF);
out->outbits >>= 8;
}
out->outbuf[out->outlen++] = (unsigned char) (out->outbits & 0xFF);
out->outbits >>= 8;
void *zlib_compress_init(void)
{
struct Outbuf *out;
void *zlib_compress_init(void)
{
struct Outbuf *out;
- struct LZ77Context *ectx = smalloc(sizeof(struct LZ77Context));
+ struct LZ77Context *ectx = snew(struct LZ77Context);
lz77_init(ectx);
ectx->literal = zlib_literal;
ectx->match = zlib_match;
lz77_init(ectx);
ectx->literal = zlib_literal;
ectx->match = zlib_match;
- out = smalloc(sizeof(struct Outbuf));
+ out = snew(struct Outbuf);
out->outbits = out->noutbits = 0;
out->firstblock = 1;
out->comp_disabled = FALSE;
out->outbits = out->noutbits = 0;
out->firstblock = 1;
out->comp_disabled = FALSE;
int nsyms,
int pfx, int pfxbits, int bits)
{
int nsyms,
int pfx, int pfxbits, int bits)
{
- struct zlib_table *tab = smalloc(sizeof(struct zlib_table));
+ struct zlib_table *tab = snew(struct zlib_table);
int pfxmask = (1 << pfxbits) - 1;
int nbits, i, j, code;
int pfxmask = (1 << pfxbits) - 1;
int nbits, i, j, code;
- tab->table = smalloc((1 << bits) * sizeof(struct zlib_tableentry));
+ tab->table = snewn(1 << bits, struct zlib_tableentry);
tab->mask = (1 << bits) - 1;
for (code = 0; code <= tab->mask; code++) {
tab->mask = (1 << bits) - 1;
for (code = 0; code <= tab->mask; code++) {
void *zlib_decompress_init(void)
{
void *zlib_decompress_init(void)
{
- struct zlib_decompress_ctx *dctx =
- smalloc(sizeof(struct zlib_decompress_ctx));
+ struct zlib_decompress_ctx *dctx = snew(struct zlib_decompress_ctx);
unsigned char lengths[288];
memset(lengths, 8, 144);
unsigned char lengths[288];
memset(lengths, 8, 144);
dctx->winpos = (dctx->winpos + 1) & (WINSIZE - 1);
if (dctx->outlen >= dctx->outsize) {
dctx->outsize = dctx->outlen + 512;
dctx->winpos = (dctx->winpos + 1) & (WINSIZE - 1);
if (dctx->outlen >= dctx->outsize) {
dctx->outsize = dctx->outlen + 512;
- dctx->outblk = srealloc(dctx->outblk, dctx->outsize);
+ dctx->outblk = sresize(dctx->outblk, dctx->outsize, unsigned char);
}
dctx->outblk[dctx->outlen++] = c;
}
}
dctx->outblk[dctx->outlen++] = c;
}
else {
subneg_addchar:
if (telnet->sb_len >= telnet->sb_size) {
else {
subneg_addchar:
if (telnet->sb_len >= telnet->sb_size) {
telnet->sb_size += SB_DELTA;
telnet->sb_size += SB_DELTA;
- newbuf = (telnet->sb_buf ?
- srealloc(telnet->sb_buf, telnet->sb_size) :
- smalloc(telnet->sb_size));
- if (newbuf)
- telnet->sb_buf = newbuf;
- else
- telnet->sb_size -= SB_DELTA;
+ telnet->sb_buf = sresize(telnet->sb_buf, telnet->sb_size,
+ unsigned char);
- if (telnet->sb_len < telnet->sb_size)
- telnet->sb_buf[telnet->sb_len++] = c;
+ telnet->sb_buf[telnet->sb_len++] = c;
telnet->state = SUBNEGOT; /* in case we came here by goto */
}
break;
telnet->state = SUBNEGOT; /* in case we came here by goto */
}
break;
char *err;
Telnet telnet;
char *err;
Telnet telnet;
- telnet = smalloc(sizeof(*telnet));
+ telnet = snew(struct telnet_tag);
telnet->fn = &fn_table;
telnet->cfg = *cfg; /* STRUCTURE COPY */
telnet->s = NULL;
telnet->fn = &fn_table;
telnet->cfg = *cfg; /* STRUCTURE COPY */
telnet->s = NULL;
*/
oldlen = line[0];
lineattrs = line[oldlen + 1];
*/
oldlen = line[0];
lineattrs = line[oldlen + 1];
- line = srealloc(line, TSIZE * (2 + cols));
+ line = sresize(line, 2 + cols, TTYPE);
line[0] = cols;
for (i = oldlen; i < cols; i++)
line[i + 1] = ERASE_CHAR;
line[0] = cols;
for (i = oldlen; i < cols; i++)
line[i + 1] = ERASE_CHAR;
* Allocate a new Terminal structure and initialise the fields
* that need it.
*/
* Allocate a new Terminal structure and initialise the fields
* that need it.
*/
- term = smalloc(sizeof(Terminal));
term->frontend = frontend;
term->ucsdata = ucsdata;
term->cfg = *mycfg; /* STRUCTURE COPY */
term->frontend = frontend;
term->ucsdata = ucsdata;
term->cfg = *mycfg; /* STRUCTURE COPY */
term->savecurs.y += 1;
} else {
/* Add a new blank line at the bottom of the screen. */
term->savecurs.y += 1;
} else {
/* Add a new blank line at the bottom of the screen. */
- line = smalloc(TSIZE * (newcols + 2));
+ line = snewn(newcols + 2, TTYPE);
line[0] = newcols;
for (j = 0; j < newcols; j++)
line[j + 1] = ERASE_CHAR;
line[0] = newcols;
for (j = 0; j < newcols; j++)
line[j + 1] = ERASE_CHAR;
term->disptop = 0;
/* Make a new displayed text buffer. */
term->disptop = 0;
/* Make a new displayed text buffer. */
- newdisp = smalloc(newrows * (newcols + 1) * TSIZE);
+ newdisp = snewn(newrows * (newcols + 1), TTYPE);
for (i = 0; i < newrows * (newcols + 1); i++)
newdisp[i] = ATTR_INVALID;
sfree(term->disptext);
for (i = 0; i < newrows * (newcols + 1); i++)
newdisp[i] = ATTR_INVALID;
sfree(term->disptext);
/* Make a new alternate screen. */
newalt = newtree234(NULL);
for (i = 0; i < newrows; i++) {
/* Make a new alternate screen. */
newalt = newtree234(NULL);
for (i = 0; i < newrows; i++) {
- line = smalloc(TSIZE * (newcols + 2));
+ line = snewn(newcols + 2, TTYPE);
line[0] = newcols;
for (j = 0; j < newcols; j++)
line[j + 1] = term->erase_char;
line[0] = newcols;
for (j = 0; j < newcols; j++)
line[j + 1] = term->erase_char;
term->alt_screen = newalt;
term->alt_sblines = 0;
term->alt_screen = newalt;
term->alt_sblines = 0;
- term->tabs = srealloc(term->tabs, newcols * sizeof(*term->tabs));
+ term->tabs = sresize(term->tabs, newcols, unsigned char);
{
int i;
for (i = (term->cols > 0 ? term->cols : 0); i < newcols; i++)
{
int i;
for (i = (term->cols > 0 ? term->cols : 0); i < newcols; i++)
if (sblen == term->savelines) {
sblen--, line2 = delpos234(term->scrollback, 0);
} else {
if (sblen == term->savelines) {
sblen--, line2 = delpos234(term->scrollback, 0);
} else {
- line2 = smalloc(TSIZE * (term->cols + 2));
+ line2 = snewn(term->cols + 2, TTYPE);
line2[0] = term->cols;
term->tempsblines += 1;
}
line2[0] = term->cols;
term->tempsblines += 1;
}
term->scrolltail->botline == botline) {
term->scrolltail->lines += lines;
} else {
term->scrolltail->botline == botline) {
term->scrolltail->lines += lines;
} else {
- newscroll = smalloc(sizeof(struct scrollregion));
+ newscroll = snew(struct scrollregion);
newscroll->topline = topline;
newscroll->botline = botline;
newscroll->lines = lines;
newscroll->topline = topline;
newscroll->botline = botline;
newscroll->lines = lines;
ticks = GETTICKCOUNT();
if (!term->beep_overloaded) {
ticks = GETTICKCOUNT();
if (!term->beep_overloaded) {
- newbeep = smalloc(sizeof(struct beeptime));
+ newbeep = snew(struct beeptime);
newbeep->ticks = ticks;
newbeep->next = NULL;
if (!term->beephead)
newbeep->ticks = ticks;
newbeep->next = NULL;
if (!term->beephead)
int buflen; /* amount of memory allocated to workbuf */
buflen = 5120; /* Default size */
int buflen; /* amount of memory allocated to workbuf */
buflen = 5120; /* Default size */
- workbuf = smalloc(buflen * sizeof(wchar_t));
+ workbuf = snewn(buflen, wchar_t);
wbptr = workbuf; /* start filling here */
old_top_x = top.x; /* needed for rect==1 */
wbptr = workbuf; /* start filling here */
old_top_x = top.x; /* needed for rect==1 */
for (p = cbuf; *p; p++) {
/* Enough overhead for trailing NL and nul */
if (wblen >= buflen - 16) {
for (p = cbuf; *p; p++) {
/* Enough overhead for trailing NL and nul */
if (wblen >= buflen - 16) {
- workbuf =
- srealloc(workbuf,
- sizeof(wchar_t) * (buflen += 100));
+ buflen += 100;
+ workbuf = sresize(workbuf, buflen, wchar_t);
wbptr = workbuf + wblen;
}
wblen++;
wbptr = workbuf + wblen;
}
wblen++;
if (term->paste_buffer)
sfree(term->paste_buffer);
term->paste_pos = term->paste_hold = term->paste_len = 0;
if (term->paste_buffer)
sfree(term->paste_buffer);
term->paste_pos = term->paste_hold = term->paste_len = 0;
- term->paste_buffer = smalloc(len * sizeof(wchar_t));
+ term->paste_buffer = snewn(len, wchar_t);
p = q = data;
while (p < data + len) {
p = q = data;
while (p < data + len) {
int beep_overloaded;
long lastbeep;
int beep_overloaded;
long lastbeep;
-#define TSIZE (sizeof(unsigned long))
+#define TTYPE unsigned long
+#define TSIZE (sizeof(TTYPE))
#define fix_cpos do { \
term->cpos = lineptr(term->curs.y) + term->curs.x; \
} while(0)
#define fix_cpos do { \
term->cpos = lineptr(term->curs.y) + term->curs.x; \
} while(0)
-/* $Id: testback.c,v 1.6 2003/01/15 23:30:21 ben Exp $ */
+/* $Id: testback.c,v 1.7 2003/03/29 16:14:26 simon Exp $ */
/*
* Copyright (c) 1999 Simon Tatham
* Copyright (c) 1999 Ben Harris
/*
* Copyright (c) 1999 Simon Tatham
* Copyright (c) 1999 Ben Harris
static char *loop_init(void *frontend_handle, void **backend_handle,
Config *cfg, char *host, int port, char **realhost,
int nodelay) {
static char *loop_init(void *frontend_handle, void **backend_handle,
Config *cfg, char *host, int port, char **realhost,
int nodelay) {
- struct loop_state *st = smalloc(sizeof(*st));
+ struct loop_state *st = snew(struct loop_state);
st->term = frontend_handle;
*backend_handle = st;
st->term = frontend_handle;
*backend_handle = st;
#include <stdlib.h>
#include <assert.h>
#include <stdlib.h>
#include <assert.h>
-#define smalloc malloc
-#define sfree free
-
-#define mknew(typ) ( (typ *) smalloc (sizeof (typ)) )
-
#ifdef TEST
#define LOG(x) (printf x)
#else
#ifdef TEST
#define LOG(x) (printf x)
#else
*/
tree234 *newtree234(cmpfn234 cmp)
{
*/
tree234 *newtree234(cmpfn234 cmp)
{
- tree234 *ret = mknew(tree234);
+ tree234 *ret = snew(tree234);
LOG(("created tree %p\n", ret));
ret->root = NULL;
ret->cmp = cmp;
LOG(("created tree %p\n", ret));
ret->root = NULL;
ret->cmp = cmp;
LOG(("adding node %p to tree %p\n", e, t));
if (t->root == NULL) {
LOG(("adding node %p to tree %p\n", e, t));
if (t->root == NULL) {
- t->root = mknew(node234);
+ t->root = snew(node234);
t->root->elems[1] = t->root->elems[2] = NULL;
t->root->kids[0] = t->root->kids[1] = NULL;
t->root->kids[2] = t->root->kids[3] = NULL;
t->root->elems[1] = t->root->elems[2] = NULL;
t->root->kids[0] = t->root->kids[1] = NULL;
t->root->kids[2] = t->root->kids[3] = NULL;
LOG((" done\n"));
break;
} else {
LOG((" done\n"));
break;
} else {
- node234 *m = mknew(node234);
+ node234 *m = snew(node234);
m->parent = n->parent;
LOG((" splitting a 4-node; created new node %p\n", m));
/*
m->parent = n->parent;
LOG((" splitting a 4-node; created new node %p\n", m));
/*
}
} else {
LOG((" root is overloaded, split into two\n"));
}
} else {
LOG((" root is overloaded, split into two\n"));
- t->root = mknew(node234);
+ t->root = snew(node234);
t->root->kids[0] = left;
t->root->counts[0] = lcount;
t->root->elems[0] = e;
t->root->kids[0] = left;
t->root->counts[0] = lcount;
t->root->elems[0] = e;
-#define srealloc realloc
-
/*
* Error reporting function.
*/
/*
* Error reporting function.
*/
if (arraysize < arraylen + 1) {
arraysize = arraylen + 1 + 256;
if (arraysize < arraylen + 1) {
arraysize = arraylen + 1 + 256;
- array = (array == NULL ? smalloc(arraysize * sizeof(*array)) :
- srealloc(array, arraysize * sizeof(*array)));
+ array = sresize(array, arraysize, void *);
if (DIRECT_FONT(ucsdata->unitab_line[i]))
continue;
if (!ucsdata->uni_tbl) {
if (DIRECT_FONT(ucsdata->unitab_line[i]))
continue;
if (!ucsdata->uni_tbl) {
- ucsdata->uni_tbl = smalloc(256 * sizeof(char *));
+ ucsdata->uni_tbl = snewn(256, char *);
memset(ucsdata->uni_tbl, 0, 256 * sizeof(char *));
}
j = ((ucsdata->unitab_line[i] >> 8) & 0xFF);
if (!ucsdata->uni_tbl[j]) {
memset(ucsdata->uni_tbl, 0, 256 * sizeof(char *));
}
j = ((ucsdata->unitab_line[i] >> 8) & 0xFF);
if (!ucsdata->uni_tbl[j]) {
- ucsdata->uni_tbl[j] = smalloc(256 * sizeof(char));
+ ucsdata->uni_tbl[j] = snewn(256, char);
memset(ucsdata->uni_tbl[j], 0, 256 * sizeof(char));
}
ucsdata->uni_tbl[j][ucsdata->unitab_line[i] & 0xFF] = i;
memset(ucsdata->uni_tbl[j], 0, 256 * sizeof(char));
}
ucsdata->uni_tbl[j][ucsdata->unitab_line[i] & 0xFF] = i;
{
struct dlgparam *dp = (struct dlgparam *)dlg;
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
{
struct dlgparam *dp = (struct dlgparam *)dlg;
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
+ /*
+ * This is an internal allocation routine, so it's allowed to
+ * use smalloc directly.
+ */
uc->privdata = smalloc(size);
uc->privdata_needs_free = FALSE;
return uc->privdata;
uc->privdata = smalloc(size);
uc->privdata_needs_free = FALSE;
return uc->privdata;
assert(ncols <=
(uc->ctrl->listbox.ncols ? uc->ctrl->listbox.ncols : 1));
assert(ncols <=
(uc->ctrl->listbox.ncols ? uc->ctrl->listbox.ncols : 1));
- percents = smalloc(ncols * sizeof(gint));
+ percents = snewn(ncols, gint);
percents[ncols-1] = 100;
for (i = 0; i < ncols-1; i++) {
percents[i] = uc->ctrl->listbox.percentages[i];
percents[ncols-1] = 100;
for (i = 0; i < ncols-1; i++) {
percents[i] = uc->ctrl->listbox.percentages[i];
continue; /* no actual control created */
}
continue; /* no actual control created */
}
- uc = smalloc(sizeof(struct uctrl));
+ uc = snew(struct uctrl);
uc->ctrl = ctrl;
uc->privdata = NULL;
uc->privdata_needs_free = FALSE;
uc->ctrl = ctrl;
uc->privdata = NULL;
uc->privdata_needs_free = FALSE;
group = NULL;
uc->nbuttons = ctrl->radio.nbuttons;
group = NULL;
uc->nbuttons = ctrl->radio.nbuttons;
- uc->buttons = smalloc(uc->nbuttons * sizeof(GtkWidget *));
+ uc->buttons = snewn(uc->nbuttons, GtkWidget *);
for (i = 0; i < ctrl->radio.nbuttons; i++) {
GtkWidget *b;
for (i = 0; i < ctrl->radio.nbuttons; i++) {
GtkWidget *b;
if (nselparams >= selparamsize) {
selparamsize += 16;
if (nselparams >= selparamsize) {
selparamsize += 16;
- selparams = srealloc(selparams,
- selparamsize * sizeof(*selparams));
+ selparams = sresize(selparams, selparamsize,
+ struct selparam);
}
selparams[nselparams].dp = &dp;
selparams[nselparams].panels = PANELS(panels);
}
selparams[nselparams].dp = &dp;
selparams[nselparams].panels = PANELS(panels);
}
dp.ntreeitems = nselparams;
}
dp.ntreeitems = nselparams;
- dp.treeitems = smalloc(dp.ntreeitems * sizeof(GtkWidget *));
+ dp.treeitems = snewn(dp.ntreeitems, GtkWidget *);
for (index = 0; index < nselparams; index++) {
gtk_signal_connect(GTK_OBJECT(selparams[index].treeitem), "select",
for (index = 0; index < nselparams; index++) {
gtk_signal_connect(GTK_OBJECT(selparams[index].treeitem), "select",
wchar_t *tmp = data;
int tmplen = len;
wchar_t *tmp = data;
int tmplen = len;
- inst->pasteout_data_utf8 = smalloc(len*6);
+ inst->pasteout_data_utf8 = snewn(len*6, char);
inst->pasteout_data_utf8_len = len*6;
inst->pasteout_data_utf8_len =
charset_from_unicode(&tmp, &tmplen, inst->pasteout_data_utf8,
inst->pasteout_data_utf8_len = len*6;
inst->pasteout_data_utf8_len =
charset_from_unicode(&tmp, &tmplen, inst->pasteout_data_utf8,
inst->pasteout_data_utf8 = NULL;
} else {
inst->pasteout_data_utf8 =
inst->pasteout_data_utf8 = NULL;
} else {
inst->pasteout_data_utf8 =
- srealloc(inst->pasteout_data_utf8,
- inst->pasteout_data_utf8_len);
+ sresize(inst->pasteout_data_utf8,
+ inst->pasteout_data_utf8_len, char);
}
} else {
inst->pasteout_data_utf8 = NULL;
inst->pasteout_data_utf8_len = 0;
}
}
} else {
inst->pasteout_data_utf8 = NULL;
inst->pasteout_data_utf8_len = 0;
}
- inst->pasteout_data = smalloc(len*6);
+ inst->pasteout_data = snewn(len*6, char);
inst->pasteout_data_len = len*6;
inst->pasteout_data_len = wc_to_mb(inst->ucsdata.line_codepage, 0,
data, len, inst->pasteout_data,
inst->pasteout_data_len = len*6;
inst->pasteout_data_len = wc_to_mb(inst->ucsdata.line_codepage, 0,
data, len, inst->pasteout_data,
inst->pasteout_data = NULL;
} else {
inst->pasteout_data =
inst->pasteout_data = NULL;
} else {
inst->pasteout_data =
- srealloc(inst->pasteout_data, inst->pasteout_data_len);
+ sresize(inst->pasteout_data, inst->pasteout_data_len, char);
}
if (gtk_selection_owner_set(inst->area, GDK_SELECTION_PRIMARY,
}
if (gtk_selection_owner_set(inst->area, GDK_SELECTION_PRIMARY,
if (inst->pastein_data)
sfree(inst->pastein_data);
if (inst->pastein_data)
sfree(inst->pastein_data);
- inst->pastein_data = smalloc(seldata->length * sizeof(wchar_t));
+ inst->pastein_data = snewn(seldata->length, wchar_t);
inst->pastein_data_len = seldata->length;
inst->pastein_data_len =
mb_to_wc((seldata->type == inst->utf8_string_atom ?
inst->pastein_data_len = seldata->length;
inst->pastein_data_len =
mb_to_wc((seldata->type == inst->utf8_string_atom ?
if (!inst->area->window)
return NULL;
if (!inst->area->window)
return NULL;
- dctx = smalloc(sizeof(*dctx));
+ dctx = snew(struct draw_ctx);
dctx->inst = inst;
dctx->gc = gdk_gc_new(inst->area->window);
return dctx;
dctx->inst = inst;
dctx->gc = gdk_gc_new(inst->area->window);
return dctx;
- wcs = smalloc(sizeof(wchar_t) * (len+1));
+ wcs = snewn(len+1, wchar_t);
for (i = 0; i < len; i++) {
wcs[i] = (wchar_t) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
}
for (i = 0; i < len; i++) {
wcs[i] = (wchar_t) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
}
* and (c) the clip rectangle should prevent it causing
* trouble anyway.
*/
* and (c) the clip rectangle should prevent it causing
* trouble anyway.
*/
- gwcs = smalloc(sizeof(GdkWChar) * (len*2+1));
+ gwcs = snewn(len*2+1, GdkWChar);
memset(gwcs, 0, sizeof(GdkWChar) * (len*2+1));
/*
* FIXME: when we have a wide-char equivalent of
memset(gwcs, 0, sizeof(GdkWChar) * (len*2+1));
/*
* FIXME: when we have a wide-char equivalent of
gwcs, len*2);
sfree(gwcs);
} else {
gwcs, len*2);
sfree(gwcs);
} else {
- gcs = smalloc(sizeof(GdkWChar) * (len+1));
+ gcs = snewn(len+1, gchar);
wc_to_mb(inst->fontinfo[fontid].charset, 0,
wcs, len, gcs, len, ".", NULL, NULL);
gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
wc_to_mb(inst->fontinfo[fontid].charset, 0,
wcs, len, gcs, len, ".", NULL, NULL);
gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
- pty_argv = smalloc((argc+1) * sizeof(char *));
+ pty_argv = snewn(argc+1, char *);
++argv;
for (i = 0; i < argc; i++)
pty_argv[i] = argv[i];
++argv;
for (i = 0; i < argc; i++)
pty_argv[i] = argv[i];
/*
* Create an instance structure and initialise to zeroes
*/
/*
* Create an instance structure and initialise to zeroes
*/
- inst = smalloc(sizeof(*inst));
+ inst = snew(struct gui_data);
memset(inst, 0, sizeof(*inst));
inst->alt_keycode = -1; /* this one needs _not_ to be zero */
memset(inst, 0, sizeof(*inst));
inst->alt_keycode = -1; /* this one needs _not_ to be zero */
char *shellname;
if (cfg->login_shell) {
char *p = strrchr(shell, '/');
char *shellname;
if (cfg->login_shell) {
char *p = strrchr(shell, '/');
- shellname = smalloc(2+strlen(shell));
+ shellname = snewn(2+strlen(shell), char);
p = p ? p+1 : shell;
sprintf(shellname, "-%s", p);
} else
p = p ? p+1 : shell;
sprintf(shellname, "-%s", p);
} else
if (!fp)
return; /* assume no auth */
if (!fp)
return; /* assume no auth */
- localbuf = smalloc(maxsize);
+ localbuf = snewn(maxsize, char);
}
retsize += 4;
assert(retbuf == sizebuf);
}
retsize += 4;
assert(retbuf == sizebuf);
- retbuf = smalloc(retsize);
+ retbuf = snewn(retsize, char);
memcpy(retbuf, sizebuf, 4);
}
}
memcpy(retbuf, sizebuf, 4);
}
}
SockAddr sk_namelookup(const char *host, char **canonicalname)
{
SockAddr sk_namelookup(const char *host, char **canonicalname)
{
- SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+ SockAddr ret = snew(struct SockAddr_tag);
unsigned long a;
struct hostent *h = NULL;
char realhost[8192];
unsigned long a;
struct hostent *h = NULL;
char realhost[8192];
}
ret->address = ntohl(a);
realhost[lenof(realhost)-1] = '\0';
}
ret->address = ntohl(a);
realhost[lenof(realhost)-1] = '\0';
- *canonicalname = smalloc(1+strlen(realhost));
+ *canonicalname = snewn(1+strlen(realhost), char);
strcpy(*canonicalname, realhost);
return ret;
}
SockAddr sk_nonamelookup(const char *host)
{
strcpy(*canonicalname, realhost);
return ret;
}
SockAddr sk_nonamelookup(const char *host)
{
- SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+ SockAddr ret = snew(struct SockAddr_tag);
ret->error = NULL;
ret->family = AF_UNSPEC;
strncpy(ret->hostname, host, lenof(ret->hostname));
ret->error = NULL;
ret->family = AF_UNSPEC;
strncpy(ret->hostname, host, lenof(ret->hostname));
/*
* Create Socket structure.
*/
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
/*
* Create Socket structure.
*/
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
/*
* Create Socket structure.
*/
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
while (*p) {
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
while (*p) {
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
- command = srealloc(command, cmdsize);
+ command = sresize(command, cmdsize, char);
}
command[cmdlen++]=*p++;
}
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
}
command[cmdlen++]=*p++;
}
if (cmdlen >= cmdsize) {
cmdsize = cmdlen + 512;
- command = srealloc(command, cmdsize);
+ command = sresize(command, cmdsize, char);
}
command[cmdlen++]=' '; /* always add trailing space */
if (--argc) p = *++argv;
}
command[cmdlen++]=' '; /* always add trailing space */
if (--argc) p = *++argv;
/* Expand the sklist buffer if necessary. */
if (i > sksize) {
sksize = i + 16;
/* Expand the sklist buffer if necessary. */
if (i > sksize) {
sksize = i + 16;
- sklist = srealloc(sklist, sksize * sizeof(*sklist));
+ sklist = sresize(sklist, sksize, int);
printer_job *printer_start_job(char *printer)
{
printer_job *printer_start_job(char *printer)
{
- printer_job *ret = smalloc(sizeof(printer_job));
+ printer_job *ret = snew(printer_job);
/*
* On Unix, we treat the printer string as the name of a
* command to pipe to - typically lpr, of course.
/*
* On Unix, we treat the printer string as the name of a
* command to pipe to - typically lpr, of course.
q++;
while (p > string && p[-1] != '.' && p[-1] != '*')
p--;
q++;
while (p > string && p[-1] != '.' && p[-1] != '*')
p--;
- xrms = smalloc(sizeof(struct xrm_string));
- key = smalloc(q-p);
+ xrms = snew(struct xrm_string);
+ key = snewn(q-p, char);
memcpy(key, p, q-p);
key[q-p-1] = '\0';
xrms->key = key;
memcpy(key, p, q-p);
key[q-p-1] = '\0';
xrms->key = key;
*/
static char *fgetline(FILE *fp)
{
*/
static char *fgetline(FILE *fp)
{
- char *ret = smalloc(512);
+ char *ret = snewn(512, char);
int size = 512, len = 0;
while (fgets(ret + len, size - len, fp)) {
len += strlen(ret + len);
if (ret[len-1] == '\n')
break; /* got a newline, we're done */
size = len + 512;
int size = 512, len = 0;
while (fgets(ret + len, size - len, fp)) {
len += strlen(ret + len);
if (ret[len-1] == '\n')
break; /* got a newline, we're done */
size = len + 512;
- ret = srealloc(ret, size);
+ ret = sresize(ret, size, char);
}
if (len == 0) { /* first fgets returned NULL */
sfree(ret);
}
if (len == 0) { /* first fgets returned NULL */
sfree(ret);
assert(c->generic.handler == dlg_stdradiobutton_handler);
c->radio.nbuttons++;
c->radio.buttons =
assert(c->generic.handler == dlg_stdradiobutton_handler);
c->radio.nbuttons++;
c->radio.buttons =
- srealloc(c->radio.buttons,
- c->radio.nbuttons * sizeof(*c->radio.buttons));
+ sresize(c->radio.buttons, c->radio.nbuttons, char *);
c->radio.buttons[c->radio.nbuttons-1] =
dupstr("Play a custom sound file");
c->radio.buttondata =
c->radio.buttons[c->radio.nbuttons-1] =
dupstr("Play a custom sound file");
c->radio.buttondata =
- srealloc(c->radio.buttondata,
- c->radio.nbuttons * sizeof(*c->radio.buttondata));
+ sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
c->radio.buttondata[c->radio.nbuttons-1] = I(BELL_WAVEFILE);
if (c->radio.shortcuts) {
c->radio.shortcuts =
c->radio.buttondata[c->radio.nbuttons-1] = I(BELL_WAVEFILE);
if (c->radio.shortcuts) {
c->radio.shortcuts =
- srealloc(c->radio.shortcuts,
- (c->radio.nbuttons *
- sizeof(*c->radio.shortcuts)));
+ sresize(c->radio.shortcuts, c->radio.nbuttons, char);
c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT;
}
break;
c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT;
}
break;
assert(c->generic.handler == dlg_stdradiobutton_handler);
c->radio.nbuttons += 2;
c->radio.buttons =
assert(c->generic.handler == dlg_stdradiobutton_handler);
c->radio.nbuttons += 2;
c->radio.buttons =
- srealloc(c->radio.buttons,
- c->radio.nbuttons * sizeof(*c->radio.buttons));
+ sresize(c->radio.buttons, c->radio.nbuttons, char *);
c->radio.buttons[c->radio.nbuttons-2] =
dupstr("Use font in both ANSI and OEM modes");
c->radio.buttons[c->radio.nbuttons-1] =
dupstr("Use font in OEM mode only");
c->radio.buttondata =
c->radio.buttons[c->radio.nbuttons-2] =
dupstr("Use font in both ANSI and OEM modes");
c->radio.buttons[c->radio.nbuttons-1] =
dupstr("Use font in OEM mode only");
c->radio.buttondata =
- srealloc(c->radio.buttondata,
- c->radio.nbuttons * sizeof(*c->radio.buttondata));
+ sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
c->radio.buttondata[c->radio.nbuttons-2] = I(VT_OEMANSI);
c->radio.buttondata[c->radio.nbuttons-1] = I(VT_OEMONLY);
if (!c->radio.shortcuts) {
int j;
c->radio.buttondata[c->radio.nbuttons-2] = I(VT_OEMANSI);
c->radio.buttondata[c->radio.nbuttons-1] = I(VT_OEMONLY);
if (!c->radio.shortcuts) {
int j;
- c->radio.shortcuts =
- smalloc((c->radio.nbuttons *
- sizeof(*c->radio.shortcuts)));
+ c->radio.shortcuts = snewn(c->radio.nbuttons, char);
for (j = 0; j < c->radio.nbuttons; j++)
c->radio.shortcuts[j] = NO_SHORTCUT;
} else {
for (j = 0; j < c->radio.nbuttons; j++)
c->radio.shortcuts[j] = NO_SHORTCUT;
} else {
- c->radio.shortcuts =
- srealloc(c->radio.shortcuts,
- (c->radio.nbuttons *
- sizeof(*c->radio.shortcuts)));
+ c->radio.shortcuts = sresize(c->radio.shortcuts,
+ c->radio.nbuttons, char);
}
c->radio.shortcuts[c->radio.nbuttons-2] = 'b';
c->radio.shortcuts[c->radio.nbuttons-1] = 'e';
}
c->radio.shortcuts[c->radio.nbuttons-2] = 'b';
c->radio.shortcuts[c->radio.nbuttons-1] = 'e';
bid = va_arg(ap, int);
}
va_end(ap);
bid = va_arg(ap, int);
}
va_end(ap);
- buttons = smalloc(nbuttons * sizeof(struct radio));
+ buttons = snewn(nbuttons, struct radio);
va_start(ap, nacross);
for (i = 0; i < nbuttons; i++) {
buttons[i].text = va_arg(ap, char *);
va_start(ap, nacross);
for (i = 0; i < nbuttons; i++) {
buttons[i].text = va_arg(ap, char *);
bid = va_arg(ap, int);
}
va_end(ap);
bid = va_arg(ap, int);
}
va_end(ap);
- buttons = smalloc(nbuttons * sizeof(struct radio));
+ buttons = snewn(nbuttons, struct radio);
va_start(ap, nacross);
for (i = 0; i < nbuttons; i++) {
buttons[i].text = va_arg(ap, char *);
va_start(ap, nacross);
for (i = 0; i < nbuttons; i++) {
buttons[i].text = va_arg(ap, char *);
bid = va_arg(ap, int);
}
va_end(ap);
bid = va_arg(ap, int);
}
va_end(ap);
- buttons = smalloc(nbuttons * sizeof(struct radio));
+ buttons = snewn(nbuttons, struct radio);
va_start(ap, id);
for (i = 0; i < nbuttons; i++) {
buttons[i].text = va_arg(ap, char *);
va_start(ap, id);
for (i = 0; i < nbuttons; i++) {
buttons[i].text = va_arg(ap, char *);
RECT r;
HFONT oldfont, newfont;
RECT r;
HFONT oldfont, newfont;
- ret = smalloc(1+strlen(text));
+ ret = snewn(1+strlen(text), char);
- pwidths = smalloc(sizeof(INT)*(1+strlen(text)));
+ pwidths = snewn(1+strlen(text), INT);
/*
* Work out the width the text will need to fit in, by doing
/*
* Work out the width the text will need to fit in, by doing
char *txt;
/* Get the item's data. */
tlen = SendDlgItemMessage (hwnd, listid, LB_GETTEXTLEN, src, 0);
char *txt;
/* Get the item's data. */
tlen = SendDlgItemMessage (hwnd, listid, LB_GETTEXTLEN, src, 0);
+ txt = snewn(tlen+1, char);
SendDlgItemMessage (hwnd, listid, LB_GETTEXT, src, (LPARAM) txt);
val = SendDlgItemMessage (hwnd, listid, LB_GETITEMDATA, src, 0);
/* Deselect old location. */
SendDlgItemMessage (hwnd, listid, LB_GETTEXT, src, (LPARAM) txt);
val = SendDlgItemMessage (hwnd, listid, LB_GETITEMDATA, src, 0);
/* Deselect old location. */
if (!text)
return NULL; /* sfree won't choke on this */
if (!text)
return NULL; /* sfree won't choke on this */
- ret = smalloc(2*strlen(text)+1); /* size potentially doubles! */
+ ret = snewn(2*strlen(text)+1, char); /* size potentially doubles! */
shortcut = tolower((unsigned char)shortcut);
p = text;
shortcut = tolower((unsigned char)shortcut);
p = text;
/* Start a containing box, if we have a boxname. */
if (s->boxname && *s->boxname) {
/* Start a containing box, if we have a boxname. */
if (s->boxname && *s->boxname) {
- struct winctrl *c = smalloc(sizeof(struct winctrl));
+ struct winctrl *c = snew(struct winctrl);
c->ctrl = NULL;
c->base_id = base_id;
c->num_ids = 1;
c->ctrl = NULL;
c->base_id = base_id;
c->num_ids = 1;
/* Draw a title, if we have one. */
if (!s->boxname && s->boxtitle) {
/* Draw a title, if we have one. */
if (!s->boxname && s->boxtitle) {
- struct winctrl *c = smalloc(sizeof(struct winctrl));
+ struct winctrl *c = snew(struct winctrl);
c->ctrl = NULL;
c->base_id = base_id;
c->num_ids = 1;
c->ctrl = NULL;
c->base_id = base_id;
c->num_ids = 1;
ctrl->radio.shortcut);
shortcuts[nshortcuts++] = ctrl->radio.shortcut;
ctrl->radio.shortcut);
shortcuts[nshortcuts++] = ctrl->radio.shortcut;
- buttons = smalloc(ctrl->radio.nbuttons * sizeof(struct radio));
+ buttons = snewn(ctrl->radio.nbuttons, struct radio);
for (i = 0; i < ctrl->radio.nbuttons; i++) {
buttons[i].text =
for (i = 0; i < ctrl->radio.nbuttons; i++) {
buttons[i].text =
ctrl->listbox.shortcut);
shortcuts[nshortcuts++] = ctrl->listbox.shortcut;
if (ctrl->listbox.draglist) {
ctrl->listbox.shortcut);
shortcuts[nshortcuts++] = ctrl->listbox.shortcut;
if (ctrl->listbox.draglist) {
- data = smalloc(sizeof(struct prefslist));
+ data = snew(struct prefslist);
num_ids = 4;
prefslist(data, &pos, ctrl->listbox.height, escaped,
base_id, base_id+1, base_id+2, base_id+3);
num_ids = 4;
prefslist(data, &pos, ctrl->listbox.height, escaped,
base_id, base_id+1, base_id+2, base_id+3);
int *tabarray;
int i, percent;
int *tabarray;
int i, percent;
- tabarray = smalloc((ctrl->listbox.ncols-1) * sizeof(int));
+ tabarray = snewn(ctrl->listbox.ncols-1, int);
percent = 0;
for (i = 0; i < ctrl->listbox.ncols-1; i++) {
percent += ctrl->listbox.percentages[i];
percent = 0;
for (i = 0; i < ctrl->listbox.ncols-1; i++) {
percent += ctrl->listbox.percentages[i];
statictext(&pos, escaped, 1, base_id);
staticbtn(&pos, "", base_id+1, "Change...", base_id+2);
sfree(escaped);
statictext(&pos, escaped, 1, base_id);
staticbtn(&pos, "", base_id+1, "Change...", base_id+2);
sfree(escaped);
- data = smalloc(sizeof(FontSpec));
break;
default:
assert(!"Can't happen");
break;
default:
assert(!"Can't happen");
* (and isn't tabdelayed).
*/
if (pos.hwnd) {
* (and isn't tabdelayed).
*/
if (pos.hwnd) {
- struct winctrl *c = smalloc(sizeof(struct winctrl));
+ struct winctrl *c = snew(struct winctrl);
c->ctrl = ctrl;
c->base_id = actual_base_id;
c->ctrl = ctrl;
c->base_id = actual_base_id;
CB_GETCURSEL, 0, 0);
len = SendDlgItemMessage(dp->hwnd, c->base_id+1,
CB_GETLBTEXTLEN, index, 0);
CB_GETCURSEL, 0, 0);
len = SendDlgItemMessage(dp->hwnd, c->base_id+1,
CB_GETLBTEXTLEN, index, 0);
+ text = snewn(len+1, char);
SendDlgItemMessage(dp->hwnd, c->base_id+1, CB_GETLBTEXT,
index, (LPARAM)text);
SetDlgItemText(dp->hwnd, c->base_id+1, text);
SendDlgItemMessage(dp->hwnd, c->base_id+1, CB_GETLBTEXT,
index, (LPARAM)text);
SetDlgItemText(dp->hwnd, c->base_id+1, text);
tmp.ctrl = ctrl;
p = find234(dp->privdata, &tmp, NULL);
if (!p) {
tmp.ctrl = ctrl;
p = find234(dp->privdata, &tmp, NULL);
if (!p) {
- p = smalloc(sizeof(struct perctrl_privdata));
+ p = snew(struct perctrl_privdata);
p->ctrl = ctrl;
p->needs_free = FALSE;
add234(dp->privdata, p);
p->ctrl = ctrl;
p->needs_free = FALSE;
add234(dp->privdata, p);
tmp.ctrl = ctrl;
p = find234(dp->privdata, &tmp, NULL);
if (!p) {
tmp.ctrl = ctrl;
p = find234(dp->privdata, &tmp, NULL);
if (!p) {
- p = smalloc(sizeof(struct perctrl_privdata));
+ p = snew(struct perctrl_privdata);
p->ctrl = ctrl;
p->needs_free = FALSE;
add234(dp->privdata, p);
}
assert(!p->needs_free);
p->needs_free = TRUE;
p->ctrl = ctrl;
p->needs_free = FALSE;
add234(dp->privdata, p);
}
assert(!p->needs_free);
p->needs_free = TRUE;
+ /*
+ * This is an internal allocation routine, so it's allowed to
+ * use smalloc directly.
+ */
p->data = smalloc(size);
return p->data;
}
p->data = smalloc(size);
return p->data;
}
- selitems = smalloc(selcount * sizeof(int));
+ selitems = snewn(selcount, int);
if (selitems) {
int count = SendDlgItemMessage(hwnd, IDN_LIST,
LB_GETSELITEMS,
if (selitems) {
int count = SendDlgItemMessage(hwnd, IDN_LIST,
LB_GETSELITEMS,
size +=
strlen(events[selitems[i]]) + sizeof(sel_nl);
size +=
strlen(events[selitems[i]]) + sizeof(sel_nl);
- clipdata = smalloc(size);
+ clipdata = snewn(size, char);
if (clipdata) {
char *p = clipdata;
for (i = 0; i < count; i++) {
if (clipdata) {
char *p = clipdata;
for (i = 0; i < count; i++) {
if (nevents >= negsize) {
negsize += 64;
if (nevents >= negsize) {
negsize += 64;
- events = srealloc(events, negsize * sizeof(*events));
+ events = sresize(events, negsize, char *);
}
time(&t);
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
localtime(&t));
}
time(&t);
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
localtime(&t));
- events[nevents] = smalloc(strlen(timebuf) + strlen(string) + 1);
+ events[nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
strcpy(events[nevents], timebuf);
strcat(events[nevents], string);
if (logbox) {
strcpy(events[nevents], timebuf);
strcat(events[nevents], string);
if (logbox) {
{
char *bits;
int size = (font_width + 15) / 16 * 2 * font_height;
{
char *bits;
int size = (font_width + 15) / 16 * 2 * font_height;
+ bits = snewn(size, char);
memset(bits, 0, size);
caretbm = CreateBitmap(font_width, font_height, 1, 1, bits);
sfree(bits);
memset(bits, 0, size);
caretbm = CreateBitmap(font_width, font_height, 1, 1, bits);
sfree(bits);
HDC hdc = GetDC(hwnd);
if (hdc) {
if (cfg.try_palette && GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) {
HDC hdc = GetDC(hwnd);
if (hdc) {
if (cfg.try_palette && GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) {
+ /*
+ * This is a genuine case where we must use smalloc
+ * because the snew macros can't cope.
+ */
logpal = smalloc(sizeof(*logpal)
- sizeof(logpal->palPalEntry)
+ NCOLOURS * sizeof(PALETTEENTRY));
logpal = smalloc(sizeof(*logpal)
- sizeof(logpal->palPalEntry)
+ NCOLOURS * sizeof(PALETTEENTRY));
if ((lParam - IDM_SAVED_MIN) / 16 < sesslist.nsessions) {
char *session =
sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
if ((lParam - IDM_SAVED_MIN) / 16 < sesslist.nsessions) {
char *session =
sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
- cl = smalloc(16 + strlen(session));
+ cl = snewn(16 + strlen(session), char);
/* 8, but play safe */
if (!cl)
cl = NULL;
/* 8, but play safe */
if (!cl)
cl = NULL;
- buff = (char*) smalloc(n);
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
/*
* Jaeyoun Chung reports that Korean character
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
/*
* Jaeyoun Chung reports that Korean character
int i;
if (len > IpDxLEN) {
sfree(IpDx);
int i;
if (len > IpDxLEN) {
sfree(IpDx);
- IpDx = smalloc((len + 16) * sizeof(int));
+ IpDx = snewn(len + 16, int);
IpDxLEN = (len + 16);
}
for (i = 0; i < IpDxLEN; i++)
IpDxLEN = (len + 16);
}
for (i = 0; i < IpDxLEN; i++)
int nlen, mptr;
if (len > uni_len) {
sfree(uni_buf);
int nlen, mptr;
if (len > uni_len) {
sfree(uni_buf);
- uni_buf = smalloc((uni_len = len) * sizeof(wchar_t));
+ uni_len = len;
+ uni_buf = snewn(uni_len, wchar_t);
}
for(nlen = mptr = 0; mptr<len; mptr++) {
}
for(nlen = mptr = 0; mptr<len; mptr++) {
if (wlen < len) {
sfree(wbuf);
wlen = len;
if (wlen < len) {
sfree(wbuf);
wlen = len;
- wbuf = smalloc(wlen * sizeof(WCHAR));
+ wbuf = snewn(wlen, WCHAR);
}
for (i = 0; i < len; i++)
wbuf[i] = (WCHAR) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
}
for (i = 0; i < len; i++)
wbuf[i] = (WCHAR) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
void set_title(void *frontend, char *title)
{
sfree(window_name);
void set_title(void *frontend, char *title)
{
sfree(window_name);
- window_name = smalloc(1 + strlen(title));
+ window_name = snewn(1 + strlen(title), char);
strcpy(window_name, title);
if (cfg.win_name_always || !IsIconic(hwnd))
SetWindowText(hwnd, title);
strcpy(window_name, title);
if (cfg.win_name_always || !IsIconic(hwnd))
SetWindowText(hwnd, title);
void set_icon(void *frontend, char *title)
{
sfree(icon_name);
void set_icon(void *frontend, char *title)
{
sfree(icon_name);
- icon_name = smalloc(1 + strlen(title));
+ icon_name = snewn(1 + strlen(title), char);
strcpy(icon_name, title);
if (!cfg.win_name_always && IsIconic(hwnd))
SetWindowText(hwnd, title);
strcpy(icon_name, title);
if (!cfg.win_name_always && IsIconic(hwnd))
SetWindowText(hwnd, title);
get_unitab(CP_ACP, unitab, 0);
rtfsize = 100 + strlen(cfg.font.name);
get_unitab(CP_ACP, unitab, 0);
rtfsize = 100 + strlen(cfg.font.name);
- rtf = smalloc(rtfsize);
+ rtf = snewn(rtfsize, char);
sprintf(rtf, "{\\rtf1\\ansi%d{\\fonttbl\\f0\\fmodern %s;}\\f0",
GetACP(), cfg.font.name);
rtflen = strlen(rtf);
sprintf(rtf, "{\\rtf1\\ansi%d{\\fonttbl\\f0\\fmodern %s;}\\f0",
GetACP(), cfg.font.name);
rtflen = strlen(rtf);
if (rtfsize < rtflen + totallen + 3) {
rtfsize = rtflen + totallen + 512;
if (rtfsize < rtflen + totallen + 3) {
rtfsize = rtflen + totallen + 512;
- rtf = srealloc(rtf, rtfsize);
+ rtf = sresize(rtf, rtfsize, char);
}
strcpy(rtf + rtflen, before); rtflen += blen;
}
strcpy(rtf + rtflen, before); rtflen += blen;
CloseClipboard();
s = GlobalLock(clipdata);
i = MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, 0, 0);
CloseClipboard();
s = GlobalLock(clipdata);
i = MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, 0, 0);
- *p = converted = smalloc(i * sizeof(wchar_t));
+ *p = converted = snewn(i, wchar_t);
MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, converted, i);
*len = i - 1;
return;
MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, converted, i);
*len = i - 1;
return;
SockAddr sk_namelookup(const char *host, char **canonicalname)
{
SockAddr sk_namelookup(const char *host, char **canonicalname)
{
- SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+ SockAddr ret = snew(struct SockAddr_tag);
unsigned long a;
struct hostent *h = NULL;
char realhost[8192];
unsigned long a;
struct hostent *h = NULL;
char realhost[8192];
}
ret->address = ntohl(a);
realhost[lenof(realhost)-1] = '\0';
}
ret->address = ntohl(a);
realhost[lenof(realhost)-1] = '\0';
- *canonicalname = smalloc(1+strlen(realhost));
+ *canonicalname = snewn(1+strlen(realhost), char);
strcpy(*canonicalname, realhost);
return ret;
}
SockAddr sk_nonamelookup(const char *host)
{
strcpy(*canonicalname, realhost);
return ret;
}
SockAddr sk_nonamelookup(const char *host)
{
- SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
+ SockAddr ret = snew(struct SockAddr_tag);
ret->error = NULL;
ret->family = AF_UNSPEC;
strncpy(ret->hostname, host, lenof(ret->hostname));
ret->error = NULL;
ret->family = AF_UNSPEC;
strncpy(ret->hostname, host, lenof(ret->hostname));
/*
* Create Socket structure.
*/
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &fn_table;
ret->error = NULL;
ret->plug = plug;
ret->fn = &fn_table;
ret->error = NULL;
ret->plug = plug;
/*
* Create Socket structure.
*/
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &fn_table;
ret->error = NULL;
ret->plug = plug;
ret->fn = &fn_table;
ret->error = NULL;
ret->plug = plug;
/*
* Create Socket structure.
*/
/*
* Create Socket structure.
*/
- ret = smalloc(sizeof(struct Socket_tag));
+ ret = snew(struct Socket_tag);
ret->fn = &fn_table;
ret->error = NULL;
ret->plug = plug;
ret->fn = &fn_table;
ret->error = NULL;
ret->plug = plug;
if (!sessionname || !*sessionname)
sessionname = "Default Settings";
if (!sessionname || !*sessionname)
sessionname = "Default Settings";
- p = smalloc(3 * strlen(sessionname) + 1);
+ p = snewn(3 * strlen(sessionname) + 1, char);
mungestr(sessionname, p);
ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
mungestr(sessionname, p);
ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
if (!sessionname || !*sessionname)
sessionname = "Default Settings";
if (!sessionname || !*sessionname)
sessionname = "Default Settings";
- p = smalloc(3 * strlen(sessionname) + 1);
+ p = snewn(3 * strlen(sessionname) + 1, char);
mungestr(sessionname, p);
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
mungestr(sessionname, p);
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
return;
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
return;
- p = smalloc(3 * strlen(sessionname) + 1);
+ p = snewn(3 * strlen(sessionname) + 1, char);
mungestr(sessionname, p);
RegDeleteKey(subkey1, p);
sfree(p);
mungestr(sessionname, p);
RegDeleteKey(subkey1, p);
sfree(p);
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)
return NULL;
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)
return NULL;
- ret = smalloc(sizeof(*ret));
+ ret = snew(struct enumsettings);
if (ret) {
ret->key = key;
ret->i = 0;
if (ret) {
ret->key = key;
ret->i = 0;
{
struct enumsettings *e = (struct enumsettings *) handle;
char *otherbuf;
{
struct enumsettings *e = (struct enumsettings *) handle;
char *otherbuf;
- otherbuf = smalloc(3 * buflen);
+ otherbuf = snewn(3 * buflen, char);
if (RegEnumKey(e->key, e->i++, otherbuf, 3 * buflen) == ERROR_SUCCESS) {
unmungestr(otherbuf, buffer, buflen);
sfree(otherbuf);
if (RegEnumKey(e->key, e->i++, otherbuf, 3 * buflen) == ERROR_SUCCESS) {
unmungestr(otherbuf, buffer, buflen);
sfree(otherbuf);
* Now read a saved key in from the registry and see what it
* says.
*/
* Now read a saved key in from the registry and see what it
* says.
*/
- otherstr = smalloc(len);
- regname = smalloc(3 * (strlen(hostname) + strlen(keytype)) + 15);
+ otherstr = snewn(len, char);
+ regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);
hostkey_regname(regname, hostname, port, keytype);
hostkey_regname(regname, hostname, port, keytype);
* under just the hostname and translate that.
*/
char *justhost = regname + 1 + strcspn(regname, ":");
* under just the hostname and translate that.
*/
char *justhost = regname + 1 + strcspn(regname, ":");
- char *oldstyle = smalloc(len + 10); /* safety margin */
+ char *oldstyle = snewn(len + 10, char); /* safety margin */
readlen = len;
ret = RegQueryValueEx(rkey, justhost, NULL, &type,
oldstyle, &readlen);
readlen = len;
ret = RegQueryValueEx(rkey, justhost, NULL, &type,
oldstyle, &readlen);
char *regname;
HKEY rkey;
char *regname;
HKEY rkey;
- regname = smalloc(3 * (strlen(hostname) + strlen(keytype)) + 15);
+ regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);
hostkey_regname(regname, hostname, port, keytype);
hostkey_regname(regname, hostname, port, keytype);
* This will guaranteeably be big enough; we can realloc it
* down later.
*/
* This will guaranteeably be big enough; we can realloc it
* down later.
*/
- outputline = smalloc(1+strlen(cmdline));
- outputargv = smalloc(sizeof(char *) * (strlen(cmdline)+1 / 2));
- outputargstart = smalloc(sizeof(char *) * (strlen(cmdline)+1 / 2));
+ outputline = snewn(1+strlen(cmdline), char);
+ outputargv = snewn(strlen(cmdline)+1 / 2, char *);
+ outputargstart = snewn(strlen(cmdline)+1 / 2, char *);
p = cmdline; q = outputline; outputargc = 0;
p = cmdline; q = outputline; outputargc = 0;
- outputargv = srealloc(outputargv, sizeof(char *) * outputargc);
- outputargstart = srealloc(outputargstart, sizeof(char *) * outputargc);
+ outputargv = sresize(outputargv, outputargc, char *);
+ outputargstart = sresize(outputargstart, outputargc, char *);
if (argc) *argc = outputargc;
if (argv) *argv = outputargv; else sfree(outputargv);
if (argc) *argc = outputargc;
if (argv) *argv = outputargv; else sfree(outputargv);
void *x11_invent_auth(char *proto, int protomaxlen,
char *data, int datamaxlen, int proto_id)
{
void *x11_invent_auth(char *proto, int protomaxlen,
char *data, int datamaxlen, int proto_id)
{
- struct X11Auth *auth = smalloc(sizeof(struct X11Auth));
+ struct X11Auth *auth = snew(struct X11Auth);
- pr = (struct X11Private *) smalloc(sizeof(struct X11Private));
+ pr = snew(struct X11Private);
pr->fn = &fn_table;
pr->auth_protocol = NULL;
pr->auth = (struct X11Auth *)auth;
pr->fn = &fn_table;
pr->auth_protocol = NULL;
pr->auth = (struct X11Auth *)auth;
pr->auth_psize = (pr->auth_plen + 3) & ~3;
pr->auth_dsize = (pr->auth_dlen + 3) & ~3;
/* Leave room for a terminating zero, to make our lives easier. */
pr->auth_psize = (pr->auth_plen + 3) & ~3;
pr->auth_dsize = (pr->auth_dlen + 3) & ~3;
/* Leave room for a terminating zero, to make our lives easier. */
- pr->auth_protocol = (char *) smalloc(pr->auth_psize + 1);
- pr->auth_data = (unsigned char *) smalloc(pr->auth_dsize);
+ pr->auth_protocol = snewn(pr->auth_psize + 1, char);
+ pr->auth_data = snewn(pr->auth_dsize, char);
message = dupprintf("PuTTY X11 proxy: %s", err);
msglen = strlen(message);
message = dupprintf("PuTTY X11 proxy: %s", err);
msglen = strlen(message);
- reply = smalloc(8 + msglen+1 + 4); /* include zero byte */
+ reply = snewn(8 + msglen+1 + 4, unsigned char); /* include zero */
msgsize = (msglen + 3) & ~3;
reply[0] = 0; /* failure */
reply[1] = msglen; /* length of reason string */
msgsize = (msglen + 3) & ~3;
reply[0] = 0; /* failure */
reply[1] = msglen; /* length of reason string */