1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-03 20:42: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

View File

@ -119,7 +119,7 @@ char *error_string(int error)
SockAddr sk_namelookup(const char *host, char **canonicalname)
{
SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
SockAddr ret = snew(struct SockAddr_tag);
unsigned long a;
struct hostent *h = NULL;
char realhost[8192];
@ -195,14 +195,14 @@ SockAddr sk_namelookup(const char *host, char **canonicalname)
}
ret->address = ntohl(a);
realhost[lenof(realhost)-1] = '\0';
*canonicalname = smalloc(1+strlen(realhost));
*canonicalname = snewn(1+strlen(realhost), char);
strcpy(*canonicalname, realhost);
return ret;
}
SockAddr sk_nonamelookup(const char *host)
{
SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
SockAddr ret = snew(struct SockAddr_tag);
ret->error = NULL;
ret->family = AF_UNSPEC;
strncpy(ret->hostname, host, lenof(ret->hostname));
@ -324,7 +324,7 @@ Socket sk_register(void *sock, Plug plug)
/*
* Create Socket structure.
*/
ret = smalloc(sizeof(struct Socket_tag));
ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
@ -367,7 +367,7 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
/*
* Create Socket structure.
*/
ret = smalloc(sizeof(struct Socket_tag));
ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;
@ -525,7 +525,7 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only)
/*
* Create Socket structure.
*/
ret = smalloc(sizeof(struct Socket_tag));
ret = snew(struct Socket_tag);
ret->fn = &tcp_fn_table;
ret->error = NULL;
ret->plug = plug;