mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
Introduced wrapper macros snew(), snewn() and sresize() for the
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]
This commit is contained in:
parent
70729da988
commit
d36a4c3685
@ -43,9 +43,8 @@ static void cmdline_save_param(char *p, char *value, int pri)
|
|||||||
{
|
{
|
||||||
if (saves[pri].nsaved >= saves[pri].savesize) {
|
if (saves[pri].nsaved >= saves[pri].savesize) {
|
||||||
saves[pri].savesize = saves[pri].nsaved + 32;
|
saves[pri].savesize = saves[pri].nsaved + 32;
|
||||||
saves[pri].params =
|
saves[pri].params = sresize(saves[pri].params, saves[pri].savesize,
|
||||||
srealloc(saves[pri].params,
|
struct cmdline_saved_param);
|
||||||
saves[pri].savesize*sizeof(*saves[pri].params));
|
|
||||||
}
|
}
|
||||||
saves[pri].params[saves[pri].nsaved].p = p;
|
saves[pri].params[saves[pri].nsaved].p = p;
|
||||||
saves[pri].params[saves[pri].nsaved].value = value;
|
saves[pri].params[saves[pri].nsaved].value = value;
|
||||||
@ -234,7 +233,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||||||
d = 0;
|
d = 0;
|
||||||
if (cmdlen >= cmdsize) {
|
if (cmdlen >= cmdsize) {
|
||||||
cmdsize = cmdlen + 512;
|
cmdsize = cmdlen + 512;
|
||||||
command = srealloc(command, cmdsize);
|
command = sresize(command, cmdsize, char);
|
||||||
}
|
}
|
||||||
command[cmdlen++] = d;
|
command[cmdlen++] = d;
|
||||||
} while (c != EOF);
|
} while (c != EOF);
|
||||||
|
6
config.c
6
config.c
@ -1141,7 +1141,7 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
|
|||||||
charclass_handler, P(ccd));
|
charclass_handler, P(ccd));
|
||||||
ccd->listbox->listbox.multisel = 1;
|
ccd->listbox->listbox.multisel = 1;
|
||||||
ccd->listbox->listbox.ncols = 4;
|
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[0] = 15;
|
||||||
ccd->listbox->listbox.percentages[1] = 25;
|
ccd->listbox->listbox.percentages[1] = 25;
|
||||||
ccd->listbox->listbox.percentages[2] = 20;
|
ccd->listbox->listbox.percentages[2] = 20;
|
||||||
@ -1345,7 +1345,7 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
|
|||||||
environ_handler, P(ed));
|
environ_handler, P(ed));
|
||||||
ed->listbox->listbox.height = 3;
|
ed->listbox->listbox.height = 3;
|
||||||
ed->listbox->listbox.ncols = 2;
|
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[0] = 30;
|
||||||
ed->listbox->listbox.percentages[1] = 70;
|
ed->listbox->listbox.percentages[1] = 70;
|
||||||
}
|
}
|
||||||
@ -1525,7 +1525,7 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
|
|||||||
portfwd_handler, P(pfd));
|
portfwd_handler, P(pfd));
|
||||||
pfd->listbox->listbox.height = 3;
|
pfd->listbox->listbox.height = 3;
|
||||||
pfd->listbox->listbox.ncols = 2;
|
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[0] = 20;
|
||||||
pfd->listbox->listbox.percentages[1] = 80;
|
pfd->listbox->listbox.percentages[1] = 80;
|
||||||
ctrl_tabdelay(s, pfd->rembutton);
|
ctrl_tabdelay(s, pfd->rembutton);
|
||||||
|
30
dialog.c
30
dialog.c
@ -41,7 +41,7 @@ int ctrl_path_compare(char *p1, char *p2)
|
|||||||
|
|
||||||
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->nctrlsets = ret->ctrlsetsize = 0;
|
||||||
ret->ctrlsets = NULL;
|
ret->ctrlsets = NULL;
|
||||||
@ -128,7 +128,7 @@ struct controlset *ctrl_settitle(struct controlbox *b,
|
|||||||
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);
|
int index = ctrl_find_set(b, path, 1);
|
||||||
s->pathname = dupstr(path);
|
s->pathname = dupstr(path);
|
||||||
s->boxname = NULL;
|
s->boxname = NULL;
|
||||||
@ -138,8 +138,7 @@ struct controlset *ctrl_settitle(struct controlbox *b,
|
|||||||
s->ctrls = NULL;
|
s->ctrls = NULL;
|
||||||
if (b->nctrlsets >= b->ctrlsetsize) {
|
if (b->nctrlsets >= b->ctrlsetsize) {
|
||||||
b->ctrlsetsize = b->nctrlsets + 32;
|
b->ctrlsetsize = b->nctrlsets + 32;
|
||||||
b->ctrlsets = srealloc(b->ctrlsets,
|
b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
|
||||||
b->ctrlsetsize*sizeof(*b->ctrlsets));
|
|
||||||
}
|
}
|
||||||
if (index < b->nctrlsets)
|
if (index < b->nctrlsets)
|
||||||
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
|
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
|
||||||
@ -162,7 +161,7 @@ struct controlset *ctrl_getset(struct controlbox *b,
|
|||||||
return b->ctrlsets[index];
|
return b->ctrlsets[index];
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
s = smalloc(sizeof(struct controlset));
|
s = snew(struct controlset);
|
||||||
s->pathname = dupstr(path);
|
s->pathname = dupstr(path);
|
||||||
s->boxname = dupstr(name);
|
s->boxname = dupstr(name);
|
||||||
s->boxtitle = boxtitle ? dupstr(boxtitle) : NULL;
|
s->boxtitle = boxtitle ? dupstr(boxtitle) : NULL;
|
||||||
@ -171,8 +170,7 @@ struct controlset *ctrl_getset(struct controlbox *b,
|
|||||||
s->ctrls = NULL;
|
s->ctrls = NULL;
|
||||||
if (b->nctrlsets >= b->ctrlsetsize) {
|
if (b->nctrlsets >= b->ctrlsetsize) {
|
||||||
b->ctrlsetsize = b->nctrlsets + 32;
|
b->ctrlsetsize = b->nctrlsets + 32;
|
||||||
b->ctrlsets = srealloc(b->ctrlsets,
|
b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
|
||||||
b->ctrlsetsize*sizeof(*b->ctrlsets));
|
|
||||||
}
|
}
|
||||||
if (index < b->nctrlsets)
|
if (index < b->nctrlsets)
|
||||||
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
|
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
|
||||||
@ -186,10 +184,14 @@ struct controlset *ctrl_getset(struct controlbox *b,
|
|||||||
void *ctrl_alloc(struct controlbox *b, size_t size)
|
void *ctrl_alloc(struct controlbox *b, size_t size)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
/*
|
||||||
|
* This is an internal allocation routine, so it's allowed to
|
||||||
|
* use smalloc directly.
|
||||||
|
*/
|
||||||
p = smalloc(size);
|
p = smalloc(size);
|
||||||
if (b->nfrees >= b->freesize) {
|
if (b->nfrees >= b->freesize) {
|
||||||
b->freesize = b->nfrees + 32;
|
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;
|
b->frees[b->nfrees++] = p;
|
||||||
return p;
|
return p;
|
||||||
@ -199,10 +201,10 @@ static union control *ctrl_new(struct controlset *s, int type,
|
|||||||
intorptr helpctx, handler_fn handler,
|
intorptr helpctx, handler_fn handler,
|
||||||
intorptr context)
|
intorptr context)
|
||||||
{
|
{
|
||||||
union control *c = smalloc(sizeof(union control));
|
union control *c = snew(union control);
|
||||||
if (s->ncontrols >= s->ctrlsize) {
|
if (s->ncontrols >= s->ctrlsize) {
|
||||||
s->ctrlsize = s->ncontrols + 32;
|
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;
|
||||||
/*
|
/*
|
||||||
@ -230,7 +232,7 @@ union control *ctrl_columns(struct controlset *s, int ncolumns, ...)
|
|||||||
} else {
|
} else {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int i;
|
int i;
|
||||||
c->columns.percentages = smalloc(ncolumns * sizeof(int));
|
c->columns.percentages = snewn(ncolumns, int);
|
||||||
va_start(ap, ncolumns);
|
va_start(ap, ncolumns);
|
||||||
for (i = 0; i < ncolumns; i++)
|
for (i = 0; i < ncolumns; i++)
|
||||||
c->columns.percentages[i] = va_arg(ap, int);
|
c->columns.percentages[i] = va_arg(ap, int);
|
||||||
@ -300,11 +302,11 @@ union control *ctrl_radiobuttons(struct controlset *s, char *label,
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
c->radio.nbuttons = i;
|
c->radio.nbuttons = i;
|
||||||
if (c->radio.shortcut == NO_SHORTCUT)
|
if (c->radio.shortcut == NO_SHORTCUT)
|
||||||
c->radio.shortcuts = smalloc(c->radio.nbuttons * sizeof(char));
|
c->radio.shortcuts = snewn(c->radio.nbuttons, char);
|
||||||
else
|
else
|
||||||
c->radio.shortcuts = NULL;
|
c->radio.shortcuts = NULL;
|
||||||
c->radio.buttons = smalloc(c->radio.nbuttons * sizeof(char *));
|
c->radio.buttons = snewn(c->radio.nbuttons, char *);
|
||||||
c->radio.buttondata = smalloc(c->radio.nbuttons * sizeof(intorptr));
|
c->radio.buttondata = snewn(c->radio.nbuttons, intorptr);
|
||||||
/*
|
/*
|
||||||
* Second pass along variable argument list to actually fill in
|
* Second pass along variable argument list to actually fill in
|
||||||
* the structure.
|
* the structure.
|
||||||
|
24
import.c
24
import.c
@ -326,7 +326,7 @@ static struct openssh_key *load_openssh_key(const Filename *filename)
|
|||||||
char base64_bit[4];
|
char base64_bit[4];
|
||||||
int base64_chars = 0;
|
int base64_chars = 0;
|
||||||
|
|
||||||
ret = smalloc(sizeof(*ret));
|
ret = snew(struct openssh_key);
|
||||||
ret->keyblob = NULL;
|
ret->keyblob = NULL;
|
||||||
ret->keyblob_len = ret->keyblob_size = 0;
|
ret->keyblob_len = ret->keyblob_size = 0;
|
||||||
ret->encrypted = 0;
|
ret->encrypted = 0;
|
||||||
@ -416,7 +416,8 @@ static struct openssh_key *load_openssh_key(const Filename *filename)
|
|||||||
|
|
||||||
if (ret->keyblob_len + len > ret->keyblob_size) {
|
if (ret->keyblob_len + len > ret->keyblob_size) {
|
||||||
ret->keyblob_size = ret->keyblob_len + len + 256;
|
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);
|
||||||
@ -564,7 +565,7 @@ struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase)
|
|||||||
* Space to create key blob in.
|
* Space to create key blob in.
|
||||||
*/
|
*/
|
||||||
blobsize = 256+key->keyblob_len;
|
blobsize = 256+key->keyblob_len;
|
||||||
blob = smalloc(blobsize);
|
blob = snewn(blobsize, unsigned char);
|
||||||
PUT_32BIT(blob, 7);
|
PUT_32BIT(blob, 7);
|
||||||
if (key->type == OSSH_DSA)
|
if (key->type == OSSH_DSA)
|
||||||
memcpy(blob+4, "ssh-dss", 7);
|
memcpy(blob+4, "ssh-dss", 7);
|
||||||
@ -636,7 +637,7 @@ struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase)
|
|||||||
* the sanity checks for free.
|
* the sanity checks for free.
|
||||||
*/
|
*/
|
||||||
assert(privptr > 0); /* should have bombed by now if not */
|
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->alg = (key->type == OSSH_RSA ? &ssh_rsa : &ssh_dss);
|
||||||
retkey->data = retkey->alg->createkey(blob, privptr,
|
retkey->data = retkey->alg->createkey(blob, privptr,
|
||||||
blob+privptr, blobptr-privptr);
|
blob+privptr, blobptr-privptr);
|
||||||
@ -719,7 +720,7 @@ int openssh_write(const Filename *filename, struct ssh2_userkey *key,
|
|||||||
dmp1.bytes = (bignum_bitcount(bdmp1)+8)/8;
|
dmp1.bytes = (bignum_bitcount(bdmp1)+8)/8;
|
||||||
dmq1.bytes = (bignum_bitcount(bdmq1)+8)/8;
|
dmq1.bytes = (bignum_bitcount(bdmq1)+8)/8;
|
||||||
sparelen = dmp1.bytes + dmq1.bytes;
|
sparelen = dmp1.bytes + dmq1.bytes;
|
||||||
spareblob = smalloc(sparelen);
|
spareblob = snewn(sparelen, unsigned char);
|
||||||
dmp1.start = spareblob;
|
dmp1.start = spareblob;
|
||||||
dmq1.start = spareblob + dmp1.bytes;
|
dmq1.start = spareblob + dmp1.bytes;
|
||||||
for (i = 0; i < dmp1.bytes; i++)
|
for (i = 0; i < dmp1.bytes; i++)
|
||||||
@ -791,7 +792,7 @@ int openssh_write(const Filename *filename, struct ssh2_userkey *key,
|
|||||||
/*
|
/*
|
||||||
* 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.
|
||||||
@ -996,7 +997,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename)
|
|||||||
char base64_bit[4];
|
char base64_bit[4];
|
||||||
int base64_chars = 0;
|
int base64_chars = 0;
|
||||||
|
|
||||||
ret = smalloc(sizeof(*ret));
|
ret = snew(struct sshcom_key);
|
||||||
ret->comment[0] = '\0';
|
ret->comment[0] = '\0';
|
||||||
ret->keyblob = NULL;
|
ret->keyblob = NULL;
|
||||||
ret->keyblob_len = ret->keyblob_size = 0;
|
ret->keyblob_len = ret->keyblob_size = 0;
|
||||||
@ -1072,7 +1073,8 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename)
|
|||||||
|
|
||||||
if (ret->keyblob_len + len > ret->keyblob_size) {
|
if (ret->keyblob_len + len > ret->keyblob_size) {
|
||||||
ret->keyblob_size = ret->keyblob_len + len + 256;
|
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);
|
||||||
@ -1333,7 +1335,7 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase)
|
|||||||
* end up feeding them to alg->createkey().
|
* end up feeding them to alg->createkey().
|
||||||
*/
|
*/
|
||||||
blobsize = cipherlen + 256;
|
blobsize = cipherlen + 256;
|
||||||
blob = smalloc(blobsize);
|
blob = snewn(blobsize, unsigned char);
|
||||||
privlen = 0;
|
privlen = 0;
|
||||||
if (type == RSA) {
|
if (type == RSA) {
|
||||||
struct mpint_pos n, e, d, u, p, q;
|
struct mpint_pos n, e, d, u, p, q;
|
||||||
@ -1391,7 +1393,7 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase)
|
|||||||
|
|
||||||
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->alg = alg;
|
||||||
retkey->data = alg->createkey(blob, publen, blob+publen, privlen);
|
retkey->data = alg->createkey(blob, publen, blob+publen, privlen);
|
||||||
if (!retkey->data) {
|
if (!retkey->data) {
|
||||||
@ -1502,7 +1504,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
|
|||||||
outlen = 512;
|
outlen = 512;
|
||||||
for (i = 0; i < nnumbers; i++)
|
for (i = 0; i < nnumbers; i++)
|
||||||
outlen += 4 + numbers[i].bytes;
|
outlen += 4 + numbers[i].bytes;
|
||||||
outblob = smalloc(outlen);
|
outblob = snewn(outlen, unsigned char);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the unencrypted key blob.
|
* Create the unencrypted key blob.
|
||||||
|
4
ldisc.c
4
ldisc.c
@ -65,7 +65,7 @@ void *ldisc_create(Config *mycfg, Terminal *term,
|
|||||||
Backend *back, void *backhandle,
|
Backend *back, void *backhandle,
|
||||||
void *frontend)
|
void *frontend)
|
||||||
{
|
{
|
||||||
Ldisc ldisc = smalloc(sizeof(*ldisc));
|
Ldisc ldisc = snew(struct ldisc_tag);
|
||||||
|
|
||||||
ldisc->buf = NULL;
|
ldisc->buf = NULL;
|
||||||
ldisc->buflen = 0;
|
ldisc->buflen = 0;
|
||||||
@ -261,7 +261,7 @@ void ldisc_send(void *handle, char *buf, int len, int interactive)
|
|||||||
default_case:
|
default_case:
|
||||||
if (ldisc->buflen >= ldisc->bufsiz) {
|
if (ldisc->buflen >= ldisc->bufsiz) {
|
||||||
ldisc->bufsiz = ldisc->buflen + 256;
|
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;
|
ldisc->buf[ldisc->buflen++] = c;
|
||||||
if (ECHOING)
|
if (ECHOING)
|
||||||
|
@ -26,7 +26,7 @@ void lpage_send(void *handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
widesize = len * 2;
|
widesize = len * 2;
|
||||||
widebuffer = smalloc(widesize * sizeof(wchar_t));
|
widebuffer = snewn(widesize, wchar_t);
|
||||||
|
|
||||||
wclen = mb_to_wc(codepage, 0, buf, len, widebuffer, widesize);
|
wclen = mb_to_wc(codepage, 0, buf, len, widebuffer, widesize);
|
||||||
luni_send(ldisc, widebuffer, wclen, interactive);
|
luni_send(ldisc, widebuffer, wclen, interactive);
|
||||||
@ -44,7 +44,7 @@ void luni_send(void *handle, wchar_t * widebuf, int len, int interactive)
|
|||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
linesize = len * ratio * 2;
|
linesize = len * ratio * 2;
|
||||||
linebuffer = smalloc(linesize * sizeof(wchar_t));
|
linebuffer = snewn(linesize, char);
|
||||||
|
|
||||||
if (in_utf(ldisc->term)) {
|
if (in_utf(ldisc->term)) {
|
||||||
/* UTF is a simple algorithm */
|
/* UTF is a simple algorithm */
|
||||||
|
@ -163,7 +163,7 @@ void logfclose(void *handle)
|
|||||||
|
|
||||||
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->lgfp = NULL;
|
||||||
ctx->frontend = frontend;
|
ctx->frontend = frontend;
|
||||||
ctx->cfg = *cfg; /* STRUCTURE COPY */
|
ctx->cfg = *cfg; /* STRUCTURE COPY */
|
||||||
|
10
misc.c
10
misc.c
@ -12,7 +12,7 @@
|
|||||||
char *dupstr(const char *s)
|
char *dupstr(const char *s)
|
||||||
{
|
{
|
||||||
int len = strlen(s);
|
int len = strlen(s);
|
||||||
char *p = smalloc(len + 1);
|
char *p = snewn(len + 1, char);
|
||||||
strcpy(p, s);
|
strcpy(p, s);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ char *dupcat(const char *s1, ...)
|
|||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
p = smalloc(len + 1);
|
p = snewn(len + 1, char);
|
||||||
strcpy(p, s1);
|
strcpy(p, s1);
|
||||||
q = p + strlen(p);
|
q = p + strlen(p);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ char *dupvprintf(const char *fmt, va_list ap)
|
|||||||
char *buf;
|
char *buf;
|
||||||
int len, size;
|
int len, size;
|
||||||
|
|
||||||
buf = smalloc(512);
|
buf = snewn(512, char);
|
||||||
size = 512;
|
size = 512;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -97,7 +97,7 @@ char *dupvprintf(const char *fmt, va_list ap)
|
|||||||
* buffer wasn't big enough, so we enlarge it a bit and hope. */
|
* buffer wasn't big enough, so we enlarge it a bit and hope. */
|
||||||
size += 512;
|
size += 512;
|
||||||
}
|
}
|
||||||
buf = srealloc(buf, size);
|
buf = sresize(buf, size, char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ void bufchain_add(bufchain *ch, const void *data, int len)
|
|||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
int grainlen = min(len, BUFFER_GRANULE);
|
int grainlen = min(len, BUFFER_GRANULE);
|
||||||
struct bufchain_granule *newbuf;
|
struct bufchain_granule *newbuf;
|
||||||
newbuf = smalloc(sizeof(struct bufchain_granule));
|
newbuf = snew(struct bufchain_granule);
|
||||||
newbuf->bufpos = 0;
|
newbuf->bufpos = 0;
|
||||||
newbuf->buflen = grainlen;
|
newbuf->buflen = grainlen;
|
||||||
memcpy(newbuf->buf, buf, grainlen);
|
memcpy(newbuf->buf, buf, grainlen);
|
||||||
|
28
pageant.c
28
pageant.c
@ -419,7 +419,7 @@ static void add_keyfile(Filename filename)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* For our purposes we want the blob prefixed with its length */
|
/* 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);
|
PUT_32BIT(blob2, bloblen);
|
||||||
memcpy(blob2 + 4, blob, bloblen);
|
memcpy(blob2 + 4, blob, bloblen);
|
||||||
sfree(blob);
|
sfree(blob);
|
||||||
@ -459,7 +459,7 @@ static void add_keyfile(Filename filename)
|
|||||||
needs_pass = ssh2_userkey_encrypted(&filename, &comment);
|
needs_pass = ssh2_userkey_encrypted(&filename, &comment);
|
||||||
attempts = 0;
|
attempts = 0;
|
||||||
if (type == SSH_KEYTYPE_SSH1)
|
if (type == SSH_KEYTYPE_SSH1)
|
||||||
rkey = smalloc(sizeof(*rkey));
|
rkey = snew(struct RSAKey);
|
||||||
pps.passphrase = passphrase;
|
pps.passphrase = passphrase;
|
||||||
pps.comment = comment;
|
pps.comment = comment;
|
||||||
original_pass = 0;
|
original_pass = 0;
|
||||||
@ -532,7 +532,7 @@ static void add_keyfile(Filename filename)
|
|||||||
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;
|
request[4] = SSH1_AGENTC_ADD_RSA_IDENTITY;
|
||||||
reqlen = 5;
|
reqlen = 5;
|
||||||
@ -580,7 +580,7 @@ static void add_keyfile(Filename filename)
|
|||||||
4 + clen /* comment */
|
4 + clen /* comment */
|
||||||
;
|
;
|
||||||
|
|
||||||
request = smalloc(reqlen);
|
request = snewn(reqlen, unsigned char);
|
||||||
|
|
||||||
request[4] = SSH2_AGENTC_ADD_IDENTITY;
|
request[4] = SSH2_AGENTC_ADD_IDENTITY;
|
||||||
reqlen = 5;
|
reqlen = 5;
|
||||||
@ -639,7 +639,7 @@ static void *make_keylist1(int *length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate the buffer. */
|
/* Allocate the buffer. */
|
||||||
p = ret = smalloc(len);
|
p = ret = snewn(len, unsigned char);
|
||||||
if (length) *length = len;
|
if (length) *length = len;
|
||||||
|
|
||||||
PUT_32BIT(p, nkeys);
|
PUT_32BIT(p, nkeys);
|
||||||
@ -684,7 +684,7 @@ static void *make_keylist2(int *length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate the buffer. */
|
/* Allocate the buffer. */
|
||||||
p = ret = smalloc(len);
|
p = ret = snewn(len, unsigned char);
|
||||||
if (length) *length = len;
|
if (length) *length = len;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -730,7 +730,7 @@ static void *get_keylist1(void)
|
|||||||
if (resplen < 5 || response[4] != SSH1_AGENT_RSA_IDENTITIES_ANSWER)
|
if (resplen < 5 || response[4] != SSH1_AGENT_RSA_IDENTITIES_ANSWER)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = smalloc(resplen-5);
|
ret = snewn(resplen-5, unsigned char);
|
||||||
memcpy(ret, response+5, resplen-5);
|
memcpy(ret, response+5, resplen-5);
|
||||||
sfree(response);
|
sfree(response);
|
||||||
} else {
|
} else {
|
||||||
@ -761,7 +761,7 @@ static void *get_keylist2(void)
|
|||||||
if (resplen < 5 || response[4] != SSH2_AGENT_IDENTITIES_ANSWER)
|
if (resplen < 5 || response[4] != SSH2_AGENT_IDENTITIES_ANSWER)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = smalloc(resplen-5);
|
ret = snewn(resplen-5, unsigned char);
|
||||||
memcpy(ret, response+5, resplen-5);
|
memcpy(ret, response+5, resplen-5);
|
||||||
sfree(response);
|
sfree(response);
|
||||||
} else {
|
} else {
|
||||||
@ -913,7 +913,7 @@ static void answer_msg(void *msg)
|
|||||||
struct RSAKey *key;
|
struct RSAKey *key;
|
||||||
char *comment;
|
char *comment;
|
||||||
int commentlen;
|
int commentlen;
|
||||||
key = smalloc(sizeof(struct RSAKey));
|
key = snew(struct RSAKey);
|
||||||
memset(key, 0, sizeof(struct RSAKey));
|
memset(key, 0, sizeof(struct RSAKey));
|
||||||
p += makekey(p, key, NULL, 1);
|
p += makekey(p, key, NULL, 1);
|
||||||
p += makeprivate(p, key);
|
p += makeprivate(p, key);
|
||||||
@ -921,7 +921,7 @@ static void answer_msg(void *msg)
|
|||||||
p += ssh1_read_bignum(p, &key->p); /* p */
|
p += ssh1_read_bignum(p, &key->p); /* p */
|
||||||
p += ssh1_read_bignum(p, &key->q); /* q */
|
p += ssh1_read_bignum(p, &key->q); /* q */
|
||||||
commentlen = GET_32BIT(p);
|
commentlen = GET_32BIT(p);
|
||||||
comment = smalloc(commentlen+1);
|
comment = snewn(commentlen+1, char);
|
||||||
if (comment) {
|
if (comment) {
|
||||||
memcpy(comment, p + 4, commentlen);
|
memcpy(comment, p + 4, commentlen);
|
||||||
comment[commentlen] = '\0';
|
comment[commentlen] = '\0';
|
||||||
@ -949,7 +949,7 @@ static void answer_msg(void *msg)
|
|||||||
int alglen, commlen;
|
int alglen, commlen;
|
||||||
int bloblen;
|
int bloblen;
|
||||||
|
|
||||||
key = smalloc(sizeof(struct ssh2_userkey));
|
key = snew(struct ssh2_userkey);
|
||||||
|
|
||||||
alglen = GET_32BIT(p);
|
alglen = GET_32BIT(p);
|
||||||
p += 4;
|
p += 4;
|
||||||
@ -977,7 +977,7 @@ static void answer_msg(void *msg)
|
|||||||
commlen = GET_32BIT(p);
|
commlen = GET_32BIT(p);
|
||||||
p += 4;
|
p += 4;
|
||||||
|
|
||||||
comment = smalloc(commlen + 1);
|
comment = snewn(commlen + 1, char);
|
||||||
if (comment) {
|
if (comment) {
|
||||||
memcpy(comment, p, commlen);
|
memcpy(comment, p, commlen);
|
||||||
comment[commlen] = '\0';
|
comment[commlen] = '\0';
|
||||||
@ -1222,7 +1222,7 @@ static void prompt_add_keyfile(void)
|
|||||||
{
|
{
|
||||||
OPENFILENAME of;
|
OPENFILENAME of;
|
||||||
char filename[FILENAME_MAX];
|
char filename[FILENAME_MAX];
|
||||||
char *filelist = smalloc(8192);
|
char *filelist = snewn(8192, char);
|
||||||
char *filewalker;
|
char *filewalker;
|
||||||
int n, dirlen;
|
int n, dirlen;
|
||||||
|
|
||||||
@ -1369,7 +1369,7 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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,
|
SendDlgItemMessage(hwnd, 100, LB_GETSELITEMS,
|
||||||
numSelected, (WPARAM)selectedArray);
|
numSelected, (WPARAM)selectedArray);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void agent_query(void *in, int inlen, void **out, int *outlen)
|
|||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
retlen = 4 + GET_32BIT(p);
|
retlen = 4 + GET_32BIT(p);
|
||||||
debug(("len is %d\n", retlen));
|
debug(("len is %d\n", retlen));
|
||||||
ret = smalloc(retlen);
|
ret = snewn(retlen, unsigned char);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
memcpy(ret, p, retlen);
|
memcpy(ret, p, retlen);
|
||||||
*out = ret;
|
*out = ret;
|
||||||
|
6
plink.c
6
plink.c
@ -410,13 +410,13 @@ int main(int argc, char **argv)
|
|||||||
while (*p) {
|
while (*p) {
|
||||||
if (cmdlen >= cmdsize) {
|
if (cmdlen >= cmdsize) {
|
||||||
cmdsize = cmdlen + 512;
|
cmdsize = cmdlen + 512;
|
||||||
command = srealloc(command, cmdsize);
|
command = sresize(command, cmdsize, char);
|
||||||
}
|
}
|
||||||
command[cmdlen++]=*p++;
|
command[cmdlen++]=*p++;
|
||||||
}
|
}
|
||||||
if (cmdlen >= cmdsize) {
|
if (cmdlen >= cmdsize) {
|
||||||
cmdsize = cmdlen + 512;
|
cmdsize = cmdlen + 512;
|
||||||
command = srealloc(command, cmdsize);
|
command = sresize(command, cmdsize, char);
|
||||||
}
|
}
|
||||||
command[cmdlen++]=' '; /* always add trailing space */
|
command[cmdlen++]=' '; /* always add trailing space */
|
||||||
if (--argc) p = *++argv;
|
if (--argc) p = *++argv;
|
||||||
@ -651,7 +651,7 @@ int main(int argc, char **argv)
|
|||||||
/* Expand the buffer if necessary. */
|
/* Expand the buffer if necessary. */
|
||||||
if (i > sksize) {
|
if (i > sksize) {
|
||||||
sksize = i + 16;
|
sksize = i + 16;
|
||||||
sklist = srealloc(sklist, sksize * sizeof(*sklist));
|
sklist = sresize(sklist, sksize, SOCKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve the sockets into sklist. */
|
/* Retrieve the sockets into sklist. */
|
||||||
|
@ -132,7 +132,7 @@ char *pfd_newconnect(Socket *s, char *hostname, int port, void *c,
|
|||||||
/*
|
/*
|
||||||
* Open socket.
|
* Open socket.
|
||||||
*/
|
*/
|
||||||
pr = (struct PFwdPrivate *) smalloc(sizeof(struct PFwdPrivate));
|
pr = snew(struct PFwdPrivate);
|
||||||
pr->fn = &fn_table;
|
pr->fn = &fn_table;
|
||||||
pr->throttled = pr->throttle_override = 0;
|
pr->throttled = pr->throttle_override = 0;
|
||||||
pr->ready = 1;
|
pr->ready = 1;
|
||||||
@ -168,7 +168,7 @@ static int pfd_accepting(Plug p, void *sock)
|
|||||||
char *err;
|
char *err;
|
||||||
|
|
||||||
org = (struct PFwdPrivate *)p;
|
org = (struct PFwdPrivate *)p;
|
||||||
pr = (struct PFwdPrivate *) smalloc(sizeof(struct PFwdPrivate));
|
pr = snew(struct PFwdPrivate);
|
||||||
pr->fn = &fn_table;
|
pr->fn = &fn_table;
|
||||||
|
|
||||||
pr->c = NULL;
|
pr->c = NULL;
|
||||||
@ -222,7 +222,7 @@ char *pfd_addforward(char *desthost, int destport, char *srcaddr, int port,
|
|||||||
/*
|
/*
|
||||||
* Open socket.
|
* Open socket.
|
||||||
*/
|
*/
|
||||||
pr = (struct PFwdPrivate *) smalloc(sizeof(struct PFwdPrivate));
|
pr = snew(struct PFwdPrivate);
|
||||||
pr->fn = &fn_table;
|
pr->fn = &fn_table;
|
||||||
pr->c = NULL;
|
pr->c = NULL;
|
||||||
strcpy(pr->hostname, desthost);
|
strcpy(pr->hostname, desthost);
|
||||||
|
10
printing.c
10
printing.c
@ -37,7 +37,7 @@ static char *printer_add_enum(int param, char *buffer,
|
|||||||
{
|
{
|
||||||
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
|
||||||
@ -50,7 +50,7 @@ static char *printer_add_enum(int param, char *buffer,
|
|||||||
if (needed < 512)
|
if (needed < 512)
|
||||||
needed = 512;
|
needed = 512;
|
||||||
|
|
||||||
buffer = srealloc(buffer, offset+needed);
|
buffer = sresize(buffer, offset+needed, char);
|
||||||
|
|
||||||
if (EnumPrinters(param, NULL, ENUM_LEVEL, buffer+offset,
|
if (EnumPrinters(param, NULL, ENUM_LEVEL, buffer+offset,
|
||||||
needed, &needed, &nprinters) == 0)
|
needed, &needed, &nprinters) == 0)
|
||||||
@ -63,11 +63,11 @@ static char *printer_add_enum(int param, char *buffer,
|
|||||||
|
|
||||||
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;
|
char *buffer = NULL, *retval;
|
||||||
|
|
||||||
*nprinters_ptr = 0; /* default return value */
|
*nprinters_ptr = 0; /* default return value */
|
||||||
buffer = smalloc(512);
|
buffer = snewn(512, char);
|
||||||
|
|
||||||
retval = printer_add_enum(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
|
retval = printer_add_enum(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
|
||||||
buffer, 0, nprinters_ptr);
|
buffer, 0, nprinters_ptr);
|
||||||
@ -107,7 +107,7 @@ void printer_finish_enum(printer_enum *pe)
|
|||||||
|
|
||||||
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;
|
DOC_INFO_1 docinfo;
|
||||||
int jobstarted = 0, pagestarted = 0;
|
int jobstarted = 0, pagestarted = 0;
|
||||||
|
|
||||||
|
10
proxy.c
10
proxy.c
@ -378,7 +378,7 @@ Socket new_connection(SockAddr addr, char *hostname,
|
|||||||
SockAddr proxy_addr;
|
SockAddr proxy_addr;
|
||||||
char *proxy_canonical_name, *err;
|
char *proxy_canonical_name, *err;
|
||||||
|
|
||||||
ret = smalloc(sizeof(struct Socket_proxy_tag));
|
ret = snew(struct Socket_proxy_tag);
|
||||||
ret->fn = &socket_fn_table;
|
ret->fn = &socket_fn_table;
|
||||||
ret->cfg = *cfg; /* STRUCTURE COPY */
|
ret->cfg = *cfg; /* STRUCTURE COPY */
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
@ -413,7 +413,7 @@ Socket new_connection(SockAddr addr, char *hostname,
|
|||||||
|
|
||||||
/* create the proxy plug to map calls from the actual
|
/* create the proxy plug to map calls from the actual
|
||||||
* socket into our proxy socket layer */
|
* 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->fn = &plug_fn_table;
|
||||||
pplug->proxy_socket = ret;
|
pplug->proxy_socket = ret;
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
|
|||||||
/* get the status line */
|
/* get the status line */
|
||||||
len = bufchain_size(&p->pending_input_data);
|
len = bufchain_size(&p->pending_input_data);
|
||||||
assert(len > 0); /* or we wouldn't be here */
|
assert(len > 0); /* or we wouldn't be here */
|
||||||
data = smalloc(len);
|
data = snewn(len, char);
|
||||||
bufchain_fetch(&p->pending_input_data, data, len);
|
bufchain_fetch(&p->pending_input_data, data, len);
|
||||||
|
|
||||||
eol = get_line_end(data, len);
|
eol = get_line_end(data, len);
|
||||||
@ -627,7 +627,7 @@ int proxy_http_negotiate (Proxy_Socket p, int change)
|
|||||||
|
|
||||||
len = bufchain_size(&p->pending_input_data);
|
len = bufchain_size(&p->pending_input_data);
|
||||||
assert(len > 0); /* or we wouldn't be here */
|
assert(len > 0); /* or we wouldn't be here */
|
||||||
data = smalloc(len);
|
data = snewn(len, char);
|
||||||
datap = data;
|
datap = data;
|
||||||
bufchain_fetch(&p->pending_input_data, data, len);
|
bufchain_fetch(&p->pending_input_data, data, len);
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ int proxy_socks4_negotiate (Proxy_Socket p, int change)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
strcpy(command + 8, p->cfg.proxy_username);
|
||||||
|
|
||||||
command[0] = 4; /* version 4 */
|
command[0] = 4; /* version 4 */
|
||||||
|
25
psftp.c
25
psftp.c
@ -245,8 +245,7 @@ int sftp_cmd_ls(struct sftp_command *cmd)
|
|||||||
|
|
||||||
if (nnames + names->nnames >= namesize) {
|
if (nnames + names->nnames >= namesize) {
|
||||||
namesize += names->nnames + 128;
|
namesize += names->nnames + 128;
|
||||||
ournames =
|
ournames = sresize(ournames, namesize, struct fxp_name *);
|
||||||
srealloc(ournames, namesize * sizeof(*ournames));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < names->nnames; i++)
|
for (i = 0; i < names->nnames; i++)
|
||||||
@ -934,10 +933,10 @@ static int sftp_cmd_lcd(struct sftp_command *cmd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
currdir = smalloc(256);
|
currdir = snewn(256, char);
|
||||||
len = GetCurrentDirectory(256, currdir);
|
len = GetCurrentDirectory(256, currdir);
|
||||||
if (len > 256)
|
if (len > 256)
|
||||||
currdir = srealloc(currdir, len);
|
currdir = sresize(currdir, len, char);
|
||||||
GetCurrentDirectory(len, currdir);
|
GetCurrentDirectory(len, currdir);
|
||||||
printf("New local directory is %s\n", currdir);
|
printf("New local directory is %s\n", currdir);
|
||||||
sfree(currdir);
|
sfree(currdir);
|
||||||
@ -950,10 +949,10 @@ static int sftp_cmd_lpwd(struct sftp_command *cmd)
|
|||||||
char *currdir;
|
char *currdir;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
currdir = smalloc(256);
|
currdir = snewn(256, char);
|
||||||
len = GetCurrentDirectory(256, currdir);
|
len = GetCurrentDirectory(256, currdir);
|
||||||
if (len > 256)
|
if (len > 256)
|
||||||
currdir = srealloc(currdir, len);
|
currdir = sresize(currdir, len, char);
|
||||||
GetCurrentDirectory(len, currdir);
|
GetCurrentDirectory(len, currdir);
|
||||||
printf("Current local directory is %s\n", currdir);
|
printf("Current local directory is %s\n", currdir);
|
||||||
sfree(currdir);
|
sfree(currdir);
|
||||||
@ -1254,7 +1253,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
|
|||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
cmd = smalloc(sizeof(struct sftp_command));
|
cmd = snew(struct sftp_command);
|
||||||
cmd->words = NULL;
|
cmd->words = NULL;
|
||||||
cmd->nwords = 0;
|
cmd->nwords = 0;
|
||||||
cmd->wordssize = 0;
|
cmd->wordssize = 0;
|
||||||
@ -1266,7 +1265,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
|
|||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
linesize += 512;
|
linesize += 512;
|
||||||
line = srealloc(line, linesize);
|
line = sresize(line, linesize, char);
|
||||||
ret = fgets(line + linelen, linesize - linelen, fp);
|
ret = fgets(line + linelen, linesize - linelen, fp);
|
||||||
|
|
||||||
if (!ret || (linelen == 0 && line[0] == '\0')) {
|
if (!ret || (linelen == 0 && line[0] == '\0')) {
|
||||||
@ -1298,7 +1297,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
|
|||||||
* containing everything else on the line.
|
* containing everything else on the line.
|
||||||
*/
|
*/
|
||||||
cmd->nwords = cmd->wordssize = 2;
|
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[0] = "!";
|
||||||
cmd->words[1] = p+1;
|
cmd->words[1] = p+1;
|
||||||
} else {
|
} else {
|
||||||
@ -1341,8 +1340,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
|
|||||||
*r = '\0';
|
*r = '\0';
|
||||||
if (cmd->nwords >= cmd->wordssize) {
|
if (cmd->nwords >= cmd->wordssize) {
|
||||||
cmd->wordssize = cmd->nwords + 16;
|
cmd->wordssize = cmd->nwords + 16;
|
||||||
cmd->words =
|
cmd->words = sresize(cmd->words, cmd->wordssize, char *);
|
||||||
srealloc(cmd->words, cmd->wordssize * sizeof(char *));
|
|
||||||
}
|
}
|
||||||
cmd->words[cmd->nwords++] = q;
|
cmd->words[cmd->nwords++] = q;
|
||||||
}
|
}
|
||||||
@ -1564,10 +1562,7 @@ int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
|
|||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (pendsize < pendlen + len) {
|
if (pendsize < pendlen + len) {
|
||||||
pendsize = pendlen + len + 4096;
|
pendsize = pendlen + len + 4096;
|
||||||
pending = (pending ? srealloc(pending, pendsize) :
|
pending = sresize(pending, pendsize, unsigned char);
|
||||||
smalloc(pendsize));
|
|
||||||
if (!pending)
|
|
||||||
fatalbox("Out of memory");
|
|
||||||
}
|
}
|
||||||
memcpy(pending + pendlen, p, len);
|
memcpy(pending + pendlen, p, len);
|
||||||
pendlen += len;
|
pendlen += len;
|
||||||
|
16
puttygen.c
16
puttygen.c
@ -389,8 +389,8 @@ static void setupbigedit2(HWND hwnd, int id, int idstatic,
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
pub_blob = key->alg->public_blob(key->data, &pub_len);
|
pub_blob = key->alg->public_blob(key->data, &pub_len);
|
||||||
buffer = smalloc(strlen(key->alg->name) + 4 * ((pub_len + 2) / 3) +
|
buffer = snewn(strlen(key->alg->name) + 4 * ((pub_len + 2) / 3) +
|
||||||
strlen(key->comment) + 3);
|
strlen(key->comment) + 3, char);
|
||||||
strcpy(buffer, key->alg->name);
|
strcpy(buffer, key->alg->name);
|
||||||
p = buffer + strlen(buffer);
|
p = buffer + strlen(buffer);
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
@ -820,7 +820,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
|||||||
SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
|
SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
|
||||||
(LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(200)));
|
(LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(200)));
|
||||||
|
|
||||||
state = smalloc(sizeof(*state));
|
state = snew(struct MainDlgState);
|
||||||
state->generation_thread_exists = FALSE;
|
state->generation_thread_exists = FALSE;
|
||||||
state->collecting_entropy = FALSE;
|
state->collecting_entropy = FALSE;
|
||||||
state->entropy = NULL;
|
state->entropy = NULL;
|
||||||
@ -974,7 +974,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
|||||||
MAKELPARAM(0, PROGRESSRANGE));
|
MAKELPARAM(0, PROGRESSRANGE));
|
||||||
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
|
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->progressbar = GetDlgItem(hwnd, IDC_PROGRESS);
|
||||||
params->dialog = hwnd;
|
params->dialog = hwnd;
|
||||||
params->keysize = state->keysize;
|
params->keysize = state->keysize;
|
||||||
@ -1021,7 +1021,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
|||||||
int len = GetWindowTextLength(editctl);
|
int len = GetWindowTextLength(editctl);
|
||||||
if (*state->commentptr)
|
if (*state->commentptr)
|
||||||
sfree(*state->commentptr);
|
sfree(*state->commentptr);
|
||||||
*state->commentptr = smalloc(len + 1);
|
*state->commentptr = snewn(len + 1, char);
|
||||||
GetWindowText(editctl, *state->commentptr, len + 1);
|
GetWindowText(editctl, *state->commentptr, len + 1);
|
||||||
if (state->ssh2) {
|
if (state->ssh2) {
|
||||||
setupbigedit2(hwnd, IDC_KEYDISPLAY, IDC_PKSTATIC,
|
setupbigedit2(hwnd, IDC_KEYDISPLAY, IDC_PKSTATIC,
|
||||||
@ -1096,8 +1096,8 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
|||||||
state->entropy_required = (state->keysize / 2) * 2;
|
state->entropy_required = (state->keysize / 2) * 2;
|
||||||
state->entropy_got = 0;
|
state->entropy_got = 0;
|
||||||
state->entropy_size = (state->entropy_required *
|
state->entropy_size = (state->entropy_required *
|
||||||
sizeof(*state->entropy));
|
sizeof(unsigned));
|
||||||
state->entropy = smalloc(state->entropy_size);
|
state->entropy = snewn(state->entropy_required, unsigned);
|
||||||
|
|
||||||
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
|
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
|
||||||
MAKELPARAM(0, state->entropy_required));
|
MAKELPARAM(0, state->entropy_required));
|
||||||
@ -1270,7 +1270,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
|||||||
* the user will immediately want to change it, which is
|
* the user will immediately want to change it, which is
|
||||||
* what we want :-)
|
* what we want :-)
|
||||||
*/
|
*/
|
||||||
*state->commentptr = smalloc(30);
|
*state->commentptr = snewn(30, char);
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
|
17
puttymem.h
17
puttymem.h
@ -25,13 +25,14 @@ void *safemalloc(size_t);
|
|||||||
void *saferealloc(void *, size_t);
|
void *saferealloc(void *, size_t);
|
||||||
void safefree(void *);
|
void safefree(void *);
|
||||||
|
|
||||||
|
/*
|
||||||
/* smalloc a thing */
|
* Direct use of smalloc within the code should be avoided where
|
||||||
#define smalloca(type) ((type *) smalloc (sizeof (type)))
|
* possible, in favour of these type-casting macros which ensure
|
||||||
/* smalloc a copy of a thing */
|
* you don't mistakenly allocate enough space for one sort of
|
||||||
#define smallocc(ptr) memcpy (smalloc (sizeof (*ptr)), ptr, sizeof (*ptr))
|
* structure and assign it to a different sort of pointer.
|
||||||
/* smalloc n things */
|
*/
|
||||||
#define smallocn(n,type) ((type *) smalloc ((n) * sizeof (type)))
|
#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)))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
2
raw.c
2
raw.c
@ -80,7 +80,7 @@ static char *raw_init(void *frontend_handle, void **backend_handle,
|
|||||||
char *err;
|
char *err;
|
||||||
Raw raw;
|
Raw raw;
|
||||||
|
|
||||||
raw = smalloc(sizeof(*raw));
|
raw = snew(struct raw_backend_data);
|
||||||
raw->fn = &fn_table;
|
raw->fn = &fn_table;
|
||||||
raw->s = NULL;
|
raw->s = NULL;
|
||||||
*backend_handle = raw;
|
*backend_handle = raw;
|
||||||
|
2
rlogin.c
2
rlogin.c
@ -110,7 +110,7 @@ static char *rlogin_init(void *frontend_handle, void **backend_handle,
|
|||||||
char *err;
|
char *err;
|
||||||
Rlogin rlogin;
|
Rlogin rlogin;
|
||||||
|
|
||||||
rlogin = smalloc(sizeof(*rlogin));
|
rlogin = snew(struct rlogin_tag);
|
||||||
rlogin->fn = &fn_table;
|
rlogin->fn = &fn_table;
|
||||||
rlogin->s = NULL;
|
rlogin->s = NULL;
|
||||||
rlogin->frontend = frontend_handle;
|
rlogin->frontend = frontend_handle;
|
||||||
|
21
scp.c
21
scp.c
@ -353,8 +353,7 @@ int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
|
|||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (pendsize < pendlen + len) {
|
if (pendsize < pendlen + len) {
|
||||||
pendsize = pendlen + len + 4096;
|
pendsize = pendlen + len + 4096;
|
||||||
pending = (pending ? srealloc(pending, pendsize) :
|
pending = sresize(pending, pendsize, unsigned char);
|
||||||
smalloc(pendsize));
|
|
||||||
if (!pending)
|
if (!pending)
|
||||||
fatalbox("Out of memory");
|
fatalbox("Out of memory");
|
||||||
}
|
}
|
||||||
@ -545,7 +544,7 @@ static void do_cmd(char *host, char *user, char *cmd)
|
|||||||
namelen = 0;
|
namelen = 0;
|
||||||
if (GetUserName(user, &namelen) == FALSE)
|
if (GetUserName(user, &namelen) == FALSE)
|
||||||
bump("Empty user name");
|
bump("Empty user name");
|
||||||
user = smalloc(namelen * sizeof(char));
|
user = snewn(namelen, char);
|
||||||
GetUserName(user, &namelen);
|
GetUserName(user, &namelen);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
tell_user(stderr, "Guessing user name: %s", user);
|
tell_user(stderr, "Guessing user name: %s", user);
|
||||||
@ -777,8 +776,7 @@ void scp_sftp_listdir(char *dirname)
|
|||||||
|
|
||||||
if (nnames + names->nnames >= namesize) {
|
if (nnames + names->nnames >= namesize) {
|
||||||
namesize += names->nnames + 128;
|
namesize += names->nnames + 128;
|
||||||
ournames =
|
ournames = sresize(ournames, namesize, struct fxp_name);
|
||||||
srealloc(ournames, namesize * sizeof(*ournames));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < names->nnames; i++)
|
for (i = 0; i < names->nnames; i++)
|
||||||
@ -1064,7 +1062,7 @@ int scp_sink_setup(char *source, int preserve, int recursive)
|
|||||||
* wildcardness comes before the final slash) and arrange
|
* wildcardness comes before the final slash) and arrange
|
||||||
* things so that a dirstack entry will be set up.
|
* 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)) {
|
if (!wc_unescape(newsource, source)) {
|
||||||
/* Yes, here we go; it's a wildcard. Bah. */
|
/* Yes, here we go; it's a wildcard. Bah. */
|
||||||
char *dupsource, *lastpart, *dirpart, *wildcard;
|
char *dupsource, *lastpart, *dirpart, *wildcard;
|
||||||
@ -1097,7 +1095,7 @@ int scp_sink_setup(char *source, int preserve, int recursive)
|
|||||||
* wildcard escapes from the directory part, throwing
|
* wildcard escapes from the directory part, throwing
|
||||||
* an error if it contains a real wildcard.
|
* an error if it contains a real wildcard.
|
||||||
*/
|
*/
|
||||||
dirpart = smalloc(1+strlen(dupsource));
|
dirpart = snewn(1+strlen(dupsource), char);
|
||||||
if (!wc_unescape(dirpart, dupsource)) {
|
if (!wc_unescape(dirpart, dupsource)) {
|
||||||
tell_user(stderr, "%s: multiple-level wildcards unsupported",
|
tell_user(stderr, "%s: multiple-level wildcards unsupported",
|
||||||
source);
|
source);
|
||||||
@ -1306,8 +1304,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
|
|||||||
}
|
}
|
||||||
if (nnames + names->nnames >= namesize) {
|
if (nnames + names->nnames >= namesize) {
|
||||||
namesize += names->nnames + 128;
|
namesize += names->nnames + 128;
|
||||||
ournames =
|
ournames = sresize(ournames, namesize, struct fxp_name);
|
||||||
srealloc(ournames, namesize * sizeof(*ournames));
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < names->nnames; i++)
|
for (i = 0; i < names->nnames; i++)
|
||||||
ournames[nnames++] = names->names[i];
|
ournames[nnames++] = names->names[i];
|
||||||
@ -1316,7 +1313,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
|
|||||||
}
|
}
|
||||||
fxp_close(dirhandle);
|
fxp_close(dirhandle);
|
||||||
|
|
||||||
newitem = smalloc(sizeof(struct scp_sftp_dirstack));
|
newitem = snew(struct scp_sftp_dirstack);
|
||||||
newitem->next = scp_sftp_dirstack_head;
|
newitem->next = scp_sftp_dirstack_head;
|
||||||
newitem->names = ournames;
|
newitem->names = ournames;
|
||||||
newitem->namepos = 0;
|
newitem->namepos = 0;
|
||||||
@ -1404,7 +1401,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
|
|||||||
bump("Lost connection");
|
bump("Lost connection");
|
||||||
if (i >= bufsize) {
|
if (i >= bufsize) {
|
||||||
bufsize = i + 128;
|
bufsize = i + 128;
|
||||||
act->buf = srealloc(act->buf, bufsize);
|
act->buf = sresize(act->buf, bufsize, char);
|
||||||
}
|
}
|
||||||
act->buf[i++] = ch;
|
act->buf[i++] = ch;
|
||||||
} while (ch != '\n');
|
} while (ch != '\n');
|
||||||
@ -2080,7 +2077,7 @@ static void get_dir_list(int argc, char *argv[])
|
|||||||
user = NULL;
|
user = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = smalloc(4 * strlen(src) + 100);
|
cmd = snewn(4 * strlen(src) + 100, char);
|
||||||
strcpy(cmd, "ls -la '");
|
strcpy(cmd, "ls -la '");
|
||||||
p = cmd + strlen(cmd);
|
p = cmd + strlen(cmd);
|
||||||
for (q = src; *q; q++) {
|
for (q = src; *q; q++) {
|
||||||
|
@ -672,7 +672,7 @@ void get_sesslist(struct sesslist *list, int allocate)
|
|||||||
int len = strlen(otherbuf) + 1;
|
int len = strlen(otherbuf) + 1;
|
||||||
if (bufsize < buflen + len) {
|
if (bufsize < buflen + len) {
|
||||||
bufsize = buflen + len + 2048;
|
bufsize = buflen + len + 2048;
|
||||||
list->buffer = srealloc(list->buffer, bufsize);
|
list->buffer = sresize(list->buffer, bufsize, char);
|
||||||
}
|
}
|
||||||
strcpy(list->buffer + buflen, otherbuf);
|
strcpy(list->buffer + buflen, otherbuf);
|
||||||
buflen += strlen(list->buffer + buflen) + 1;
|
buflen += strlen(list->buffer + buflen) + 1;
|
||||||
@ -680,7 +680,7 @@ void get_sesslist(struct sesslist *list, int allocate)
|
|||||||
} while (ret);
|
} while (ret);
|
||||||
enum_settings_finish(handle);
|
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';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -699,7 +699,7 @@ void get_sesslist(struct sesslist *list, int allocate)
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->sessions = smalloc((list->nsessions + 1) * sizeof(char *));
|
list->sessions = snewn(list->nsessions + 1, char *);
|
||||||
list->sessions[0] = "Default Settings";
|
list->sessions[0] = "Default Settings";
|
||||||
p = list->buffer;
|
p = list->buffer;
|
||||||
i = 1;
|
i = 1;
|
||||||
|
20
sftp.c
20
sftp.c
@ -40,7 +40,7 @@ static void sftp_pkt_ensure(struct sftp_packet *pkt, int length)
|
|||||||
{
|
{
|
||||||
if (pkt->maxlen < length) {
|
if (pkt->maxlen < length) {
|
||||||
pkt->maxlen = length + 256;
|
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)
|
||||||
@ -56,7 +56,7 @@ static void sftp_pkt_addbyte(struct sftp_packet *pkt, unsigned char byte)
|
|||||||
static struct sftp_packet *sftp_pkt_init(int pkt_type)
|
static struct sftp_packet *sftp_pkt_init(int pkt_type)
|
||||||
{
|
{
|
||||||
struct sftp_packet *pkt;
|
struct sftp_packet *pkt;
|
||||||
pkt = smalloc(sizeof(struct sftp_packet));
|
pkt = snew(struct sftp_packet);
|
||||||
pkt->data = NULL;
|
pkt->data = NULL;
|
||||||
pkt->savedpos = -1;
|
pkt->savedpos = -1;
|
||||||
pkt->length = 0;
|
pkt->length = 0;
|
||||||
@ -228,10 +228,10 @@ struct sftp_packet *sftp_recv(void)
|
|||||||
if (!sftp_recvdata(x, 4))
|
if (!sftp_recvdata(x, 4))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pkt = smalloc(sizeof(struct sftp_packet));
|
pkt = snew(struct sftp_packet);
|
||||||
pkt->savedpos = 0;
|
pkt->savedpos = 0;
|
||||||
pkt->length = pkt->maxlen = GET_32BIT(x);
|
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)) {
|
if (!sftp_recvdata(pkt->data, pkt->length)) {
|
||||||
sftp_pkt_free(pkt);
|
sftp_pkt_free(pkt);
|
||||||
@ -249,7 +249,7 @@ struct sftp_packet *sftp_recv(void)
|
|||||||
|
|
||||||
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);
|
memcpy(p, s, len);
|
||||||
p[len] = '\0';
|
p[len] = '\0';
|
||||||
return p;
|
return p;
|
||||||
@ -444,7 +444,7 @@ struct fxp_handle *fxp_open(char *path, int type)
|
|||||||
sftp_pkt_free(pktin);
|
sftp_pkt_free(pktin);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
handle = smalloc(sizeof(struct fxp_handle));
|
handle = snew(struct fxp_handle);
|
||||||
handle->hstring = mkstr(hstring, len);
|
handle->hstring = mkstr(hstring, len);
|
||||||
handle->hlen = len;
|
handle->hlen = len;
|
||||||
sftp_pkt_free(pktin);
|
sftp_pkt_free(pktin);
|
||||||
@ -490,7 +490,7 @@ struct fxp_handle *fxp_opendir(char *path)
|
|||||||
sftp_pkt_free(pktin);
|
sftp_pkt_free(pktin);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
handle = smalloc(sizeof(struct fxp_handle));
|
handle = snew(struct fxp_handle);
|
||||||
handle->hstring = mkstr(hstring, len);
|
handle->hstring = mkstr(hstring, len);
|
||||||
handle->hlen = len;
|
handle->hlen = len;
|
||||||
sftp_pkt_free(pktin);
|
sftp_pkt_free(pktin);
|
||||||
@ -855,9 +855,9 @@ struct fxp_names *fxp_readdir(struct fxp_handle *handle)
|
|||||||
if (pktin->type == SSH_FXP_NAME) {
|
if (pktin->type == SSH_FXP_NAME) {
|
||||||
struct fxp_names *ret;
|
struct fxp_names *ret;
|
||||||
int i;
|
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++) {
|
for (i = 0; i < ret->nnames; i++) {
|
||||||
char *str;
|
char *str;
|
||||||
int len;
|
int len;
|
||||||
@ -930,7 +930,7 @@ void fxp_free_names(struct fxp_names *names)
|
|||||||
struct fxp_name *fxp_dup_name(struct fxp_name *name)
|
struct fxp_name *fxp_dup_name(struct fxp_name *name)
|
||||||
{
|
{
|
||||||
struct fxp_name *ret;
|
struct fxp_name *ret;
|
||||||
ret = smalloc(sizeof(struct fxp_name));
|
ret = snew(struct fxp_name);
|
||||||
ret->filename = dupstr(name->filename);
|
ret->filename = dupstr(name->filename);
|
||||||
ret->longname = dupstr(name->longname);
|
ret->longname = dupstr(name->longname);
|
||||||
ret->attrs = name->attrs; /* structure copy */
|
ret->attrs = name->attrs; /* structure copy */
|
||||||
|
@ -42,7 +42,7 @@ static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
|
|||||||
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
|
Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);
|
||||||
|
|
||||||
wtlen = GetWindowTextLength(hWnd);
|
wtlen = GetWindowTextLength(hWnd);
|
||||||
wt = (LPTSTR) smalloc((wtlen + 1) * sizeof(TCHAR));
|
wt = (LPTSTR) snewn(wtlen + 1, TCHAR);
|
||||||
GetWindowText(hWnd, wt, wtlen + 1);
|
GetWindowText(hWnd, wt, wtlen + 1);
|
||||||
|
|
||||||
SetTextColor(hdc, tip_text);
|
SetTextColor(hdc, tip_text);
|
||||||
|
92
ssh.c
92
ssh.c
@ -292,7 +292,7 @@ enum { PKT_END, PKT_INT, PKT_CHAR, PKT_DATA, PKT_STR, PKT_BIGNUM };
|
|||||||
#define crBegin(v) { int *crLine = &v; switch(v) { case 0:;
|
#define crBegin(v) { int *crLine = &v; switch(v) { case 0:;
|
||||||
#define crState(t) \
|
#define crState(t) \
|
||||||
struct t *s; \
|
struct t *s; \
|
||||||
if (!ssh->t) ssh->t = smalloc(sizeof(struct t)); \
|
if (!ssh->t) ssh->t = snew(struct t); \
|
||||||
s = ssh->t;
|
s = ssh->t;
|
||||||
#define crFinish(z) } *crLine = 0; return (z); }
|
#define crFinish(z) } *crLine = 0; return (z); }
|
||||||
#define crFinishV } *crLine = 0; return; }
|
#define crFinishV } *crLine = 0; return; }
|
||||||
@ -814,7 +814,8 @@ static int ssh1_rdpkt(Ssh ssh, unsigned char **data, int *datalen)
|
|||||||
|
|
||||||
if (ssh->pktin.maxlen < st->biglen) {
|
if (ssh->pktin.maxlen < st->biglen) {
|
||||||
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;
|
||||||
@ -859,8 +860,9 @@ static int ssh1_rdpkt(Ssh ssh, unsigned char **data, int *datalen)
|
|||||||
|
|
||||||
if (ssh->pktin.maxlen < st->pad + decomplen) {
|
if (ssh->pktin.maxlen < st->pad + decomplen) {
|
||||||
ssh->pktin.maxlen = st->pad + decomplen;
|
ssh->pktin.maxlen = st->pad + decomplen;
|
||||||
ssh->pktin.data = srealloc(ssh->pktin.data,
|
ssh->pktin.data = sresize(ssh->pktin.data,
|
||||||
ssh->pktin.maxlen + APIEXTRA);
|
ssh->pktin.maxlen + APIEXTRA,
|
||||||
|
unsigned char);
|
||||||
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
|
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -942,7 +944,8 @@ static int ssh2_rdpkt(Ssh ssh, unsigned char **data, int *datalen)
|
|||||||
|
|
||||||
if (ssh->pktin.maxlen < st->cipherblk) {
|
if (ssh->pktin.maxlen < st->cipherblk) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -993,8 +996,9 @@ static int ssh2_rdpkt(Ssh ssh, unsigned char **data, int *datalen)
|
|||||||
*/
|
*/
|
||||||
if (ssh->pktin.maxlen < st->packetlen + st->maclen) {
|
if (ssh->pktin.maxlen < st->packetlen + st->maclen) {
|
||||||
ssh->pktin.maxlen = st->packetlen + st->maclen;
|
ssh->pktin.maxlen = st->packetlen + st->maclen;
|
||||||
ssh->pktin.data = srealloc(ssh->pktin.data,
|
ssh->pktin.data = sresize(ssh->pktin.data,
|
||||||
ssh->pktin.maxlen + APIEXTRA);
|
ssh->pktin.maxlen + APIEXTRA,
|
||||||
|
unsigned char);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1036,8 +1040,9 @@ static int ssh2_rdpkt(Ssh ssh, unsigned char **data, int *datalen)
|
|||||||
&newpayload, &newlen)) {
|
&newpayload, &newlen)) {
|
||||||
if (ssh->pktin.maxlen < newlen + 5) {
|
if (ssh->pktin.maxlen < newlen + 5) {
|
||||||
ssh->pktin.maxlen = newlen + 5;
|
ssh->pktin.maxlen = newlen + 5;
|
||||||
ssh->pktin.data = srealloc(ssh->pktin.data,
|
ssh->pktin.data = sresize(ssh->pktin.data,
|
||||||
ssh->pktin.maxlen + APIEXTRA);
|
ssh->pktin.maxlen + APIEXTRA,
|
||||||
|
unsigned char);
|
||||||
}
|
}
|
||||||
ssh->pktin.length = 5 + newlen;
|
ssh->pktin.length = 5 + newlen;
|
||||||
memcpy(ssh->pktin.data + 5, newpayload, newlen);
|
memcpy(ssh->pktin.data + 5, newpayload, newlen);
|
||||||
@ -1170,9 +1175,11 @@ static void ssh1_pktout_size(Ssh ssh, int len)
|
|||||||
#ifdef MSCRYPTOAPI
|
#ifdef MSCRYPTOAPI
|
||||||
/* Allocate enough buffer space for extra block
|
/* Allocate enough buffer space for extra block
|
||||||
* for MS CryptEncrypt() */
|
* for MS CryptEncrypt() */
|
||||||
ssh->pktout.data = srealloc(ssh->pktout.data, biglen + 12);
|
ssh->pktout.data = sresize(ssh->pktout.data, biglen + 12,
|
||||||
|
unsigned char);
|
||||||
#else
|
#else
|
||||||
ssh->pktout.data = srealloc(ssh->pktout.data, biglen + 4);
|
ssh->pktout.data = sresize(ssh->pktout.data, biglen + 4,
|
||||||
|
unsigned char);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ssh->pktout.body = ssh->pktout.data + 4 + pad + 1;
|
ssh->pktout.body = ssh->pktout.data + 4 + pad + 1;
|
||||||
@ -1248,8 +1255,9 @@ static void s_wrpkt_defer(Ssh ssh)
|
|||||||
len = s_wrpkt_prepare(ssh);
|
len = s_wrpkt_prepare(ssh);
|
||||||
if (ssh->deferred_len + len > ssh->deferred_size) {
|
if (ssh->deferred_len + len > ssh->deferred_size) {
|
||||||
ssh->deferred_size = ssh->deferred_len + len + 128;
|
ssh->deferred_size = ssh->deferred_len + len + 128;
|
||||||
ssh->deferred_send_data = srealloc(ssh->deferred_send_data,
|
ssh->deferred_send_data = sresize(ssh->deferred_send_data,
|
||||||
ssh->deferred_size);
|
ssh->deferred_size,
|
||||||
|
unsigned char);
|
||||||
}
|
}
|
||||||
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
|
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
|
||||||
ssh->deferred_len += len;
|
ssh->deferred_len += len;
|
||||||
@ -1396,8 +1404,9 @@ static void ssh2_pkt_ensure(Ssh ssh, int length)
|
|||||||
{
|
{
|
||||||
if (ssh->pktout.maxlen < length) {
|
if (ssh->pktout.maxlen < length) {
|
||||||
ssh->pktout.maxlen = length + 256;
|
ssh->pktout.maxlen = length + 256;
|
||||||
ssh->pktout.data = srealloc(ssh->pktout.data,
|
ssh->pktout.data = sresize(ssh->pktout.data,
|
||||||
ssh->pktout.maxlen + APIEXTRA);
|
ssh->pktout.maxlen + APIEXTRA,
|
||||||
|
unsigned char);
|
||||||
if (!ssh->pktout.data)
|
if (!ssh->pktout.data)
|
||||||
fatalbox("Out of memory");
|
fatalbox("Out of memory");
|
||||||
}
|
}
|
||||||
@ -1453,7 +1462,7 @@ static unsigned char *ssh2_mpint_fmt(Bignum b, int *len)
|
|||||||
{
|
{
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
int i, n = (bignum_bitcount(b) + 7) / 8;
|
int i, n = (bignum_bitcount(b) + 7) / 8;
|
||||||
p = smalloc(n + 1);
|
p = snewn(n + 1, unsigned char);
|
||||||
if (!p)
|
if (!p)
|
||||||
fatalbox("out of memory");
|
fatalbox("out of memory");
|
||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
@ -1564,8 +1573,9 @@ static void ssh2_pkt_defer(Ssh ssh)
|
|||||||
int len = ssh2_pkt_construct(ssh);
|
int len = ssh2_pkt_construct(ssh);
|
||||||
if (ssh->deferred_len + len > ssh->deferred_size) {
|
if (ssh->deferred_len + len > ssh->deferred_size) {
|
||||||
ssh->deferred_size = ssh->deferred_len + len + 128;
|
ssh->deferred_size = ssh->deferred_len + len + 128;
|
||||||
ssh->deferred_send_data = srealloc(ssh->deferred_send_data,
|
ssh->deferred_send_data = sresize(ssh->deferred_send_data,
|
||||||
ssh->deferred_size);
|
ssh->deferred_size,
|
||||||
|
unsigned char);
|
||||||
}
|
}
|
||||||
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
|
memcpy(ssh->deferred_send_data + ssh->deferred_len, ssh->pktout.data, len);
|
||||||
ssh->deferred_len += len;
|
ssh->deferred_len += len;
|
||||||
@ -1876,7 +1886,7 @@ static int do_ssh_init(Ssh ssh, unsigned char c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
s->vstrsize = 16;
|
s->vstrsize = 16;
|
||||||
s->vstring = smalloc(s->vstrsize);
|
s->vstring = snewn(s->vstrsize, char);
|
||||||
strcpy(s->vstring, "SSH-");
|
strcpy(s->vstring, "SSH-");
|
||||||
s->vslen = 4;
|
s->vslen = 4;
|
||||||
s->i = 0;
|
s->i = 0;
|
||||||
@ -1884,7 +1894,7 @@ static int do_ssh_init(Ssh ssh, unsigned char c)
|
|||||||
crReturn(1); /* get another char */
|
crReturn(1); /* get another char */
|
||||||
if (s->vslen >= s->vstrsize - 1) {
|
if (s->vslen >= s->vstrsize - 1) {
|
||||||
s->vstrsize += 16;
|
s->vstrsize += 16;
|
||||||
s->vstring = srealloc(s->vstring, s->vstrsize);
|
s->vstring = sresize(s->vstring, s->vstrsize, char);
|
||||||
}
|
}
|
||||||
s->vstring[s->vslen++] = c;
|
s->vstring[s->vslen++] = c;
|
||||||
if (s->i >= 0) {
|
if (s->i >= 0) {
|
||||||
@ -1904,7 +1914,7 @@ static int do_ssh_init(Ssh ssh, unsigned char c)
|
|||||||
s->vstring[strcspn(s->vstring, "\r\n")] = '\0';/* remove EOL chars */
|
s->vstring[strcspn(s->vstring, "\r\n")] = '\0';/* remove EOL chars */
|
||||||
{
|
{
|
||||||
char *vlog;
|
char *vlog;
|
||||||
vlog = smalloc(20 + s->vslen);
|
vlog = snewn(20 + s->vslen, char);
|
||||||
sprintf(vlog, "Server version: %s", s->vstring);
|
sprintf(vlog, "Server version: %s", s->vstring);
|
||||||
logevent(vlog);
|
logevent(vlog);
|
||||||
sfree(vlog);
|
sfree(vlog);
|
||||||
@ -2083,7 +2093,7 @@ static char *connect_to_host(Ssh ssh, char *host, int port,
|
|||||||
SockAddr addr;
|
SockAddr addr;
|
||||||
char *err;
|
char *err;
|
||||||
|
|
||||||
ssh->savedhost = smalloc(1 + strlen(host));
|
ssh->savedhost = snewn(1 + strlen(host), char);
|
||||||
if (!ssh->savedhost)
|
if (!ssh->savedhost)
|
||||||
fatalbox("Out of memory");
|
fatalbox("Out of memory");
|
||||||
strcpy(ssh->savedhost, host);
|
strcpy(ssh->savedhost, host);
|
||||||
@ -2326,7 +2336,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
|
|
||||||
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)
|
if (!s->rsabuf)
|
||||||
fatalbox("Out of memory");
|
fatalbox("Out of memory");
|
||||||
|
|
||||||
@ -2339,7 +2349,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
*/
|
*/
|
||||||
int len = rsastr_len(&hostkey);
|
int len = rsastr_len(&hostkey);
|
||||||
char fingerprint[100];
|
char fingerprint[100];
|
||||||
char *keystr = smalloc(len);
|
char *keystr = snewn(len, char);
|
||||||
if (!keystr)
|
if (!keystr)
|
||||||
fatalbox("Out of memory");
|
fatalbox("Out of memory");
|
||||||
rsastr_fmt(keystr, &hostkey);
|
rsastr_fmt(keystr, &hostkey);
|
||||||
@ -2577,7 +2587,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
len += ssh1_bignum_length(s->challenge);
|
len += ssh1_bignum_length(s->challenge);
|
||||||
len += 16; /* session id */
|
len += 16; /* session id */
|
||||||
len += 4; /* response format */
|
len += 4; /* response format */
|
||||||
agentreq = smalloc(4 + len);
|
agentreq = snewn(4 + len, char);
|
||||||
PUT_32BIT(agentreq, len);
|
PUT_32BIT(agentreq, len);
|
||||||
q = agentreq + 4;
|
q = agentreq + 4;
|
||||||
*q++ = SSH1_AGENTC_RSA_CHALLENGE;
|
*q++ = SSH1_AGENTC_RSA_CHALLENGE;
|
||||||
@ -2892,7 +2902,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
|
|
||||||
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++) {
|
for (i = bottom; i <= top; i++) {
|
||||||
if (i == pwlen)
|
if (i == pwlen)
|
||||||
@ -3182,7 +3192,7 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
dserv, "(", dport, dserv, ")");
|
dserv, "(", dport, dserv, ")");
|
||||||
} else {
|
} else {
|
||||||
struct ssh_rportfwd *pf;
|
struct ssh_rportfwd *pf;
|
||||||
pf = smalloc(sizeof(*pf));
|
pf = snew(struct ssh_rportfwd);
|
||||||
strcpy(pf->dhost, host);
|
strcpy(pf->dhost, host);
|
||||||
pf->dport = dport;
|
pf->dport = dport;
|
||||||
if (saddr) {
|
if (saddr) {
|
||||||
@ -3330,7 +3340,7 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
|
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
|
||||||
logevent("Rejected X11 connect request");
|
logevent("Rejected X11 connect request");
|
||||||
} else {
|
} else {
|
||||||
c = smalloc(sizeof(struct ssh_channel));
|
c = snew(struct ssh_channel);
|
||||||
c->ssh = ssh;
|
c->ssh = ssh;
|
||||||
|
|
||||||
if (x11_init(&c->u.x11.s, ssh->cfg.x11_display, c,
|
if (x11_init(&c->u.x11.s, ssh->cfg.x11_display, c,
|
||||||
@ -3365,7 +3375,7 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
|
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
|
||||||
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
|
PKT_INT, GET_32BIT(ssh->pktin.body), PKT_END);
|
||||||
} else {
|
} else {
|
||||||
c = smalloc(sizeof(struct ssh_channel));
|
c = snew(struct ssh_channel);
|
||||||
c->ssh = ssh;
|
c->ssh = ssh;
|
||||||
c->remoteid = GET_32BIT(ssh->pktin.body);
|
c->remoteid = GET_32BIT(ssh->pktin.body);
|
||||||
c->localid = alloc_channel_id(ssh);
|
c->localid = alloc_channel_id(ssh);
|
||||||
@ -3386,7 +3396,7 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
int hostsize, port;
|
int hostsize, port;
|
||||||
char host[256], buf[1024];
|
char host[256], buf[1024];
|
||||||
char *p, *h, *e;
|
char *p, *h, *e;
|
||||||
c = smalloc(sizeof(struct ssh_channel));
|
c = snew(struct ssh_channel);
|
||||||
c->ssh = ssh;
|
c->ssh = ssh;
|
||||||
|
|
||||||
hostsize = GET_32BIT(ssh->pktin.body+4);
|
hostsize = GET_32BIT(ssh->pktin.body+4);
|
||||||
@ -3542,7 +3552,8 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
if (c->u.a.lensofar == 4) {
|
if (c->u.a.lensofar == 4) {
|
||||||
c->u.a.totallen =
|
c->u.a.totallen =
|
||||||
4 + GET_32BIT(c->u.a.msglen);
|
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);
|
memcpy(c->u.a.message, c->u.a.msglen, 4);
|
||||||
}
|
}
|
||||||
if (c->u.a.lensofar >= 4 && len > 0) {
|
if (c->u.a.lensofar >= 4 && len > 0) {
|
||||||
@ -4682,7 +4693,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
s->len += 4 + s->pklen; /* key blob */
|
s->len += 4 + s->pklen; /* key blob */
|
||||||
s->len += 4 + s->siglen; /* data to sign */
|
s->len += 4 + s->siglen; /* data to sign */
|
||||||
s->len += 4; /* flags */
|
s->len += 4; /* flags */
|
||||||
s->agentreq = smalloc(4 + s->len);
|
s->agentreq = snewn(4 + s->len, char);
|
||||||
PUT_32BIT(s->agentreq, s->len);
|
PUT_32BIT(s->agentreq, s->len);
|
||||||
s->q = s->agentreq + 4;
|
s->q = s->agentreq + 4;
|
||||||
*s->q++ = SSH2_AGENTC_SIGN_REQUEST;
|
*s->q++ = SSH2_AGENTC_SIGN_REQUEST;
|
||||||
@ -4973,7 +4984,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
sigdata_len = ssh->pktout.length - 5 + 4 + 20;
|
sigdata_len = ssh->pktout.length - 5 + 4 + 20;
|
||||||
if (ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)
|
if (ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)
|
||||||
sigdata_len -= 4;
|
sigdata_len -= 4;
|
||||||
sigdata = smalloc(sigdata_len);
|
sigdata = snewn(sigdata_len, char);
|
||||||
p = 0;
|
p = 0;
|
||||||
if (!(ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)) {
|
if (!(ssh->remote_bugs & BUG_SSH2_PK_SESSIONID)) {
|
||||||
PUT_32BIT(sigdata+p, 20);
|
PUT_32BIT(sigdata+p, 20);
|
||||||
@ -5105,7 +5116,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
* So now create a channel with a session in it.
|
* So now create a channel with a session in it.
|
||||||
*/
|
*/
|
||||||
ssh->channels = newtree234(ssh_channelcmp);
|
ssh->channels = newtree234(ssh_channelcmp);
|
||||||
ssh->mainchan = smalloc(sizeof(struct ssh_channel));
|
ssh->mainchan = snew(struct ssh_channel);
|
||||||
ssh->mainchan->ssh = ssh;
|
ssh->mainchan->ssh = ssh;
|
||||||
ssh->mainchan->localid = alloc_channel_id(ssh);
|
ssh->mainchan->localid = alloc_channel_id(ssh);
|
||||||
ssh2_pkt_init(ssh, SSH2_MSG_CHANNEL_OPEN);
|
ssh2_pkt_init(ssh, SSH2_MSG_CHANNEL_OPEN);
|
||||||
@ -5262,7 +5273,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
dserv, "(", dport, dserv, ")");
|
dserv, "(", dport, dserv, ")");
|
||||||
} else {
|
} else {
|
||||||
struct ssh_rportfwd *pf;
|
struct ssh_rportfwd *pf;
|
||||||
pf = smalloc(sizeof(*pf));
|
pf = snew(struct ssh_rportfwd);
|
||||||
strcpy(pf->dhost, host);
|
strcpy(pf->dhost, host);
|
||||||
pf->dport = dport;
|
pf->dport = dport;
|
||||||
pf->sport = sport;
|
pf->sport = sport;
|
||||||
@ -5530,7 +5541,8 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
if (c->u.a.lensofar == 4) {
|
if (c->u.a.lensofar == 4) {
|
||||||
c->u.a.totallen =
|
c->u.a.totallen =
|
||||||
4 + GET_32BIT(c->u.a.msglen);
|
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);
|
memcpy(c->u.a.message, c->u.a.msglen, 4);
|
||||||
}
|
}
|
||||||
if (c->u.a.lensofar >= 4 && length > 0) {
|
if (c->u.a.lensofar >= 4 && length > 0) {
|
||||||
@ -5794,7 +5806,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
struct ssh_channel *c;
|
struct ssh_channel *c;
|
||||||
unsigned remid, winsize, pktsize;
|
unsigned remid, winsize, pktsize;
|
||||||
ssh2_pkt_getstring(ssh, &type, &typelen);
|
ssh2_pkt_getstring(ssh, &type, &typelen);
|
||||||
c = smalloc(sizeof(struct ssh_channel));
|
c = snew(struct ssh_channel);
|
||||||
c->ssh = ssh;
|
c->ssh = ssh;
|
||||||
|
|
||||||
remid = ssh2_pkt_getuint32(ssh);
|
remid = ssh2_pkt_getuint32(ssh);
|
||||||
@ -5804,7 +5816,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
|
|||||||
port = ssh2_pkt_getuint32(ssh);
|
port = ssh2_pkt_getuint32(ssh);
|
||||||
|
|
||||||
if (typelen == 3 && !memcmp(type, "x11", 3)) {
|
if (typelen == 3 && !memcmp(type, "x11", 3)) {
|
||||||
char *addrstr = smalloc(peeraddrlen+1);
|
char *addrstr = snewn(peeraddrlen+1, char);
|
||||||
memcpy(addrstr, peeraddr, peeraddrlen);
|
memcpy(addrstr, peeraddr, peeraddrlen);
|
||||||
peeraddr[peeraddrlen] = '\0';
|
peeraddr[peeraddrlen] = '\0';
|
||||||
|
|
||||||
@ -5947,7 +5959,7 @@ static char *ssh_init(void *frontend_handle, void **backend_handle,
|
|||||||
char *p;
|
char *p;
|
||||||
Ssh ssh;
|
Ssh ssh;
|
||||||
|
|
||||||
ssh = smalloc(sizeof(*ssh));
|
ssh = snew(struct ssh_tag);
|
||||||
ssh->cfg = *cfg; /* STRUCTURE COPY */
|
ssh->cfg = *cfg; /* STRUCTURE COPY */
|
||||||
ssh->s = NULL;
|
ssh->s = NULL;
|
||||||
ssh->cipher = NULL;
|
ssh->cipher = NULL;
|
||||||
@ -6241,7 +6253,7 @@ void *new_sock_channel(void *handle, Socket s)
|
|||||||
{
|
{
|
||||||
Ssh ssh = (Ssh) handle;
|
Ssh ssh = (Ssh) handle;
|
||||||
struct ssh_channel *c;
|
struct ssh_channel *c;
|
||||||
c = smalloc(sizeof(struct ssh_channel));
|
c = snew(struct ssh_channel);
|
||||||
c->ssh = ssh;
|
c->ssh = ssh;
|
||||||
|
|
||||||
if (c) {
|
if (c) {
|
||||||
|
2
sshaes.c
2
sshaes.c
@ -1085,7 +1085,7 @@ static void aes_decrypt_cbc(unsigned char *blk, int len, AESContext * ctx)
|
|||||||
|
|
||||||
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)
|
||||||
|
@ -478,13 +478,13 @@ static void blowfish_setkey(BlowfishContext * ctx,
|
|||||||
|
|
||||||
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)
|
static void *blowfish_ssh1_make_context(void)
|
||||||
{
|
{
|
||||||
/* In SSH1, need one key for each direction */
|
/* 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)
|
||||||
|
30
sshbn.c
30
sshbn.c
@ -34,7 +34,7 @@ Bignum Zero = bnZero, One = bnOne;
|
|||||||
|
|
||||||
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)
|
if (!b)
|
||||||
abort(); /* FIXME */
|
abort(); /* FIXME */
|
||||||
memset(b, 0, (length + 1) * sizeof(*b));
|
memset(b, 0, (length + 1) * sizeof(*b));
|
||||||
@ -50,7 +50,7 @@ void bn_restore_invariant(Bignum 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)
|
if (!b)
|
||||||
abort(); /* FIXME */
|
abort(); /* FIXME */
|
||||||
memcpy(b, orig, (orig[0] + 1) * sizeof(*b));
|
memcpy(b, orig, (orig[0] + 1) * sizeof(*b));
|
||||||
@ -216,7 +216,7 @@ Bignum modpow(Bignum base, Bignum exp, Bignum mod)
|
|||||||
/* Allocate m of size mlen, copy mod to m */
|
/* Allocate m of size mlen, copy mod to m */
|
||||||
/* We use big endian internally */
|
/* We use big endian internally */
|
||||||
mlen = mod[0];
|
mlen = mod[0];
|
||||||
m = smalloc(mlen * sizeof(unsigned short));
|
m = snewn(mlen, unsigned short);
|
||||||
for (j = 0; j < mlen; j++)
|
for (j = 0; j < mlen; j++)
|
||||||
m[j] = mod[mod[0] - j];
|
m[j] = mod[mod[0] - j];
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ Bignum modpow(Bignum base, Bignum exp, Bignum mod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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];
|
i = mlen - base[0];
|
||||||
for (j = 0; j < i; j++)
|
for (j = 0; j < i; j++)
|
||||||
n[j] = 0;
|
n[j] = 0;
|
||||||
@ -239,8 +239,8 @@ Bignum modpow(Bignum base, Bignum exp, Bignum mod)
|
|||||||
n[i + j] = base[base[0] - j];
|
n[i + j] = base[base[0] - j];
|
||||||
|
|
||||||
/* Allocate a and b of size 2*mlen. Set a = 1 */
|
/* Allocate a and b of size 2*mlen. Set a = 1 */
|
||||||
a = smalloc(2 * mlen * sizeof(unsigned short));
|
a = snewn(2 * mlen, unsigned short);
|
||||||
b = smalloc(2 * mlen * sizeof(unsigned short));
|
b = snewn(2 * mlen, unsigned short);
|
||||||
for (i = 0; i < 2 * mlen; i++)
|
for (i = 0; i < 2 * mlen; i++)
|
||||||
a[i] = 0;
|
a[i] = 0;
|
||||||
a[2 * mlen - 1] = 1;
|
a[2 * mlen - 1] = 1;
|
||||||
@ -325,7 +325,7 @@ Bignum modmul(Bignum p, Bignum q, Bignum mod)
|
|||||||
/* Allocate m of size mlen, copy mod to m */
|
/* Allocate m of size mlen, copy mod to m */
|
||||||
/* We use big endian internally */
|
/* We use big endian internally */
|
||||||
mlen = mod[0];
|
mlen = mod[0];
|
||||||
m = smalloc(mlen * sizeof(unsigned short));
|
m = snewn(mlen, unsigned short);
|
||||||
for (j = 0; j < mlen; j++)
|
for (j = 0; j < mlen; j++)
|
||||||
m[j] = mod[mod[0] - j];
|
m[j] = mod[mod[0] - j];
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ Bignum modmul(Bignum p, Bignum q, Bignum mod)
|
|||||||
pqlen = (p[0] > q[0] ? p[0] : q[0]);
|
pqlen = (p[0] > q[0] ? p[0] : q[0]);
|
||||||
|
|
||||||
/* Allocate n of size pqlen, copy p to n */
|
/* Allocate n of size pqlen, copy p to n */
|
||||||
n = smalloc(pqlen * sizeof(unsigned short));
|
n = snewn(pqlen, unsigned short);
|
||||||
i = pqlen - p[0];
|
i = pqlen - p[0];
|
||||||
for (j = 0; j < i; j++)
|
for (j = 0; j < i; j++)
|
||||||
n[j] = 0;
|
n[j] = 0;
|
||||||
@ -350,7 +350,7 @@ Bignum modmul(Bignum p, Bignum q, Bignum mod)
|
|||||||
n[i + j] = p[p[0] - j];
|
n[i + j] = p[p[0] - j];
|
||||||
|
|
||||||
/* Allocate o of size pqlen, copy q to o */
|
/* Allocate o of size pqlen, copy q to o */
|
||||||
o = smalloc(pqlen * sizeof(unsigned short));
|
o = snewn(pqlen, unsigned short);
|
||||||
i = pqlen - q[0];
|
i = pqlen - q[0];
|
||||||
for (j = 0; j < i; j++)
|
for (j = 0; j < i; j++)
|
||||||
o[j] = 0;
|
o[j] = 0;
|
||||||
@ -358,7 +358,7 @@ Bignum modmul(Bignum p, Bignum q, Bignum mod)
|
|||||||
o[i + j] = q[q[0] - j];
|
o[i + j] = q[q[0] - j];
|
||||||
|
|
||||||
/* Allocate a of size 2*pqlen for result */
|
/* Allocate a of size 2*pqlen for result */
|
||||||
a = smalloc(2 * pqlen * sizeof(unsigned short));
|
a = snewn(2 * pqlen, unsigned short);
|
||||||
|
|
||||||
/* Main computation */
|
/* Main computation */
|
||||||
internal_mul(n, o, a, pqlen);
|
internal_mul(n, o, a, pqlen);
|
||||||
@ -415,7 +415,7 @@ static void bigdivmod(Bignum p, Bignum mod, Bignum result, Bignum quotient)
|
|||||||
/* Allocate m of size mlen, copy mod to m */
|
/* Allocate m of size mlen, copy mod to m */
|
||||||
/* We use big endian internally */
|
/* We use big endian internally */
|
||||||
mlen = mod[0];
|
mlen = mod[0];
|
||||||
m = smalloc(mlen * sizeof(unsigned short));
|
m = snewn(mlen, unsigned short);
|
||||||
for (j = 0; j < mlen; j++)
|
for (j = 0; j < mlen; j++)
|
||||||
m[j] = mod[mod[0] - j];
|
m[j] = mod[mod[0] - j];
|
||||||
|
|
||||||
@ -435,7 +435,7 @@ static void bigdivmod(Bignum p, Bignum mod, Bignum result, Bignum quotient)
|
|||||||
plen = mlen + 1;
|
plen = mlen + 1;
|
||||||
|
|
||||||
/* Allocate n of size plen, copy p to n */
|
/* 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++)
|
for (j = 0; j < plen; j++)
|
||||||
n[j] = 0;
|
n[j] = 0;
|
||||||
for (j = 1; j <= p[0]; j++)
|
for (j = 1; j <= p[0]; j++)
|
||||||
@ -673,7 +673,7 @@ Bignum bigmuladd(Bignum a, Bignum b, Bignum addend)
|
|||||||
Bignum ret;
|
Bignum ret;
|
||||||
|
|
||||||
/* mlen space for a, mlen space for b, 2*mlen for result */
|
/* 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++) {
|
for (i = 0; i < mlen; i++) {
|
||||||
workspace[0 * mlen + i] = (mlen - i <= a[0] ? a[mlen - i] : 0);
|
workspace[0 * mlen + i] = (mlen - i <= a[0] ? a[mlen - i] : 0);
|
||||||
workspace[1 * mlen + i] = (mlen - i <= b[0] ? b[mlen - i] : 0);
|
workspace[1 * mlen + i] = (mlen - i <= b[0] ? b[mlen - i] : 0);
|
||||||
@ -949,14 +949,14 @@ char *bignum_decimal(Bignum x)
|
|||||||
i = bignum_bitcount(x);
|
i = bignum_bitcount(x);
|
||||||
ndigits = (28 * i + 92) / 93; /* multiply by 28/93 and round up */
|
ndigits = (28 * i + 92) / 93; /* multiply by 28/93 and round up */
|
||||||
ndigits++; /* allow for trailing \0 */
|
ndigits++; /* allow for trailing \0 */
|
||||||
ret = smalloc(ndigits);
|
ret = snewn(ndigits, char);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now allocate some workspace to hold the binary form as we
|
* Now allocate some workspace to hold the binary form as we
|
||||||
* repeatedly divide it by ten. Initialise this to the
|
* repeatedly divide it by ten. Initialise this to the
|
||||||
* big-endian form of the number.
|
* 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++)
|
for (i = 0; i < x[0]; i++)
|
||||||
workspace[i] = x[x[0] - i];
|
workspace[i] = x[x[0] - i];
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ struct crcda_ctx {
|
|||||||
|
|
||||||
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->h = NULL;
|
||||||
ret->n = HASH_MINSIZE / HASH_ENTRYSIZE;
|
ret->n = HASH_MINSIZE / HASH_ENTRYSIZE;
|
||||||
return ret;
|
return ret;
|
||||||
@ -118,11 +118,11 @@ int detect_attack(void *handle, uchar *buf, uint32 len, uchar *IV)
|
|||||||
|
|
||||||
if (ctx->h == NULL) {
|
if (ctx->h == NULL) {
|
||||||
ctx->n = l;
|
ctx->n = l;
|
||||||
ctx->h = (uint16 *) smalloc(ctx->n * HASH_ENTRYSIZE);
|
ctx->h = snewn(ctx->n, uint16);
|
||||||
} else {
|
} else {
|
||||||
if (l > ctx->n) {
|
if (l > ctx->n) {
|
||||||
ctx->n = l;
|
ctx->n = l;
|
||||||
ctx->h = (uint16 *) srealloc(ctx->h, ctx->n * HASH_ENTRYSIZE);
|
ctx->h = sresize(ctx->h, ctx->n, uint16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
sshdes.c
8
sshdes.c
@ -746,24 +746,24 @@ static void des_cbc3_decrypt(unsigned char *dest, const unsigned char *src,
|
|||||||
|
|
||||||
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)
|
static void *des3_ssh1_make_context(void)
|
||||||
{
|
{
|
||||||
/* Need 3 keys for each direction, in SSH1 */
|
/* 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)
|
static void *des_ssh1_make_context(void)
|
||||||
{
|
{
|
||||||
/* Need one key for each direction, in SSH1 */
|
/* 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 */
|
||||||
|
6
sshdh.c
6
sshdh.c
@ -52,7 +52,7 @@ static void dh_init(struct dh_ctx *ctx)
|
|||||||
*/
|
*/
|
||||||
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->p = bignum_from_bytes(P, sizeof(P));
|
||||||
ctx->g = bignum_from_bytes(G, sizeof(G));
|
ctx->g = bignum_from_bytes(G, sizeof(G));
|
||||||
dh_init(ctx);
|
dh_init(ctx);
|
||||||
@ -64,7 +64,7 @@ void *dh_setup_group1(void)
|
|||||||
*/
|
*/
|
||||||
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->p = copybn(pval);
|
||||||
ctx->g = copybn(gval);
|
ctx->g = copybn(gval);
|
||||||
dh_init(ctx);
|
dh_init(ctx);
|
||||||
@ -110,7 +110,7 @@ Bignum dh_create_e(void *handle, int nbits)
|
|||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
|
|
||||||
nbytes = ssh1_bignum_length(ctx->qmask);
|
nbytes = ssh1_bignum_length(ctx->qmask);
|
||||||
buf = smalloc(nbytes);
|
buf = snewn(nbytes, unsigned char);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/*
|
/*
|
||||||
|
14
sshdss.c
14
sshdss.c
@ -91,7 +91,7 @@ static void *dss_newkey(char *data, int len)
|
|||||||
int slen;
|
int slen;
|
||||||
struct dss_key *dss;
|
struct dss_key *dss;
|
||||||
|
|
||||||
dss = smalloc(sizeof(struct dss_key));
|
dss = snew(struct dss_key);
|
||||||
if (!dss)
|
if (!dss)
|
||||||
return NULL;
|
return NULL;
|
||||||
getstring(&data, &len, &p, &slen);
|
getstring(&data, &len, &p, &slen);
|
||||||
@ -141,7 +141,7 @@ static char *dss_fmtkey(void *key)
|
|||||||
len += 4 * (bignum_bitcount(dss->q) + 15) / 16;
|
len += 4 * (bignum_bitcount(dss->q) + 15) / 16;
|
||||||
len += 4 * (bignum_bitcount(dss->g) + 15) / 16;
|
len += 4 * (bignum_bitcount(dss->g) + 15) / 16;
|
||||||
len += 4 * (bignum_bitcount(dss->y) + 15) / 16;
|
len += 4 * (bignum_bitcount(dss->y) + 15) / 16;
|
||||||
p = smalloc(len);
|
p = snewn(len, char);
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ static char *dss_fingerprint(void *key)
|
|||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
|
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
|
||||||
digest[i]);
|
digest[i]);
|
||||||
ret = smalloc(strlen(buffer) + 1);
|
ret = snewn(strlen(buffer) + 1, char);
|
||||||
if (ret)
|
if (ret)
|
||||||
strcpy(ret, buffer);
|
strcpy(ret, buffer);
|
||||||
return ret;
|
return ret;
|
||||||
@ -322,7 +322,7 @@ static unsigned char *dss_public_blob(void *key, int *len)
|
|||||||
* 27 + sum of lengths. (five length fields, 20+7=27).
|
* 27 + sum of lengths. (five length fields, 20+7=27).
|
||||||
*/
|
*/
|
||||||
bloblen = 27 + plen + qlen + glen + ylen;
|
bloblen = 27 + plen + qlen + glen + ylen;
|
||||||
blob = smalloc(bloblen);
|
blob = snewn(bloblen, unsigned char);
|
||||||
p = blob;
|
p = blob;
|
||||||
PUT_32BIT(p, 7);
|
PUT_32BIT(p, 7);
|
||||||
p += 4;
|
p += 4;
|
||||||
@ -362,7 +362,7 @@ static unsigned char *dss_private_blob(void *key, int *len)
|
|||||||
* mpint x, string[20] the SHA of p||q||g. Total 4 + xlen.
|
* mpint x, string[20] the SHA of p||q||g. Total 4 + xlen.
|
||||||
*/
|
*/
|
||||||
bloblen = 4 + xlen;
|
bloblen = 4 + xlen;
|
||||||
blob = smalloc(bloblen);
|
blob = snewn(bloblen, unsigned char);
|
||||||
p = blob;
|
p = blob;
|
||||||
PUT_32BIT(p, xlen);
|
PUT_32BIT(p, xlen);
|
||||||
p += 4;
|
p += 4;
|
||||||
@ -422,7 +422,7 @@ static void *dss_openssh_createkey(unsigned char **blob, int *len)
|
|||||||
char **b = (char **) blob;
|
char **b = (char **) blob;
|
||||||
struct dss_key *dss;
|
struct dss_key *dss;
|
||||||
|
|
||||||
dss = smalloc(sizeof(struct dss_key));
|
dss = snew(struct dss_key);
|
||||||
if (!dss)
|
if (!dss)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -606,7 +606,7 @@ static unsigned char *dss_sign(void *key, char *data, int datalen, int *siglen)
|
|||||||
* i.e. 4+7 + 4+40 bytes.
|
* i.e. 4+7 + 4+40 bytes.
|
||||||
*/
|
*/
|
||||||
nbytes = 4 + 7 + 4 + 40;
|
nbytes = 4 + 7 + 4 + 40;
|
||||||
bytes = smalloc(nbytes);
|
bytes = snewn(nbytes, unsigned char);
|
||||||
PUT_32BIT(bytes, 7);
|
PUT_32BIT(bytes, 7);
|
||||||
memcpy(bytes + 4, "ssh-dss", 7);
|
memcpy(bytes + 4, "ssh-dss", 7);
|
||||||
PUT_32BIT(bytes + 4 + 7, 40);
|
PUT_32BIT(bytes + 4 + 7, 40);
|
||||||
|
2
sshmd5.c
2
sshmd5.c
@ -210,7 +210,7 @@ void MD5Final(unsigned char output[16], struct MD5Context *s)
|
|||||||
|
|
||||||
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)
|
||||||
|
16
sshpubk.c
16
sshpubk.c
@ -87,7 +87,7 @@ static int loadrsakey_main(FILE * fp, struct RSAKey *key, int pub_only,
|
|||||||
i += 4;
|
i += 4;
|
||||||
if (len - i < j)
|
if (len - i < j)
|
||||||
goto end;
|
goto end;
|
||||||
comment = smalloc(j + 1);
|
comment = snewn(j + 1, char);
|
||||||
if (comment) {
|
if (comment) {
|
||||||
memcpy(comment, buf + i, j);
|
memcpy(comment, buf + i, j);
|
||||||
comment[j] = '\0';
|
comment[j] = '\0';
|
||||||
@ -457,7 +457,7 @@ static char *read_body(FILE * fp)
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
size = 128;
|
size = 128;
|
||||||
text = smalloc(size);
|
text = snewn(size, char);
|
||||||
len = 0;
|
len = 0;
|
||||||
text[len] = '\0';
|
text[len] = '\0';
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ static char *read_body(FILE * fp)
|
|||||||
}
|
}
|
||||||
if (len + 1 > size) {
|
if (len + 1 > size) {
|
||||||
size += 128;
|
size += 128;
|
||||||
text = srealloc(text, size);
|
text = sresize(text, size, char);
|
||||||
}
|
}
|
||||||
text[len++] = c;
|
text[len++] = c;
|
||||||
text[len] = '\0';
|
text[len] = '\0';
|
||||||
@ -538,7 +538,7 @@ static unsigned char *read_blob(FILE * fp, int nlines, int *bloblen)
|
|||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
/* We expect at most 64 base64 characters, ie 48 real bytes, per line. */
|
/* 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;
|
len = 0;
|
||||||
for (i = 0; i < nlines; i++) {
|
for (i = 0; i < nlines; i++) {
|
||||||
line = read_body(fp);
|
line = read_body(fp);
|
||||||
@ -727,7 +727,7 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
|
|||||||
4 + commlen +
|
4 + commlen +
|
||||||
4 + public_blob_len +
|
4 + public_blob_len +
|
||||||
4 + private_blob_len);
|
4 + private_blob_len);
|
||||||
macdata = smalloc(maclen);
|
macdata = snewn(maclen, unsigned char);
|
||||||
p = macdata;
|
p = macdata;
|
||||||
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
|
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
|
||||||
DO_STR(alg->name, namelen);
|
DO_STR(alg->name, namelen);
|
||||||
@ -778,7 +778,7 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
|
|||||||
/*
|
/*
|
||||||
* 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->alg = alg;
|
||||||
ret->comment = comment;
|
ret->comment = comment;
|
||||||
ret->data = alg->createkey(public_blob, public_blob_len,
|
ret->data = alg->createkey(public_blob, public_blob_len,
|
||||||
@ -1009,7 +1009,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
|
|||||||
}
|
}
|
||||||
priv_encrypted_len = priv_blob_len + cipherblk - 1;
|
priv_encrypted_len = priv_blob_len + cipherblk - 1;
|
||||||
priv_encrypted_len -= priv_encrypted_len % cipherblk;
|
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);
|
memset(priv_blob_encrypted, 0, priv_encrypted_len);
|
||||||
memcpy(priv_blob_encrypted, priv_blob, priv_blob_len);
|
memcpy(priv_blob_encrypted, priv_blob, priv_blob_len);
|
||||||
/* Create padding based on the SHA hash of the unpadded blob. This prevents
|
/* Create padding based on the SHA hash of the unpadded blob. This prevents
|
||||||
@ -1036,7 +1036,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
|
|||||||
4 + commlen +
|
4 + commlen +
|
||||||
4 + pub_blob_len +
|
4 + pub_blob_len +
|
||||||
4 + priv_encrypted_len);
|
4 + priv_encrypted_len);
|
||||||
macdata = smalloc(maclen);
|
macdata = snewn(maclen, unsigned char);
|
||||||
p = macdata;
|
p = macdata;
|
||||||
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
|
#define DO_STR(s,len) PUT_32BIT(p,(len));memcpy(p+4,(s),(len));p+=4+(len)
|
||||||
DO_STR(key->alg->name, namelen);
|
DO_STR(key->alg->name, namelen);
|
||||||
|
@ -202,7 +202,7 @@ int random_byte(void)
|
|||||||
|
|
||||||
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();
|
random_stir();
|
||||||
memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2);
|
memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2);
|
||||||
*len = POOLSIZE / 2;
|
*len = POOLSIZE / 2;
|
||||||
|
18
sshrsa.c
18
sshrsa.c
@ -316,7 +316,7 @@ unsigned char *rsa_public_blob(struct RSAKey *key, int *len)
|
|||||||
|
|
||||||
length = (ssh1_bignum_length(key->modulus) +
|
length = (ssh1_bignum_length(key->modulus) +
|
||||||
ssh1_bignum_length(key->exponent) + 4);
|
ssh1_bignum_length(key->exponent) + 4);
|
||||||
ret = smalloc(length);
|
ret = snewn(length, unsigned char);
|
||||||
|
|
||||||
PUT_32BIT(ret, bignum_bitcount(key->modulus));
|
PUT_32BIT(ret, bignum_bitcount(key->modulus));
|
||||||
pos = 4;
|
pos = 4;
|
||||||
@ -388,7 +388,7 @@ static void *rsa2_newkey(char *data, int len)
|
|||||||
int slen;
|
int slen;
|
||||||
struct RSAKey *rsa;
|
struct RSAKey *rsa;
|
||||||
|
|
||||||
rsa = smalloc(sizeof(struct RSAKey));
|
rsa = snew(struct RSAKey);
|
||||||
if (!rsa)
|
if (!rsa)
|
||||||
return NULL;
|
return NULL;
|
||||||
getstring(&data, &len, &p, &slen);
|
getstring(&data, &len, &p, &slen);
|
||||||
@ -419,7 +419,7 @@ static char *rsa2_fmtkey(void *key)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = rsastr_len(rsa);
|
len = rsastr_len(rsa);
|
||||||
p = smalloc(len);
|
p = snewn(len, char);
|
||||||
rsastr_fmt(p, rsa);
|
rsastr_fmt(p, rsa);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ static unsigned char *rsa2_public_blob(void *key, int *len)
|
|||||||
* (three length fields, 12+7=19).
|
* (three length fields, 12+7=19).
|
||||||
*/
|
*/
|
||||||
bloblen = 19 + elen + mlen;
|
bloblen = 19 + elen + mlen;
|
||||||
blob = smalloc(bloblen);
|
blob = snewn(bloblen, unsigned char);
|
||||||
p = blob;
|
p = blob;
|
||||||
PUT_32BIT(p, 7);
|
PUT_32BIT(p, 7);
|
||||||
p += 4;
|
p += 4;
|
||||||
@ -475,7 +475,7 @@ static unsigned char *rsa2_private_blob(void *key, int *len)
|
|||||||
* sum of lengths.
|
* sum of lengths.
|
||||||
*/
|
*/
|
||||||
bloblen = 16 + dlen + plen + qlen + ulen;
|
bloblen = 16 + dlen + plen + qlen + ulen;
|
||||||
blob = smalloc(bloblen);
|
blob = snewn(bloblen, unsigned char);
|
||||||
p = blob;
|
p = blob;
|
||||||
PUT_32BIT(p, dlen);
|
PUT_32BIT(p, dlen);
|
||||||
p += 4;
|
p += 4;
|
||||||
@ -523,7 +523,7 @@ static void *rsa2_openssh_createkey(unsigned char **blob, int *len)
|
|||||||
char **b = (char **) blob;
|
char **b = (char **) blob;
|
||||||
struct RSAKey *rsa;
|
struct RSAKey *rsa;
|
||||||
|
|
||||||
rsa = smalloc(sizeof(struct RSAKey));
|
rsa = snew(struct RSAKey);
|
||||||
if (!rsa)
|
if (!rsa)
|
||||||
return NULL;
|
return NULL;
|
||||||
rsa->comment = NULL;
|
rsa->comment = NULL;
|
||||||
@ -608,7 +608,7 @@ static char *rsa2_fingerprint(void *key)
|
|||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
|
sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
|
||||||
digest[i]);
|
digest[i]);
|
||||||
ret = smalloc(strlen(buffer) + 1);
|
ret = snewn(strlen(buffer) + 1, char);
|
||||||
if (ret)
|
if (ret)
|
||||||
strcpy(ret, buffer);
|
strcpy(ret, buffer);
|
||||||
return ret;
|
return ret;
|
||||||
@ -705,7 +705,7 @@ static unsigned char *rsa2_sign(void *key, char *data, int datalen,
|
|||||||
SHA_Simple(data, datalen, hash);
|
SHA_Simple(data, datalen, hash);
|
||||||
|
|
||||||
nbytes = (bignum_bitcount(rsa->modulus) - 1) / 8;
|
nbytes = (bignum_bitcount(rsa->modulus) - 1) / 8;
|
||||||
bytes = smalloc(nbytes);
|
bytes = snewn(nbytes, unsigned char);
|
||||||
|
|
||||||
bytes[0] = 1;
|
bytes[0] = 1;
|
||||||
for (i = 1; i < nbytes - 20 - ASN1_LEN; i++)
|
for (i = 1; i < nbytes - 20 - ASN1_LEN; i++)
|
||||||
@ -722,7 +722,7 @@ static unsigned char *rsa2_sign(void *key, char *data, int datalen,
|
|||||||
freebn(in);
|
freebn(in);
|
||||||
|
|
||||||
nbytes = (bignum_bitcount(out) + 7) / 8;
|
nbytes = (bignum_bitcount(out) + 7) / 8;
|
||||||
bytes = smalloc(4 + 7 + 4 + nbytes);
|
bytes = snewn(4 + 7 + 4 + nbytes, unsigned char);
|
||||||
PUT_32BIT(bytes, 7);
|
PUT_32BIT(bytes, 7);
|
||||||
memcpy(bytes + 4, "ssh-rsa", 7);
|
memcpy(bytes + 4, "ssh-rsa", 7);
|
||||||
PUT_32BIT(bytes + 4 + 7, nbytes);
|
PUT_32BIT(bytes + 4 + 7, nbytes);
|
||||||
|
2
sshsha.c
2
sshsha.c
@ -195,7 +195,7 @@ void SHA_Simple(void *p, int len, unsigned char *output)
|
|||||||
|
|
||||||
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)
|
||||||
|
17
sshzlib.c
17
sshzlib.c
@ -126,7 +126,7 @@ static int lz77_init(struct LZ77Context *ctx)
|
|||||||
struct LZ77InternalContext *st;
|
struct LZ77InternalContext *st;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
st = (struct LZ77InternalContext *) smalloc(sizeof(*st));
|
st = snew(struct LZ77InternalContext);
|
||||||
if (!st)
|
if (!st)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -354,7 +354,7 @@ static void outbits(struct Outbuf *out, unsigned long bits, int nbits)
|
|||||||
while (out->noutbits >= 8) {
|
while (out->noutbits >= 8) {
|
||||||
if (out->outlen >= out->outsize) {
|
if (out->outlen >= out->outsize) {
|
||||||
out->outsize = out->outlen + 64;
|
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->outbuf[out->outlen++] = (unsigned char) (out->outbits & 0xFF);
|
||||||
out->outbits >>= 8;
|
out->outbits >>= 8;
|
||||||
@ -583,13 +583,13 @@ static void zlib_match(struct LZ77Context *ectx, int distance, int len)
|
|||||||
void *zlib_compress_init(void)
|
void *zlib_compress_init(void)
|
||||||
{
|
{
|
||||||
struct Outbuf *out;
|
struct Outbuf *out;
|
||||||
struct LZ77Context *ectx = smalloc(sizeof(struct LZ77Context));
|
struct LZ77Context *ectx = snew(struct LZ77Context);
|
||||||
|
|
||||||
lz77_init(ectx);
|
lz77_init(ectx);
|
||||||
ectx->literal = zlib_literal;
|
ectx->literal = zlib_literal;
|
||||||
ectx->match = zlib_match;
|
ectx->match = zlib_match;
|
||||||
|
|
||||||
out = smalloc(sizeof(struct Outbuf));
|
out = snew(struct Outbuf);
|
||||||
out->outbits = out->noutbits = 0;
|
out->outbits = out->noutbits = 0;
|
||||||
out->firstblock = 1;
|
out->firstblock = 1;
|
||||||
out->comp_disabled = FALSE;
|
out->comp_disabled = FALSE;
|
||||||
@ -806,11 +806,11 @@ static struct zlib_table *zlib_mkonetab(int *codes, unsigned char *lengths,
|
|||||||
int nsyms,
|
int nsyms,
|
||||||
int pfx, int pfxbits, int bits)
|
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 pfxmask = (1 << pfxbits) - 1;
|
||||||
int nbits, i, j, code;
|
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;
|
tab->mask = (1 << bits) - 1;
|
||||||
|
|
||||||
for (code = 0; code <= tab->mask; code++) {
|
for (code = 0; code <= tab->mask; code++) {
|
||||||
@ -941,8 +941,7 @@ struct zlib_decompress_ctx {
|
|||||||
|
|
||||||
void *zlib_decompress_init(void)
|
void *zlib_decompress_init(void)
|
||||||
{
|
{
|
||||||
struct zlib_decompress_ctx *dctx =
|
struct zlib_decompress_ctx *dctx = snew(struct zlib_decompress_ctx);
|
||||||
smalloc(sizeof(struct zlib_decompress_ctx));
|
|
||||||
unsigned char lengths[288];
|
unsigned char lengths[288];
|
||||||
|
|
||||||
memset(lengths, 8, 144);
|
memset(lengths, 8, 144);
|
||||||
@ -1002,7 +1001,7 @@ static void zlib_emit_char(struct zlib_decompress_ctx *dctx, int c)
|
|||||||
dctx->winpos = (dctx->winpos + 1) & (WINSIZE - 1);
|
dctx->winpos = (dctx->winpos + 1) & (WINSIZE - 1);
|
||||||
if (dctx->outlen >= dctx->outsize) {
|
if (dctx->outlen >= dctx->outsize) {
|
||||||
dctx->outsize = dctx->outlen + 512;
|
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;
|
||||||
}
|
}
|
||||||
|
15
telnet.c
15
telnet.c
@ -611,18 +611,11 @@ static void do_telnet_read(Telnet telnet, char *buf, int len)
|
|||||||
else {
|
else {
|
||||||
subneg_addchar:
|
subneg_addchar:
|
||||||
if (telnet->sb_len >= telnet->sb_size) {
|
if (telnet->sb_len >= telnet->sb_size) {
|
||||||
unsigned char *newbuf;
|
|
||||||
telnet->sb_size += SB_DELTA;
|
telnet->sb_size += SB_DELTA;
|
||||||
newbuf = (telnet->sb_buf ?
|
telnet->sb_buf = sresize(telnet->sb_buf, telnet->sb_size,
|
||||||
srealloc(telnet->sb_buf, telnet->sb_size) :
|
unsigned char);
|
||||||
smalloc(telnet->sb_size));
|
|
||||||
if (newbuf)
|
|
||||||
telnet->sb_buf = newbuf;
|
|
||||||
else
|
|
||||||
telnet->sb_size -= SB_DELTA;
|
|
||||||
}
|
}
|
||||||
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 */
|
telnet->state = SUBNEGOT; /* in case we came here by goto */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -691,7 +684,7 @@ static char *telnet_init(void *frontend_handle, void **backend_handle,
|
|||||||
char *err;
|
char *err;
|
||||||
Telnet telnet;
|
Telnet telnet;
|
||||||
|
|
||||||
telnet = smalloc(sizeof(*telnet));
|
telnet = snew(struct telnet_tag);
|
||||||
telnet->fn = &fn_table;
|
telnet->fn = &fn_table;
|
||||||
telnet->cfg = *cfg; /* STRUCTURE COPY */
|
telnet->cfg = *cfg; /* STRUCTURE COPY */
|
||||||
telnet->s = NULL;
|
telnet->s = NULL;
|
||||||
|
27
terminal.c
27
terminal.c
@ -99,7 +99,7 @@ static unsigned long *resizeline(unsigned long *line, int cols)
|
|||||||
*/
|
*/
|
||||||
oldlen = line[0];
|
oldlen = line[0];
|
||||||
lineattrs = line[oldlen + 1];
|
lineattrs = line[oldlen + 1];
|
||||||
line = srealloc(line, TSIZE * (2 + cols));
|
line = sresize(line, 2 + cols, TTYPE);
|
||||||
line[0] = cols;
|
line[0] = cols;
|
||||||
for (i = oldlen; i < cols; i++)
|
for (i = oldlen; i < cols; i++)
|
||||||
line[i + 1] = ERASE_CHAR;
|
line[i + 1] = ERASE_CHAR;
|
||||||
@ -372,7 +372,7 @@ Terminal *term_init(Config *mycfg, struct unicode_data *ucsdata,
|
|||||||
* Allocate a new Terminal structure and initialise the fields
|
* Allocate a new Terminal structure and initialise the fields
|
||||||
* that need it.
|
* that need it.
|
||||||
*/
|
*/
|
||||||
term = smalloc(sizeof(Terminal));
|
term = snew(Terminal);
|
||||||
term->frontend = frontend;
|
term->frontend = frontend;
|
||||||
term->ucsdata = ucsdata;
|
term->ucsdata = ucsdata;
|
||||||
term->cfg = *mycfg; /* STRUCTURE COPY */
|
term->cfg = *mycfg; /* STRUCTURE COPY */
|
||||||
@ -511,7 +511,7 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines)
|
|||||||
term->savecurs.y += 1;
|
term->savecurs.y += 1;
|
||||||
} else {
|
} else {
|
||||||
/* Add a new blank line at the bottom of the screen. */
|
/* Add a new blank line at the bottom of the screen. */
|
||||||
line = smalloc(TSIZE * (newcols + 2));
|
line = snewn(newcols + 2, TTYPE);
|
||||||
line[0] = newcols;
|
line[0] = newcols;
|
||||||
for (j = 0; j < newcols; j++)
|
for (j = 0; j < newcols; j++)
|
||||||
line[j + 1] = ERASE_CHAR;
|
line[j + 1] = ERASE_CHAR;
|
||||||
@ -551,7 +551,7 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines)
|
|||||||
term->disptop = 0;
|
term->disptop = 0;
|
||||||
|
|
||||||
/* Make a new displayed text buffer. */
|
/* 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++)
|
for (i = 0; i < newrows * (newcols + 1); i++)
|
||||||
newdisp[i] = ATTR_INVALID;
|
newdisp[i] = ATTR_INVALID;
|
||||||
sfree(term->disptext);
|
sfree(term->disptext);
|
||||||
@ -561,7 +561,7 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines)
|
|||||||
/* Make a new alternate screen. */
|
/* Make a new alternate screen. */
|
||||||
newalt = newtree234(NULL);
|
newalt = newtree234(NULL);
|
||||||
for (i = 0; i < newrows; i++) {
|
for (i = 0; i < newrows; i++) {
|
||||||
line = smalloc(TSIZE * (newcols + 2));
|
line = snewn(newcols + 2, TTYPE);
|
||||||
line[0] = newcols;
|
line[0] = newcols;
|
||||||
for (j = 0; j < newcols; j++)
|
for (j = 0; j < newcols; j++)
|
||||||
line[j + 1] = term->erase_char;
|
line[j + 1] = term->erase_char;
|
||||||
@ -576,7 +576,7 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines)
|
|||||||
term->alt_screen = newalt;
|
term->alt_screen = newalt;
|
||||||
term->alt_sblines = 0;
|
term->alt_sblines = 0;
|
||||||
|
|
||||||
term->tabs = srealloc(term->tabs, newcols * sizeof(*term->tabs));
|
term->tabs = sresize(term->tabs, newcols, unsigned char);
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = (term->cols > 0 ? term->cols : 0); i < newcols; i++)
|
for (i = (term->cols > 0 ? term->cols : 0); i < newcols; i++)
|
||||||
@ -797,7 +797,7 @@ static void scroll(Terminal *term, int topline, int botline, int lines, int sb)
|
|||||||
if (sblen == term->savelines) {
|
if (sblen == term->savelines) {
|
||||||
sblen--, line2 = delpos234(term->scrollback, 0);
|
sblen--, line2 = delpos234(term->scrollback, 0);
|
||||||
} else {
|
} else {
|
||||||
line2 = smalloc(TSIZE * (term->cols + 2));
|
line2 = snewn(term->cols + 2, TTYPE);
|
||||||
line2[0] = term->cols;
|
line2[0] = term->cols;
|
||||||
term->tempsblines += 1;
|
term->tempsblines += 1;
|
||||||
}
|
}
|
||||||
@ -889,7 +889,7 @@ static void save_scroll(Terminal *term, int topline, int botline, int lines)
|
|||||||
term->scrolltail->botline == botline) {
|
term->scrolltail->botline == botline) {
|
||||||
term->scrolltail->lines += lines;
|
term->scrolltail->lines += lines;
|
||||||
} else {
|
} else {
|
||||||
newscroll = smalloc(sizeof(struct scrollregion));
|
newscroll = snew(struct scrollregion);
|
||||||
newscroll->topline = topline;
|
newscroll->topline = topline;
|
||||||
newscroll->botline = botline;
|
newscroll->botline = botline;
|
||||||
newscroll->lines = lines;
|
newscroll->lines = lines;
|
||||||
@ -1631,7 +1631,7 @@ void term_out(Terminal *term)
|
|||||||
ticks = GETTICKCOUNT();
|
ticks = GETTICKCOUNT();
|
||||||
|
|
||||||
if (!term->beep_overloaded) {
|
if (!term->beep_overloaded) {
|
||||||
newbeep = smalloc(sizeof(struct beeptime));
|
newbeep = snew(struct beeptime);
|
||||||
newbeep->ticks = ticks;
|
newbeep->ticks = ticks;
|
||||||
newbeep->next = NULL;
|
newbeep->next = NULL;
|
||||||
if (!term->beephead)
|
if (!term->beephead)
|
||||||
@ -3563,7 +3563,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect)
|
|||||||
int buflen; /* amount of memory allocated to workbuf */
|
int buflen; /* amount of memory allocated to workbuf */
|
||||||
|
|
||||||
buflen = 5120; /* Default size */
|
buflen = 5120; /* Default size */
|
||||||
workbuf = smalloc(buflen * sizeof(wchar_t));
|
workbuf = snewn(buflen, wchar_t);
|
||||||
wbptr = workbuf; /* start filling here */
|
wbptr = workbuf; /* start filling here */
|
||||||
old_top_x = top.x; /* needed for rect==1 */
|
old_top_x = top.x; /* needed for rect==1 */
|
||||||
|
|
||||||
@ -3679,9 +3679,8 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect)
|
|||||||
for (p = cbuf; *p; p++) {
|
for (p = cbuf; *p; p++) {
|
||||||
/* Enough overhead for trailing NL and nul */
|
/* Enough overhead for trailing NL and nul */
|
||||||
if (wblen >= buflen - 16) {
|
if (wblen >= buflen - 16) {
|
||||||
workbuf =
|
buflen += 100;
|
||||||
srealloc(workbuf,
|
workbuf = sresize(workbuf, buflen, wchar_t);
|
||||||
sizeof(wchar_t) * (buflen += 100));
|
|
||||||
wbptr = workbuf + wblen;
|
wbptr = workbuf + wblen;
|
||||||
}
|
}
|
||||||
wblen++;
|
wblen++;
|
||||||
@ -3950,7 +3949,7 @@ void term_do_paste(Terminal *term)
|
|||||||
if (term->paste_buffer)
|
if (term->paste_buffer)
|
||||||
sfree(term->paste_buffer);
|
sfree(term->paste_buffer);
|
||||||
term->paste_pos = term->paste_hold = term->paste_len = 0;
|
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;
|
p = q = data;
|
||||||
while (p < data + len) {
|
while (p < data + len) {
|
||||||
|
@ -53,7 +53,8 @@ struct terminal_tag {
|
|||||||
int beep_overloaded;
|
int beep_overloaded;
|
||||||
long lastbeep;
|
long lastbeep;
|
||||||
|
|
||||||
#define TSIZE (sizeof(unsigned long))
|
#define TTYPE unsigned long
|
||||||
|
#define TSIZE (sizeof(TTYPE))
|
||||||
#define fix_cpos do { \
|
#define fix_cpos do { \
|
||||||
term->cpos = lineptr(term->curs.y) + term->curs.x; \
|
term->cpos = lineptr(term->curs.y) + term->curs.x; \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $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 Simon Tatham
|
||||||
* Copyright (c) 1999 Ben Harris
|
* Copyright (c) 1999 Ben Harris
|
||||||
@ -77,7 +77,7 @@ static char *null_init(void *frontend_handle, void **backend_handle,
|
|||||||
static char *loop_init(void *frontend_handle, void **backend_handle,
|
static char *loop_init(void *frontend_handle, void **backend_handle,
|
||||||
Config *cfg, char *host, int port, char **realhost,
|
Config *cfg, char *host, int port, char **realhost,
|
||||||
int nodelay) {
|
int nodelay) {
|
||||||
struct loop_state *st = smalloc(sizeof(*st));
|
struct loop_state *st = snew(struct loop_state);
|
||||||
|
|
||||||
st->term = frontend_handle;
|
st->term = frontend_handle;
|
||||||
*backend_handle = st;
|
*backend_handle = st;
|
||||||
|
19
tree234.c
19
tree234.c
@ -29,13 +29,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "puttymem.h"
|
||||||
#include "tree234.h"
|
#include "tree234.h"
|
||||||
|
|
||||||
#define smalloc malloc
|
|
||||||
#define sfree free
|
|
||||||
|
|
||||||
#define mknew(typ) ( (typ *) smalloc (sizeof (typ)) )
|
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
#define LOG(x) (printf x)
|
#define LOG(x) (printf x)
|
||||||
#else
|
#else
|
||||||
@ -61,7 +57,7 @@ struct node234_Tag {
|
|||||||
*/
|
*/
|
||||||
tree234 *newtree234(cmpfn234 cmp)
|
tree234 *newtree234(cmpfn234 cmp)
|
||||||
{
|
{
|
||||||
tree234 *ret = mknew(tree234);
|
tree234 *ret = snew(tree234);
|
||||||
LOG(("created tree %p\n", ret));
|
LOG(("created tree %p\n", ret));
|
||||||
ret->root = NULL;
|
ret->root = NULL;
|
||||||
ret->cmp = cmp;
|
ret->cmp = cmp;
|
||||||
@ -128,7 +124,7 @@ static void *add234_internal(tree234 * t, void *e, int index)
|
|||||||
|
|
||||||
LOG(("adding node %p to tree %p\n", e, t));
|
LOG(("adding node %p to tree %p\n", e, t));
|
||||||
if (t->root == NULL) {
|
if (t->root == NULL) {
|
||||||
t->root = mknew(node234);
|
t->root = snew(node234);
|
||||||
t->root->elems[1] = t->root->elems[2] = NULL;
|
t->root->elems[1] = t->root->elems[2] = NULL;
|
||||||
t->root->kids[0] = t->root->kids[1] = NULL;
|
t->root->kids[0] = t->root->kids[1] = NULL;
|
||||||
t->root->kids[2] = t->root->kids[3] = NULL;
|
t->root->kids[2] = t->root->kids[3] = NULL;
|
||||||
@ -300,7 +296,7 @@ static void *add234_internal(tree234 * t, void *e, int index)
|
|||||||
LOG((" done\n"));
|
LOG((" done\n"));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
node234 *m = mknew(node234);
|
node234 *m = snew(node234);
|
||||||
m->parent = n->parent;
|
m->parent = n->parent;
|
||||||
LOG((" splitting a 4-node; created new node %p\n", m));
|
LOG((" splitting a 4-node; created new node %p\n", m));
|
||||||
/*
|
/*
|
||||||
@ -423,7 +419,7 @@ static void *add234_internal(tree234 * t, void *e, int index)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG((" root is overloaded, split into two\n"));
|
LOG((" root is overloaded, split into two\n"));
|
||||||
t->root = mknew(node234);
|
t->root = snew(node234);
|
||||||
t->root->kids[0] = left;
|
t->root->kids[0] = left;
|
||||||
t->root->counts[0] = lcount;
|
t->root->counts[0] = lcount;
|
||||||
t->root->elems[0] = e;
|
t->root->elems[0] = e;
|
||||||
@ -1012,8 +1008,6 @@ void *del234(tree234 * t, void *e)
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define srealloc realloc
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Error reporting function.
|
* Error reporting function.
|
||||||
*/
|
*/
|
||||||
@ -1201,8 +1195,7 @@ void internal_addtest(void *elem, int index, void *realret)
|
|||||||
|
|
||||||
if (arraysize < arraylen + 1) {
|
if (arraysize < arraylen + 1) {
|
||||||
arraysize = arraylen + 1 + 256;
|
arraysize = arraylen + 1 + 256;
|
||||||
array = (array == NULL ? smalloc(arraysize * sizeof(*array)) :
|
array = sresize(array, arraysize, void *);
|
||||||
srealloc(array, arraysize * sizeof(*array)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = index;
|
i = index;
|
||||||
|
@ -516,12 +516,12 @@ void init_ucs(Config *cfg, struct unicode_data *ucsdata)
|
|||||||
if (DIRECT_FONT(ucsdata->unitab_line[i]))
|
if (DIRECT_FONT(ucsdata->unitab_line[i]))
|
||||||
continue;
|
continue;
|
||||||
if (!ucsdata->uni_tbl) {
|
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 *));
|
memset(ucsdata->uni_tbl, 0, 256 * sizeof(char *));
|
||||||
}
|
}
|
||||||
j = ((ucsdata->unitab_line[i] >> 8) & 0xFF);
|
j = ((ucsdata->unitab_line[i] >> 8) & 0xFF);
|
||||||
if (!ucsdata->uni_tbl[j]) {
|
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));
|
memset(ucsdata->uni_tbl[j], 0, 256 * sizeof(char));
|
||||||
}
|
}
|
||||||
ucsdata->uni_tbl[j][ucsdata->unitab_line[i] & 0xFF] = i;
|
ucsdata->uni_tbl[j][ucsdata->unitab_line[i] & 0xFF] = i;
|
||||||
|
@ -207,6 +207,10 @@ void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
|
|||||||
{
|
{
|
||||||
struct dlgparam *dp = (struct dlgparam *)dlg;
|
struct dlgparam *dp = (struct dlgparam *)dlg;
|
||||||
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
|
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 = smalloc(size);
|
||||||
uc->privdata_needs_free = FALSE;
|
uc->privdata_needs_free = FALSE;
|
||||||
return uc->privdata;
|
return uc->privdata;
|
||||||
@ -379,7 +383,7 @@ void dlg_listbox_addwithid(union control *ctrl, void *dlg,
|
|||||||
|
|
||||||
assert(ncols <=
|
assert(ncols <=
|
||||||
(uc->ctrl->listbox.ncols ? uc->ctrl->listbox.ncols : 1));
|
(uc->ctrl->listbox.ncols ? uc->ctrl->listbox.ncols : 1));
|
||||||
percents = smalloc(ncols * sizeof(gint));
|
percents = snewn(ncols, gint);
|
||||||
percents[ncols-1] = 100;
|
percents[ncols-1] = 100;
|
||||||
for (i = 0; i < ncols-1; i++) {
|
for (i = 0; i < ncols-1; i++) {
|
||||||
percents[i] = uc->ctrl->listbox.percentages[i];
|
percents[i] = uc->ctrl->listbox.percentages[i];
|
||||||
@ -1244,7 +1248,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
|
|||||||
continue; /* no actual control created */
|
continue; /* no actual control created */
|
||||||
}
|
}
|
||||||
|
|
||||||
uc = smalloc(sizeof(struct uctrl));
|
uc = snew(struct uctrl);
|
||||||
uc->ctrl = ctrl;
|
uc->ctrl = ctrl;
|
||||||
uc->privdata = NULL;
|
uc->privdata = NULL;
|
||||||
uc->privdata_needs_free = FALSE;
|
uc->privdata_needs_free = FALSE;
|
||||||
@ -1309,7 +1313,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
|
|||||||
group = NULL;
|
group = NULL;
|
||||||
|
|
||||||
uc->nbuttons = ctrl->radio.nbuttons;
|
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++) {
|
for (i = 0; i < ctrl->radio.nbuttons; i++) {
|
||||||
GtkWidget *b;
|
GtkWidget *b;
|
||||||
@ -2038,8 +2042,8 @@ int do_config_box(const char *title)
|
|||||||
|
|
||||||
if (nselparams >= selparamsize) {
|
if (nselparams >= selparamsize) {
|
||||||
selparamsize += 16;
|
selparamsize += 16;
|
||||||
selparams = srealloc(selparams,
|
selparams = sresize(selparams, selparamsize,
|
||||||
selparamsize * sizeof(*selparams));
|
struct selparam);
|
||||||
}
|
}
|
||||||
selparams[nselparams].dp = &dp;
|
selparams[nselparams].dp = &dp;
|
||||||
selparams[nselparams].panels = PANELS(panels);
|
selparams[nselparams].panels = PANELS(panels);
|
||||||
@ -2059,7 +2063,7 @@ int do_config_box(const char *title)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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++) {
|
for (index = 0; index < nselparams; index++) {
|
||||||
gtk_signal_connect(GTK_OBJECT(selparams[index].treeitem), "select",
|
gtk_signal_connect(GTK_OBJECT(selparams[index].treeitem), "select",
|
||||||
|
24
unix/pterm.c
24
unix/pterm.c
@ -1283,7 +1283,7 @@ void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
|
|||||||
wchar_t *tmp = data;
|
wchar_t *tmp = data;
|
||||||
int tmplen = len;
|
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 = len*6;
|
||||||
inst->pasteout_data_utf8_len =
|
inst->pasteout_data_utf8_len =
|
||||||
charset_from_unicode(&tmp, &tmplen, inst->pasteout_data_utf8,
|
charset_from_unicode(&tmp, &tmplen, inst->pasteout_data_utf8,
|
||||||
@ -1294,15 +1294,15 @@ void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
|
|||||||
inst->pasteout_data_utf8 = NULL;
|
inst->pasteout_data_utf8 = NULL;
|
||||||
} else {
|
} else {
|
||||||
inst->pasteout_data_utf8 =
|
inst->pasteout_data_utf8 =
|
||||||
srealloc(inst->pasteout_data_utf8,
|
sresize(inst->pasteout_data_utf8,
|
||||||
inst->pasteout_data_utf8_len);
|
inst->pasteout_data_utf8_len, char);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
inst->pasteout_data_utf8 = NULL;
|
inst->pasteout_data_utf8 = NULL;
|
||||||
inst->pasteout_data_utf8_len = 0;
|
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 = len*6;
|
||||||
inst->pasteout_data_len = wc_to_mb(inst->ucsdata.line_codepage, 0,
|
inst->pasteout_data_len = wc_to_mb(inst->ucsdata.line_codepage, 0,
|
||||||
data, len, inst->pasteout_data,
|
data, len, inst->pasteout_data,
|
||||||
@ -1313,7 +1313,7 @@ void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
|
|||||||
inst->pasteout_data = NULL;
|
inst->pasteout_data = NULL;
|
||||||
} else {
|
} else {
|
||||||
inst->pasteout_data =
|
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,
|
||||||
@ -1414,7 +1414,7 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
|
|||||||
if (inst->pastein_data)
|
if (inst->pastein_data)
|
||||||
sfree(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 = seldata->length;
|
||||||
inst->pastein_data_len =
|
inst->pastein_data_len =
|
||||||
mb_to_wc((seldata->type == inst->utf8_string_atom ?
|
mb_to_wc((seldata->type == inst->utf8_string_atom ?
|
||||||
@ -1530,7 +1530,7 @@ Context get_ctx(void *frontend)
|
|||||||
if (!inst->area->window)
|
if (!inst->area->window)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
dctx = smalloc(sizeof(*dctx));
|
dctx = snew(struct draw_ctx);
|
||||||
dctx->inst = inst;
|
dctx->inst = inst;
|
||||||
dctx->gc = gdk_gc_new(inst->area->window);
|
dctx->gc = gdk_gc_new(inst->area->window);
|
||||||
return dctx;
|
return dctx;
|
||||||
@ -1627,7 +1627,7 @@ void do_text_internal(Context ctx, int x, int y, char *text, int len,
|
|||||||
wchar_t *wcs;
|
wchar_t *wcs;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
wcs = smalloc(sizeof(wchar_t) * (len+1));
|
wcs = snewn(len+1, wchar_t);
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
wcs[i] = (wchar_t) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
|
wcs[i] = (wchar_t) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
|
||||||
}
|
}
|
||||||
@ -1654,7 +1654,7 @@ void do_text_internal(Context ctx, int x, int y, char *text, int len,
|
|||||||
* and (c) the clip rectangle should prevent it causing
|
* and (c) the clip rectangle should prevent it causing
|
||||||
* trouble anyway.
|
* trouble anyway.
|
||||||
*/
|
*/
|
||||||
gwcs = smalloc(sizeof(GdkWChar) * (len*2+1));
|
gwcs = snewn(len*2+1, GdkWChar);
|
||||||
memset(gwcs, 0, sizeof(GdkWChar) * (len*2+1));
|
memset(gwcs, 0, sizeof(GdkWChar) * (len*2+1));
|
||||||
/*
|
/*
|
||||||
* FIXME: when we have a wide-char equivalent of
|
* FIXME: when we have a wide-char equivalent of
|
||||||
@ -1668,7 +1668,7 @@ void do_text_internal(Context ctx, int x, int y, char *text, int len,
|
|||||||
gwcs, len*2);
|
gwcs, len*2);
|
||||||
sfree(gwcs);
|
sfree(gwcs);
|
||||||
} else {
|
} else {
|
||||||
gcs = smalloc(sizeof(GdkWChar) * (len+1));
|
gcs = snewn(len+1, gchar);
|
||||||
wc_to_mb(inst->fontinfo[fontid].charset, 0,
|
wc_to_mb(inst->fontinfo[fontid].charset, 0,
|
||||||
wcs, len, gcs, len, ".", NULL, NULL);
|
wcs, len, gcs, len, ".", NULL, NULL);
|
||||||
gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
|
gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
|
||||||
@ -2129,7 +2129,7 @@ int do_cmdline(int argc, char **argv, int do_everything, Config *cfg)
|
|||||||
|
|
||||||
if (--argc > 0) {
|
if (--argc > 0) {
|
||||||
int i;
|
int i;
|
||||||
pty_argv = smalloc((argc+1) * sizeof(char *));
|
pty_argv = snewn(argc+1, char *);
|
||||||
++argv;
|
++argv;
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
pty_argv[i] = argv[i];
|
pty_argv[i] = argv[i];
|
||||||
@ -2293,7 +2293,7 @@ int main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* 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));
|
memset(inst, 0, sizeof(*inst));
|
||||||
inst->alt_keycode = -1; /* this one needs _not_ to be zero */
|
inst->alt_keycode = -1; /* this one needs _not_ to be zero */
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ static char *pty_init(void *frontend, void **backend_handle, Config *cfg,
|
|||||||
char *shellname;
|
char *shellname;
|
||||||
if (cfg->login_shell) {
|
if (cfg->login_shell) {
|
||||||
char *p = strrchr(shell, '/');
|
char *p = strrchr(shell, '/');
|
||||||
shellname = smalloc(2+strlen(shell));
|
shellname = snewn(2+strlen(shell), char);
|
||||||
p = p ? p+1 : shell;
|
p = p ? p+1 : shell;
|
||||||
sprintf(shellname, "-%s", p);
|
sprintf(shellname, "-%s", p);
|
||||||
} else
|
} else
|
||||||
|
@ -29,7 +29,7 @@ void platform_get_x11_auth(char *display, int *protocol,
|
|||||||
if (!fp)
|
if (!fp)
|
||||||
return; /* assume no auth */
|
return; /* assume no auth */
|
||||||
|
|
||||||
localbuf = smalloc(maxsize);
|
localbuf = snewn(maxsize, char);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/*
|
/*
|
||||||
|
@ -80,7 +80,7 @@ void agent_query(void *in, int inlen, void **out, int *outlen)
|
|||||||
}
|
}
|
||||||
retsize += 4;
|
retsize += 4;
|
||||||
assert(retbuf == sizebuf);
|
assert(retbuf == sizebuf);
|
||||||
retbuf = smalloc(retsize);
|
retbuf = snewn(retsize, char);
|
||||||
memcpy(retbuf, sizebuf, 4);
|
memcpy(retbuf, sizebuf, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
unix/uxnet.c
12
unix/uxnet.c
@ -119,7 +119,7 @@ char *error_string(int error)
|
|||||||
|
|
||||||
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;
|
unsigned long a;
|
||||||
struct hostent *h = NULL;
|
struct hostent *h = NULL;
|
||||||
char realhost[8192];
|
char realhost[8192];
|
||||||
@ -195,14 +195,14 @@ SockAddr sk_namelookup(const char *host, char **canonicalname)
|
|||||||
}
|
}
|
||||||
ret->address = ntohl(a);
|
ret->address = ntohl(a);
|
||||||
realhost[lenof(realhost)-1] = '\0';
|
realhost[lenof(realhost)-1] = '\0';
|
||||||
*canonicalname = smalloc(1+strlen(realhost));
|
*canonicalname = snewn(1+strlen(realhost), char);
|
||||||
strcpy(*canonicalname, realhost);
|
strcpy(*canonicalname, realhost);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddr sk_nonamelookup(const char *host)
|
SockAddr sk_nonamelookup(const char *host)
|
||||||
{
|
{
|
||||||
SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
|
SockAddr ret = snew(struct SockAddr_tag);
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->family = AF_UNSPEC;
|
ret->family = AF_UNSPEC;
|
||||||
strncpy(ret->hostname, host, lenof(ret->hostname));
|
strncpy(ret->hostname, host, lenof(ret->hostname));
|
||||||
@ -324,7 +324,7 @@ Socket sk_register(void *sock, 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->fn = &tcp_fn_table;
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
@ -367,7 +367,7 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
|
|||||||
/*
|
/*
|
||||||
* Create Socket structure.
|
* Create Socket structure.
|
||||||
*/
|
*/
|
||||||
ret = smalloc(sizeof(struct Socket_tag));
|
ret = snew(struct Socket_tag);
|
||||||
ret->fn = &tcp_fn_table;
|
ret->fn = &tcp_fn_table;
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
@ -525,7 +525,7 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only)
|
|||||||
/*
|
/*
|
||||||
* Create Socket structure.
|
* Create Socket structure.
|
||||||
*/
|
*/
|
||||||
ret = smalloc(sizeof(struct Socket_tag));
|
ret = snew(struct Socket_tag);
|
||||||
ret->fn = &tcp_fn_table;
|
ret->fn = &tcp_fn_table;
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
|
@ -446,13 +446,13 @@ int main(int argc, char **argv)
|
|||||||
while (*p) {
|
while (*p) {
|
||||||
if (cmdlen >= cmdsize) {
|
if (cmdlen >= cmdsize) {
|
||||||
cmdsize = cmdlen + 512;
|
cmdsize = cmdlen + 512;
|
||||||
command = srealloc(command, cmdsize);
|
command = sresize(command, cmdsize, char);
|
||||||
}
|
}
|
||||||
command[cmdlen++]=*p++;
|
command[cmdlen++]=*p++;
|
||||||
}
|
}
|
||||||
if (cmdlen >= cmdsize) {
|
if (cmdlen >= cmdsize) {
|
||||||
cmdsize = cmdlen + 512;
|
cmdsize = cmdlen + 512;
|
||||||
command = srealloc(command, cmdsize);
|
command = sresize(command, cmdsize, char);
|
||||||
}
|
}
|
||||||
command[cmdlen++]=' '; /* always add trailing space */
|
command[cmdlen++]=' '; /* always add trailing space */
|
||||||
if (--argc) p = *++argv;
|
if (--argc) p = *++argv;
|
||||||
@ -631,7 +631,7 @@ int main(int argc, char **argv)
|
|||||||
/* Expand the sklist buffer if necessary. */
|
/* Expand the sklist buffer if necessary. */
|
||||||
if (i > sksize) {
|
if (i > sksize) {
|
||||||
sksize = i + 16;
|
sksize = i + 16;
|
||||||
sklist = srealloc(sklist, sksize * sizeof(*sklist));
|
sklist = sresize(sklist, sksize, int);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -12,7 +12,7 @@ struct printer_job_tag {
|
|||||||
|
|
||||||
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
|
* On Unix, we treat the printer string as the name of a
|
||||||
* command to pipe to - typically lpr, of course.
|
* command to pipe to - typically lpr, of course.
|
||||||
|
@ -75,8 +75,8 @@ void provide_xrm_string(char *string)
|
|||||||
q++;
|
q++;
|
||||||
while (p > string && p[-1] != '.' && p[-1] != '*')
|
while (p > string && p[-1] != '.' && p[-1] != '*')
|
||||||
p--;
|
p--;
|
||||||
xrms = smalloc(sizeof(struct xrm_string));
|
xrms = snew(struct xrm_string);
|
||||||
key = smalloc(q-p);
|
key = snewn(q-p, char);
|
||||||
memcpy(key, p, q-p);
|
memcpy(key, p, q-p);
|
||||||
key[q-p-1] = '\0';
|
key[q-p-1] = '\0';
|
||||||
xrms->key = key;
|
xrms->key = key;
|
||||||
@ -199,14 +199,14 @@ static void make_filename(char *filename, int index)
|
|||||||
*/
|
*/
|
||||||
static char *fgetline(FILE *fp)
|
static char *fgetline(FILE *fp)
|
||||||
{
|
{
|
||||||
char *ret = smalloc(512);
|
char *ret = snewn(512, char);
|
||||||
int size = 512, len = 0;
|
int size = 512, len = 0;
|
||||||
while (fgets(ret + len, size - len, fp)) {
|
while (fgets(ret + len, size - len, fp)) {
|
||||||
len += strlen(ret + len);
|
len += strlen(ret + len);
|
||||||
if (ret[len-1] == '\n')
|
if (ret[len-1] == '\n')
|
||||||
break; /* got a newline, we're done */
|
break; /* got a newline, we're done */
|
||||||
size = len + 512;
|
size = len + 512;
|
||||||
ret = srealloc(ret, size);
|
ret = sresize(ret, size, char);
|
||||||
}
|
}
|
||||||
if (len == 0) { /* first fgets returned NULL */
|
if (len == 0) { /* first fgets returned NULL */
|
||||||
sfree(ret);
|
sfree(ret);
|
||||||
|
26
wincfg.c
26
wincfg.c
@ -128,19 +128,15 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
|
|||||||
assert(c->generic.handler == dlg_stdradiobutton_handler);
|
assert(c->generic.handler == dlg_stdradiobutton_handler);
|
||||||
c->radio.nbuttons++;
|
c->radio.nbuttons++;
|
||||||
c->radio.buttons =
|
c->radio.buttons =
|
||||||
srealloc(c->radio.buttons,
|
sresize(c->radio.buttons, c->radio.nbuttons, char *);
|
||||||
c->radio.nbuttons * sizeof(*c->radio.buttons));
|
|
||||||
c->radio.buttons[c->radio.nbuttons-1] =
|
c->radio.buttons[c->radio.nbuttons-1] =
|
||||||
dupstr("Play a custom sound file");
|
dupstr("Play a custom sound file");
|
||||||
c->radio.buttondata =
|
c->radio.buttondata =
|
||||||
srealloc(c->radio.buttondata,
|
sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
|
||||||
c->radio.nbuttons * sizeof(*c->radio.buttondata));
|
|
||||||
c->radio.buttondata[c->radio.nbuttons-1] = I(BELL_WAVEFILE);
|
c->radio.buttondata[c->radio.nbuttons-1] = I(BELL_WAVEFILE);
|
||||||
if (c->radio.shortcuts) {
|
if (c->radio.shortcuts) {
|
||||||
c->radio.shortcuts =
|
c->radio.shortcuts =
|
||||||
srealloc(c->radio.shortcuts,
|
sresize(c->radio.shortcuts, c->radio.nbuttons, char);
|
||||||
(c->radio.nbuttons *
|
|
||||||
sizeof(*c->radio.shortcuts)));
|
|
||||||
c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT;
|
c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -201,29 +197,23 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
|
|||||||
assert(c->generic.handler == dlg_stdradiobutton_handler);
|
assert(c->generic.handler == dlg_stdradiobutton_handler);
|
||||||
c->radio.nbuttons += 2;
|
c->radio.nbuttons += 2;
|
||||||
c->radio.buttons =
|
c->radio.buttons =
|
||||||
srealloc(c->radio.buttons,
|
sresize(c->radio.buttons, c->radio.nbuttons, char *);
|
||||||
c->radio.nbuttons * sizeof(*c->radio.buttons));
|
|
||||||
c->radio.buttons[c->radio.nbuttons-2] =
|
c->radio.buttons[c->radio.nbuttons-2] =
|
||||||
dupstr("Use font in both ANSI and OEM modes");
|
dupstr("Use font in both ANSI and OEM modes");
|
||||||
c->radio.buttons[c->radio.nbuttons-1] =
|
c->radio.buttons[c->radio.nbuttons-1] =
|
||||||
dupstr("Use font in OEM mode only");
|
dupstr("Use font in OEM mode only");
|
||||||
c->radio.buttondata =
|
c->radio.buttondata =
|
||||||
srealloc(c->radio.buttondata,
|
sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
|
||||||
c->radio.nbuttons * sizeof(*c->radio.buttondata));
|
|
||||||
c->radio.buttondata[c->radio.nbuttons-2] = I(VT_OEMANSI);
|
c->radio.buttondata[c->radio.nbuttons-2] = I(VT_OEMANSI);
|
||||||
c->radio.buttondata[c->radio.nbuttons-1] = I(VT_OEMONLY);
|
c->radio.buttondata[c->radio.nbuttons-1] = I(VT_OEMONLY);
|
||||||
if (!c->radio.shortcuts) {
|
if (!c->radio.shortcuts) {
|
||||||
int j;
|
int j;
|
||||||
c->radio.shortcuts =
|
c->radio.shortcuts = snewn(c->radio.nbuttons, char);
|
||||||
smalloc((c->radio.nbuttons *
|
|
||||||
sizeof(*c->radio.shortcuts)));
|
|
||||||
for (j = 0; j < c->radio.nbuttons; j++)
|
for (j = 0; j < c->radio.nbuttons; j++)
|
||||||
c->radio.shortcuts[j] = NO_SHORTCUT;
|
c->radio.shortcuts[j] = NO_SHORTCUT;
|
||||||
} else {
|
} else {
|
||||||
c->radio.shortcuts =
|
c->radio.shortcuts = sresize(c->radio.shortcuts,
|
||||||
srealloc(c->radio.shortcuts,
|
c->radio.nbuttons, char);
|
||||||
(c->radio.nbuttons *
|
|
||||||
sizeof(*c->radio.shortcuts)));
|
|
||||||
}
|
}
|
||||||
c->radio.shortcuts[c->radio.nbuttons-2] = 'b';
|
c->radio.shortcuts[c->radio.nbuttons-2] = 'b';
|
||||||
c->radio.shortcuts[c->radio.nbuttons-1] = 'e';
|
c->radio.shortcuts[c->radio.nbuttons-1] = 'e';
|
||||||
|
38
winctrls.c
38
winctrls.c
@ -289,7 +289,7 @@ void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...)
|
|||||||
bid = va_arg(ap, int);
|
bid = va_arg(ap, int);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
buttons = smalloc(nbuttons * sizeof(struct radio));
|
buttons = snewn(nbuttons, struct radio);
|
||||||
va_start(ap, nacross);
|
va_start(ap, nacross);
|
||||||
for (i = 0; i < nbuttons; i++) {
|
for (i = 0; i < nbuttons; i++) {
|
||||||
buttons[i].text = va_arg(ap, char *);
|
buttons[i].text = va_arg(ap, char *);
|
||||||
@ -320,7 +320,7 @@ void bareradioline(struct ctlpos *cp, int nacross, ...)
|
|||||||
bid = va_arg(ap, int);
|
bid = va_arg(ap, int);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
buttons = smalloc(nbuttons * sizeof(struct radio));
|
buttons = snewn(nbuttons, struct radio);
|
||||||
va_start(ap, nacross);
|
va_start(ap, nacross);
|
||||||
for (i = 0; i < nbuttons; i++) {
|
for (i = 0; i < nbuttons; i++) {
|
||||||
buttons[i].text = va_arg(ap, char *);
|
buttons[i].text = va_arg(ap, char *);
|
||||||
@ -351,7 +351,7 @@ void radiobig(struct ctlpos *cp, char *text, int id, ...)
|
|||||||
bid = va_arg(ap, int);
|
bid = va_arg(ap, int);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
buttons = smalloc(nbuttons * sizeof(struct radio));
|
buttons = snewn(nbuttons, struct radio);
|
||||||
va_start(ap, id);
|
va_start(ap, id);
|
||||||
for (i = 0; i < nbuttons; i++) {
|
for (i = 0; i < nbuttons; i++) {
|
||||||
buttons[i].text = va_arg(ap, char *);
|
buttons[i].text = va_arg(ap, char *);
|
||||||
@ -395,10 +395,10 @@ char *staticwrap(struct ctlpos *cp, HWND hwnd, char *text, int *lines)
|
|||||||
RECT r;
|
RECT r;
|
||||||
HFONT oldfont, newfont;
|
HFONT oldfont, newfont;
|
||||||
|
|
||||||
ret = smalloc(1+strlen(text));
|
ret = snewn(1+strlen(text), char);
|
||||||
p = text;
|
p = text;
|
||||||
q = ret;
|
q = ret;
|
||||||
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
|
||||||
@ -973,7 +973,7 @@ static void pl_moveitem(HWND hwnd, int listid, int src, int dst)
|
|||||||
char *txt;
|
char *txt;
|
||||||
/* Get the item's data. */
|
/* Get the item's data. */
|
||||||
tlen = SendDlgItemMessage (hwnd, listid, LB_GETTEXTLEN, src, 0);
|
tlen = SendDlgItemMessage (hwnd, listid, LB_GETTEXTLEN, src, 0);
|
||||||
txt = smalloc(tlen+1);
|
txt = snewn(tlen+1, char);
|
||||||
SendDlgItemMessage (hwnd, listid, LB_GETTEXT, src, (LPARAM) txt);
|
SendDlgItemMessage (hwnd, listid, LB_GETTEXT, src, (LPARAM) txt);
|
||||||
val = SendDlgItemMessage (hwnd, listid, LB_GETITEMDATA, src, 0);
|
val = SendDlgItemMessage (hwnd, listid, LB_GETITEMDATA, src, 0);
|
||||||
/* Deselect old location. */
|
/* Deselect old location. */
|
||||||
@ -1176,7 +1176,7 @@ static char *shortcut_escape(char *text, char shortcut)
|
|||||||
if (!text)
|
if (!text)
|
||||||
return NULL; /* sfree won't choke on this */
|
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);
|
shortcut = tolower((unsigned char)shortcut);
|
||||||
|
|
||||||
p = text;
|
p = text;
|
||||||
@ -1338,7 +1338,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
|
|
||||||
/* Start a containing box, if we have a boxname. */
|
/* Start a containing box, if we have a boxname. */
|
||||||
if (s->boxname && *s->boxname) {
|
if (s->boxname && *s->boxname) {
|
||||||
struct winctrl *c = smalloc(sizeof(struct winctrl));
|
struct winctrl *c = snew(struct winctrl);
|
||||||
c->ctrl = NULL;
|
c->ctrl = NULL;
|
||||||
c->base_id = base_id;
|
c->base_id = base_id;
|
||||||
c->num_ids = 1;
|
c->num_ids = 1;
|
||||||
@ -1351,7 +1351,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
|
|
||||||
/* Draw a title, if we have one. */
|
/* Draw a title, if we have one. */
|
||||||
if (!s->boxname && s->boxtitle) {
|
if (!s->boxname && s->boxtitle) {
|
||||||
struct winctrl *c = smalloc(sizeof(struct winctrl));
|
struct winctrl *c = snew(struct winctrl);
|
||||||
c->ctrl = NULL;
|
c->ctrl = NULL;
|
||||||
c->base_id = base_id;
|
c->base_id = base_id;
|
||||||
c->num_ids = 1;
|
c->num_ids = 1;
|
||||||
@ -1534,7 +1534,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
ctrl->radio.shortcut);
|
ctrl->radio.shortcut);
|
||||||
shortcuts[nshortcuts++] = 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++) {
|
for (i = 0; i < ctrl->radio.nbuttons; i++) {
|
||||||
buttons[i].text =
|
buttons[i].text =
|
||||||
@ -1584,7 +1584,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
ctrl->listbox.shortcut);
|
ctrl->listbox.shortcut);
|
||||||
shortcuts[nshortcuts++] = ctrl->listbox.shortcut;
|
shortcuts[nshortcuts++] = ctrl->listbox.shortcut;
|
||||||
if (ctrl->listbox.draglist) {
|
if (ctrl->listbox.draglist) {
|
||||||
data = smalloc(sizeof(struct prefslist));
|
data = snew(struct prefslist);
|
||||||
num_ids = 4;
|
num_ids = 4;
|
||||||
prefslist(data, &pos, ctrl->listbox.height, escaped,
|
prefslist(data, &pos, ctrl->listbox.height, escaped,
|
||||||
base_id, base_id+1, base_id+2, base_id+3);
|
base_id, base_id+1, base_id+2, base_id+3);
|
||||||
@ -1616,7 +1616,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
int *tabarray;
|
int *tabarray;
|
||||||
int i, percent;
|
int i, percent;
|
||||||
|
|
||||||
tabarray = smalloc((ctrl->listbox.ncols-1) * sizeof(int));
|
tabarray = snewn(ctrl->listbox.ncols-1, int);
|
||||||
percent = 0;
|
percent = 0;
|
||||||
for (i = 0; i < ctrl->listbox.ncols-1; i++) {
|
for (i = 0; i < ctrl->listbox.ncols-1; i++) {
|
||||||
percent += ctrl->listbox.percentages[i];
|
percent += ctrl->listbox.percentages[i];
|
||||||
@ -1646,7 +1646,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
statictext(&pos, escaped, 1, base_id);
|
statictext(&pos, escaped, 1, base_id);
|
||||||
staticbtn(&pos, "", base_id+1, "Change...", base_id+2);
|
staticbtn(&pos, "", base_id+1, "Change...", base_id+2);
|
||||||
sfree(escaped);
|
sfree(escaped);
|
||||||
data = smalloc(sizeof(FontSpec));
|
data = snew(FontSpec);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"Can't happen");
|
assert(!"Can't happen");
|
||||||
@ -1660,7 +1660,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
|||||||
* (and isn't tabdelayed).
|
* (and isn't tabdelayed).
|
||||||
*/
|
*/
|
||||||
if (pos.hwnd) {
|
if (pos.hwnd) {
|
||||||
struct winctrl *c = smalloc(sizeof(struct winctrl));
|
struct winctrl *c = snew(struct winctrl);
|
||||||
|
|
||||||
c->ctrl = ctrl;
|
c->ctrl = ctrl;
|
||||||
c->base_id = actual_base_id;
|
c->base_id = actual_base_id;
|
||||||
@ -1814,7 +1814,7 @@ int winctrl_handle_command(struct dlgparam *dp, UINT msg,
|
|||||||
CB_GETCURSEL, 0, 0);
|
CB_GETCURSEL, 0, 0);
|
||||||
len = SendDlgItemMessage(dp->hwnd, c->base_id+1,
|
len = SendDlgItemMessage(dp->hwnd, c->base_id+1,
|
||||||
CB_GETLBTEXTLEN, index, 0);
|
CB_GETLBTEXTLEN, index, 0);
|
||||||
text = smalloc(len+1);
|
text = snewn(len+1, char);
|
||||||
SendDlgItemMessage(dp->hwnd, c->base_id+1, CB_GETLBTEXT,
|
SendDlgItemMessage(dp->hwnd, c->base_id+1, CB_GETLBTEXT,
|
||||||
index, (LPARAM)text);
|
index, (LPARAM)text);
|
||||||
SetDlgItemText(dp->hwnd, c->base_id+1, text);
|
SetDlgItemText(dp->hwnd, c->base_id+1, text);
|
||||||
@ -2503,7 +2503,7 @@ void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
|
|||||||
tmp.ctrl = ctrl;
|
tmp.ctrl = ctrl;
|
||||||
p = find234(dp->privdata, &tmp, NULL);
|
p = find234(dp->privdata, &tmp, NULL);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = smalloc(sizeof(struct perctrl_privdata));
|
p = snew(struct perctrl_privdata);
|
||||||
p->ctrl = ctrl;
|
p->ctrl = ctrl;
|
||||||
p->needs_free = FALSE;
|
p->needs_free = FALSE;
|
||||||
add234(dp->privdata, p);
|
add234(dp->privdata, p);
|
||||||
@ -2518,13 +2518,17 @@ void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
|
|||||||
tmp.ctrl = ctrl;
|
tmp.ctrl = ctrl;
|
||||||
p = find234(dp->privdata, &tmp, NULL);
|
p = find234(dp->privdata, &tmp, NULL);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = smalloc(sizeof(struct perctrl_privdata));
|
p = snew(struct perctrl_privdata);
|
||||||
p->ctrl = ctrl;
|
p->ctrl = ctrl;
|
||||||
p->needs_free = FALSE;
|
p->needs_free = FALSE;
|
||||||
add234(dp->privdata, p);
|
add234(dp->privdata, p);
|
||||||
}
|
}
|
||||||
assert(!p->needs_free);
|
assert(!p->needs_free);
|
||||||
p->needs_free = TRUE;
|
p->needs_free = TRUE;
|
||||||
|
/*
|
||||||
|
* This is an internal allocation routine, so it's allowed to
|
||||||
|
* use smalloc directly.
|
||||||
|
*/
|
||||||
p->data = smalloc(size);
|
p->data = smalloc(size);
|
||||||
return p->data;
|
return p->data;
|
||||||
}
|
}
|
||||||
|
8
windlg.c
8
windlg.c
@ -102,7 +102,7 @@ static int CALLBACK LogProc(HWND hwnd, UINT msg,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
selitems = smalloc(selcount * sizeof(int));
|
selitems = snewn(selcount, int);
|
||||||
if (selitems) {
|
if (selitems) {
|
||||||
int count = SendDlgItemMessage(hwnd, IDN_LIST,
|
int count = SendDlgItemMessage(hwnd, IDN_LIST,
|
||||||
LB_GETSELITEMS,
|
LB_GETSELITEMS,
|
||||||
@ -123,7 +123,7 @@ static int CALLBACK LogProc(HWND hwnd, UINT msg,
|
|||||||
size +=
|
size +=
|
||||||
strlen(events[selitems[i]]) + sizeof(sel_nl);
|
strlen(events[selitems[i]]) + sizeof(sel_nl);
|
||||||
|
|
||||||
clipdata = smalloc(size);
|
clipdata = snewn(size, char);
|
||||||
if (clipdata) {
|
if (clipdata) {
|
||||||
char *p = clipdata;
|
char *p = clipdata;
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
@ -648,14 +648,14 @@ void logevent(void *frontend, char *string)
|
|||||||
|
|
||||||
if (nevents >= negsize) {
|
if (nevents >= negsize) {
|
||||||
negsize += 64;
|
negsize += 64;
|
||||||
events = srealloc(events, negsize * sizeof(*events));
|
events = sresize(events, negsize, char *);
|
||||||
}
|
}
|
||||||
|
|
||||||
time(&t);
|
time(&t);
|
||||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
|
||||||
localtime(&t));
|
localtime(&t));
|
||||||
|
|
||||||
events[nevents] = smalloc(strlen(timebuf) + strlen(string) + 1);
|
events[nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
|
||||||
strcpy(events[nevents], timebuf);
|
strcpy(events[nevents], timebuf);
|
||||||
strcat(events[nevents], string);
|
strcat(events[nevents], string);
|
||||||
if (logbox) {
|
if (logbox) {
|
||||||
|
27
window.c
27
window.c
@ -600,7 +600,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
|||||||
{
|
{
|
||||||
char *bits;
|
char *bits;
|
||||||
int size = (font_width + 15) / 16 * 2 * font_height;
|
int size = (font_width + 15) / 16 * 2 * font_height;
|
||||||
bits = smalloc(size);
|
bits = snewn(size, char);
|
||||||
memset(bits, 0, size);
|
memset(bits, 0, size);
|
||||||
caretbm = CreateBitmap(font_width, font_height, 1, 1, bits);
|
caretbm = CreateBitmap(font_width, font_height, 1, 1, bits);
|
||||||
sfree(bits);
|
sfree(bits);
|
||||||
@ -999,6 +999,10 @@ static void init_palette(void)
|
|||||||
HDC hdc = GetDC(hwnd);
|
HDC hdc = GetDC(hwnd);
|
||||||
if (hdc) {
|
if (hdc) {
|
||||||
if (cfg.try_palette && GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) {
|
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)
|
logpal = smalloc(sizeof(*logpal)
|
||||||
- sizeof(logpal->palPalEntry)
|
- sizeof(logpal->palPalEntry)
|
||||||
+ NCOLOURS * sizeof(PALETTEENTRY));
|
+ NCOLOURS * sizeof(PALETTEENTRY));
|
||||||
@ -1723,7 +1727,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
|||||||
if ((lParam - IDM_SAVED_MIN) / 16 < sesslist.nsessions) {
|
if ((lParam - IDM_SAVED_MIN) / 16 < sesslist.nsessions) {
|
||||||
char *session =
|
char *session =
|
||||||
sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
|
sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
|
||||||
cl = smalloc(16 + strlen(session));
|
cl = snewn(16 + strlen(session), char);
|
||||||
/* 8, but play safe */
|
/* 8, but play safe */
|
||||||
if (!cl)
|
if (!cl)
|
||||||
cl = NULL;
|
cl = NULL;
|
||||||
@ -2531,7 +2535,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
|||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
int i;
|
int i;
|
||||||
buff = (char*) smalloc(n);
|
buff = snewn(n, char);
|
||||||
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
|
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
|
||||||
/*
|
/*
|
||||||
* Jaeyoun Chung reports that Korean character
|
* Jaeyoun Chung reports that Korean character
|
||||||
@ -2719,7 +2723,7 @@ void do_text(Context ctx, int x, int y, char *text, int len,
|
|||||||
int i;
|
int i;
|
||||||
if (len > IpDxLEN) {
|
if (len > IpDxLEN) {
|
||||||
sfree(IpDx);
|
sfree(IpDx);
|
||||||
IpDx = smalloc((len + 16) * sizeof(int));
|
IpDx = snewn(len + 16, int);
|
||||||
IpDxLEN = (len + 16);
|
IpDxLEN = (len + 16);
|
||||||
}
|
}
|
||||||
for (i = 0; i < IpDxLEN; i++)
|
for (i = 0; i < IpDxLEN; i++)
|
||||||
@ -2850,7 +2854,8 @@ void do_text(Context ctx, int x, int y, char *text, int len,
|
|||||||
int nlen, mptr;
|
int nlen, mptr;
|
||||||
if (len > uni_len) {
|
if (len > uni_len) {
|
||||||
sfree(uni_buf);
|
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++) {
|
||||||
@ -2910,7 +2915,7 @@ void do_text(Context ctx, int x, int y, char *text, int len,
|
|||||||
if (wlen < len) {
|
if (wlen < len) {
|
||||||
sfree(wbuf);
|
sfree(wbuf);
|
||||||
wlen = len;
|
wlen = len;
|
||||||
wbuf = smalloc(wlen * sizeof(WCHAR));
|
wbuf = snewn(wlen, WCHAR);
|
||||||
}
|
}
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
wbuf[i] = (WCHAR) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
|
wbuf[i] = (WCHAR) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
|
||||||
@ -3920,7 +3925,7 @@ void request_paste(void *frontend)
|
|||||||
void set_title(void *frontend, char *title)
|
void set_title(void *frontend, char *title)
|
||||||
{
|
{
|
||||||
sfree(window_name);
|
sfree(window_name);
|
||||||
window_name = smalloc(1 + strlen(title));
|
window_name = snewn(1 + strlen(title), char);
|
||||||
strcpy(window_name, title);
|
strcpy(window_name, title);
|
||||||
if (cfg.win_name_always || !IsIconic(hwnd))
|
if (cfg.win_name_always || !IsIconic(hwnd))
|
||||||
SetWindowText(hwnd, title);
|
SetWindowText(hwnd, title);
|
||||||
@ -3929,7 +3934,7 @@ void set_title(void *frontend, char *title)
|
|||||||
void set_icon(void *frontend, char *title)
|
void set_icon(void *frontend, char *title)
|
||||||
{
|
{
|
||||||
sfree(icon_name);
|
sfree(icon_name);
|
||||||
icon_name = smalloc(1 + strlen(title));
|
icon_name = snewn(1 + strlen(title), char);
|
||||||
strcpy(icon_name, title);
|
strcpy(icon_name, title);
|
||||||
if (!cfg.win_name_always && IsIconic(hwnd))
|
if (!cfg.win_name_always && IsIconic(hwnd))
|
||||||
SetWindowText(hwnd, title);
|
SetWindowText(hwnd, title);
|
||||||
@ -4100,7 +4105,7 @@ void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
|
|||||||
get_unitab(CP_ACP, unitab, 0);
|
get_unitab(CP_ACP, unitab, 0);
|
||||||
|
|
||||||
rtfsize = 100 + strlen(cfg.font.name);
|
rtfsize = 100 + strlen(cfg.font.name);
|
||||||
rtf = smalloc(rtfsize);
|
rtf = snewn(rtfsize, char);
|
||||||
sprintf(rtf, "{\\rtf1\\ansi%d{\\fonttbl\\f0\\fmodern %s;}\\f0",
|
sprintf(rtf, "{\\rtf1\\ansi%d{\\fonttbl\\f0\\fmodern %s;}\\f0",
|
||||||
GetACP(), cfg.font.name);
|
GetACP(), cfg.font.name);
|
||||||
rtflen = strlen(rtf);
|
rtflen = strlen(rtf);
|
||||||
@ -4165,7 +4170,7 @@ void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
|
|||||||
|
|
||||||
if (rtfsize < rtflen + totallen + 3) {
|
if (rtfsize < rtflen + totallen + 3) {
|
||||||
rtfsize = rtflen + totallen + 512;
|
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;
|
||||||
@ -4253,7 +4258,7 @@ void get_clip(void *frontend, wchar_t ** p, int *len)
|
|||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
s = GlobalLock(clipdata);
|
s = GlobalLock(clipdata);
|
||||||
i = MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, 0, 0);
|
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);
|
MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, converted, i);
|
||||||
*len = i - 1;
|
*len = i - 1;
|
||||||
return;
|
return;
|
||||||
|
12
winnet.c
12
winnet.c
@ -226,7 +226,7 @@ char *winsock_error_string(int error)
|
|||||||
|
|
||||||
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;
|
unsigned long a;
|
||||||
struct hostent *h = NULL;
|
struct hostent *h = NULL;
|
||||||
char realhost[8192];
|
char realhost[8192];
|
||||||
@ -357,14 +357,14 @@ SockAddr sk_namelookup(const char *host, char **canonicalname)
|
|||||||
}
|
}
|
||||||
ret->address = ntohl(a);
|
ret->address = ntohl(a);
|
||||||
realhost[lenof(realhost)-1] = '\0';
|
realhost[lenof(realhost)-1] = '\0';
|
||||||
*canonicalname = smalloc(1+strlen(realhost));
|
*canonicalname = snewn(1+strlen(realhost), char);
|
||||||
strcpy(*canonicalname, realhost);
|
strcpy(*canonicalname, realhost);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddr sk_nonamelookup(const char *host)
|
SockAddr sk_nonamelookup(const char *host)
|
||||||
{
|
{
|
||||||
SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
|
SockAddr ret = snew(struct SockAddr_tag);
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->family = AF_UNSPEC;
|
ret->family = AF_UNSPEC;
|
||||||
strncpy(ret->hostname, host, lenof(ret->hostname));
|
strncpy(ret->hostname, host, lenof(ret->hostname));
|
||||||
@ -490,7 +490,7 @@ Socket sk_register(void *sock, Plug plug)
|
|||||||
/*
|
/*
|
||||||
* Create Socket structure.
|
* Create Socket structure.
|
||||||
*/
|
*/
|
||||||
ret = smalloc(sizeof(struct Socket_tag));
|
ret = snew(struct Socket_tag);
|
||||||
ret->fn = &fn_table;
|
ret->fn = &fn_table;
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
@ -553,7 +553,7 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
|
|||||||
/*
|
/*
|
||||||
* Create Socket structure.
|
* Create Socket structure.
|
||||||
*/
|
*/
|
||||||
ret = smalloc(sizeof(struct Socket_tag));
|
ret = snew(struct Socket_tag);
|
||||||
ret->fn = &fn_table;
|
ret->fn = &fn_table;
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
@ -732,7 +732,7 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only)
|
|||||||
/*
|
/*
|
||||||
* Create Socket structure.
|
* Create Socket structure.
|
||||||
*/
|
*/
|
||||||
ret = smalloc(sizeof(struct Socket_tag));
|
ret = snew(struct Socket_tag);
|
||||||
ret->fn = &fn_table;
|
ret->fn = &fn_table;
|
||||||
ret->error = NULL;
|
ret->error = NULL;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
|
18
winstore.c
18
winstore.c
@ -70,7 +70,7 @@ void *open_settings_w(const char *sessionname)
|
|||||||
if (!sessionname || !*sessionname)
|
if (!sessionname || !*sessionname)
|
||||||
sessionname = "Default Settings";
|
sessionname = "Default Settings";
|
||||||
|
|
||||||
p = smalloc(3 * strlen(sessionname) + 1);
|
p = snewn(3 * strlen(sessionname) + 1, char);
|
||||||
mungestr(sessionname, p);
|
mungestr(sessionname, p);
|
||||||
|
|
||||||
ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
|
ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
|
||||||
@ -113,7 +113,7 @@ void *open_settings_r(const char *sessionname)
|
|||||||
if (!sessionname || !*sessionname)
|
if (!sessionname || !*sessionname)
|
||||||
sessionname = "Default Settings";
|
sessionname = "Default Settings";
|
||||||
|
|
||||||
p = smalloc(3 * strlen(sessionname) + 1);
|
p = snewn(3 * strlen(sessionname) + 1, char);
|
||||||
mungestr(sessionname, p);
|
mungestr(sessionname, p);
|
||||||
|
|
||||||
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
|
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
|
||||||
@ -231,7 +231,7 @@ void del_settings(const char *sessionname)
|
|||||||
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
|
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p = smalloc(3 * strlen(sessionname) + 1);
|
p = snewn(3 * strlen(sessionname) + 1, char);
|
||||||
mungestr(sessionname, p);
|
mungestr(sessionname, p);
|
||||||
RegDeleteKey(subkey1, p);
|
RegDeleteKey(subkey1, p);
|
||||||
sfree(p);
|
sfree(p);
|
||||||
@ -252,7 +252,7 @@ void *enum_settings_start(void)
|
|||||||
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)
|
if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = smalloc(sizeof(*ret));
|
ret = snew(struct enumsettings);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret->key = key;
|
ret->key = key;
|
||||||
ret->i = 0;
|
ret->i = 0;
|
||||||
@ -265,7 +265,7 @@ char *enum_settings_next(void *handle, char *buffer, int buflen)
|
|||||||
{
|
{
|
||||||
struct enumsettings *e = (struct enumsettings *) handle;
|
struct enumsettings *e = (struct enumsettings *) handle;
|
||||||
char *otherbuf;
|
char *otherbuf;
|
||||||
otherbuf = smalloc(3 * buflen);
|
otherbuf = snewn(3 * buflen, char);
|
||||||
if (RegEnumKey(e->key, e->i++, otherbuf, 3 * buflen) == ERROR_SUCCESS) {
|
if (RegEnumKey(e->key, e->i++, otherbuf, 3 * buflen) == ERROR_SUCCESS) {
|
||||||
unmungestr(otherbuf, buffer, buflen);
|
unmungestr(otherbuf, buffer, buflen);
|
||||||
sfree(otherbuf);
|
sfree(otherbuf);
|
||||||
@ -310,8 +310,8 @@ int verify_host_key(const char *hostname, int port,
|
|||||||
* Now read a saved key in from the registry and see what it
|
* Now read a saved key in from the registry and see what it
|
||||||
* says.
|
* says.
|
||||||
*/
|
*/
|
||||||
otherstr = smalloc(len);
|
otherstr = snewn(len, char);
|
||||||
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);
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ int verify_host_key(const char *hostname, int port,
|
|||||||
* under just the hostname and translate that.
|
* under just the hostname and translate that.
|
||||||
*/
|
*/
|
||||||
char *justhost = regname + 1 + strcspn(regname, ":");
|
char *justhost = regname + 1 + strcspn(regname, ":");
|
||||||
char *oldstyle = smalloc(len + 10); /* safety margin */
|
char *oldstyle = snewn(len + 10, char); /* safety margin */
|
||||||
readlen = len;
|
readlen = len;
|
||||||
ret = RegQueryValueEx(rkey, justhost, NULL, &type,
|
ret = RegQueryValueEx(rkey, justhost, NULL, &type,
|
||||||
oldstyle, &readlen);
|
oldstyle, &readlen);
|
||||||
@ -406,7 +406,7 @@ void store_host_key(const char *hostname, int port,
|
|||||||
char *regname;
|
char *regname;
|
||||||
HKEY rkey;
|
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);
|
||||||
|
|
||||||
|
10
winutils.c
10
winutils.c
@ -148,9 +148,9 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
|
|||||||
* This will guaranteeably be big enough; we can realloc it
|
* This will guaranteeably be big enough; we can realloc it
|
||||||
* down later.
|
* down later.
|
||||||
*/
|
*/
|
||||||
outputline = smalloc(1+strlen(cmdline));
|
outputline = snewn(1+strlen(cmdline), char);
|
||||||
outputargv = smalloc(sizeof(char *) * (strlen(cmdline)+1 / 2));
|
outputargv = snewn(strlen(cmdline)+1 / 2, char *);
|
||||||
outputargstart = smalloc(sizeof(char *) * (strlen(cmdline)+1 / 2));
|
outputargstart = snewn(strlen(cmdline)+1 / 2, char *);
|
||||||
|
|
||||||
p = cmdline; q = outputline; outputargc = 0;
|
p = cmdline; q = outputline; outputargc = 0;
|
||||||
|
|
||||||
@ -217,8 +217,8 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
|
|||||||
*q++ = '\0';
|
*q++ = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
outputargv = srealloc(outputargv, sizeof(char *) * outputargc);
|
outputargv = sresize(outputargv, outputargc, char *);
|
||||||
outputargstart = srealloc(outputargstart, sizeof(char *) * outputargc);
|
outputargstart = sresize(outputargstart, outputargc, char *);
|
||||||
|
|
||||||
if (argc) *argc = outputargc;
|
if (argc) *argc = outputargc;
|
||||||
if (argv) *argv = outputargv; else sfree(outputargv);
|
if (argv) *argv = outputargv; else sfree(outputargv);
|
||||||
|
10
x11fwd.c
10
x11fwd.c
@ -81,7 +81,7 @@ struct X11Private {
|
|||||||
void *x11_invent_auth(char *proto, int protomaxlen,
|
void *x11_invent_auth(char *proto, int protomaxlen,
|
||||||
char *data, int datamaxlen, int proto_id)
|
char *data, int datamaxlen, int proto_id)
|
||||||
{
|
{
|
||||||
struct X11Auth *auth = smalloc(sizeof(struct X11Auth));
|
struct X11Auth *auth = snew(struct X11Auth);
|
||||||
char ourdata[64];
|
char ourdata[64];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ char *x11_init(Socket * s, char *display, void *c, void *auth,
|
|||||||
/*
|
/*
|
||||||
* Open socket.
|
* Open socket.
|
||||||
*/
|
*/
|
||||||
pr = (struct X11Private *) smalloc(sizeof(struct X11Private));
|
pr = snew(struct X11Private);
|
||||||
pr->fn = &fn_table;
|
pr->fn = &fn_table;
|
||||||
pr->auth_protocol = NULL;
|
pr->auth_protocol = NULL;
|
||||||
pr->auth = (struct X11Auth *)auth;
|
pr->auth = (struct X11Auth *)auth;
|
||||||
@ -384,8 +384,8 @@ int x11_send(Socket s, char *data, int len)
|
|||||||
pr->auth_psize = (pr->auth_plen + 3) & ~3;
|
pr->auth_psize = (pr->auth_plen + 3) & ~3;
|
||||||
pr->auth_dsize = (pr->auth_dlen + 3) & ~3;
|
pr->auth_dsize = (pr->auth_dlen + 3) & ~3;
|
||||||
/* Leave room for a terminating zero, to make our lives easier. */
|
/* Leave room for a terminating zero, to make our lives easier. */
|
||||||
pr->auth_protocol = (char *) smalloc(pr->auth_psize + 1);
|
pr->auth_protocol = snewn(pr->auth_psize + 1, char);
|
||||||
pr->auth_data = (unsigned char *) smalloc(pr->auth_dsize);
|
pr->auth_data = snewn(pr->auth_dsize, char);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -421,7 +421,7 @@ int x11_send(Socket s, char *data, int len)
|
|||||||
|
|
||||||
message = dupprintf("PuTTY X11 proxy: %s", err);
|
message = dupprintf("PuTTY X11 proxy: %s", err);
|
||||||
msglen = strlen(message);
|
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;
|
msgsize = (msglen + 3) & ~3;
|
||||||
reply[0] = 0; /* failure */
|
reply[0] = 0; /* failure */
|
||||||
reply[1] = msglen; /* length of reason string */
|
reply[1] = msglen; /* length of reason string */
|
||||||
|
Loading…
Reference in New Issue
Block a user