mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 03:52:49 -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:
10
x11fwd.c
10
x11fwd.c
@ -81,7 +81,7 @@ struct X11Private {
|
||||
void *x11_invent_auth(char *proto, int protomaxlen,
|
||||
char *data, int datamaxlen, int proto_id)
|
||||
{
|
||||
struct X11Auth *auth = smalloc(sizeof(struct X11Auth));
|
||||
struct X11Auth *auth = snew(struct X11Auth);
|
||||
char ourdata[64];
|
||||
int i;
|
||||
|
||||
@ -282,7 +282,7 @@ char *x11_init(Socket * s, char *display, void *c, void *auth,
|
||||
/*
|
||||
* Open socket.
|
||||
*/
|
||||
pr = (struct X11Private *) smalloc(sizeof(struct X11Private));
|
||||
pr = snew(struct X11Private);
|
||||
pr->fn = &fn_table;
|
||||
pr->auth_protocol = NULL;
|
||||
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_dsize = (pr->auth_dlen + 3) & ~3;
|
||||
/* Leave room for a terminating zero, to make our lives easier. */
|
||||
pr->auth_protocol = (char *) smalloc(pr->auth_psize + 1);
|
||||
pr->auth_data = (unsigned char *) smalloc(pr->auth_dsize);
|
||||
pr->auth_protocol = snewn(pr->auth_psize + 1, char);
|
||||
pr->auth_data = snewn(pr->auth_dsize, char);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -421,7 +421,7 @@ int x11_send(Socket s, char *data, int len)
|
||||
|
||||
message = dupprintf("PuTTY X11 proxy: %s", err);
|
||||
msglen = strlen(message);
|
||||
reply = smalloc(8 + msglen+1 + 4); /* include zero byte */
|
||||
reply = snewn(8 + msglen+1 + 4, unsigned char); /* include zero */
|
||||
msgsize = (msglen + 3) & ~3;
|
||||
reply[0] = 0; /* failure */
|
||||
reply[1] = msglen; /* length of reason string */
|
||||
|
Reference in New Issue
Block a user