1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05: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:
Simon Tatham
2003-03-29 16:14:26 +00:00
parent 70729da988
commit d36a4c3685
60 changed files with 385 additions and 389 deletions

10
misc.c
View File

@ -12,7 +12,7 @@
char *dupstr(const char *s)
{
int len = strlen(s);
char *p = smalloc(len + 1);
char *p = snewn(len + 1, char);
strcpy(p, s);
return p;
}
@ -34,7 +34,7 @@ char *dupcat(const char *s1, ...)
}
va_end(ap);
p = smalloc(len + 1);
p = snewn(len + 1, char);
strcpy(p, s1);
q = p + strlen(p);
@ -76,7 +76,7 @@ char *dupvprintf(const char *fmt, va_list ap)
char *buf;
int len, size;
buf = smalloc(512);
buf = snewn(512, char);
size = 512;
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. */
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) {
int grainlen = min(len, BUFFER_GRANULE);
struct bufchain_granule *newbuf;
newbuf = smalloc(sizeof(struct bufchain_granule));
newbuf = snew(struct bufchain_granule);
newbuf->bufpos = 0;
newbuf->buflen = grainlen;
memcpy(newbuf->buf, buf, grainlen);