mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12: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:
15
telnet.c
15
telnet.c
@ -611,18 +611,11 @@ static void do_telnet_read(Telnet telnet, char *buf, int len)
|
||||
else {
|
||||
subneg_addchar:
|
||||
if (telnet->sb_len >= telnet->sb_size) {
|
||||
unsigned char *newbuf;
|
||||
telnet->sb_size += SB_DELTA;
|
||||
newbuf = (telnet->sb_buf ?
|
||||
srealloc(telnet->sb_buf, telnet->sb_size) :
|
||||
smalloc(telnet->sb_size));
|
||||
if (newbuf)
|
||||
telnet->sb_buf = newbuf;
|
||||
else
|
||||
telnet->sb_size -= SB_DELTA;
|
||||
telnet->sb_buf = sresize(telnet->sb_buf, telnet->sb_size,
|
||||
unsigned char);
|
||||
}
|
||||
if (telnet->sb_len < telnet->sb_size)
|
||||
telnet->sb_buf[telnet->sb_len++] = c;
|
||||
telnet->sb_buf[telnet->sb_len++] = c;
|
||||
telnet->state = SUBNEGOT; /* in case we came here by goto */
|
||||
}
|
||||
break;
|
||||
@ -691,7 +684,7 @@ static char *telnet_init(void *frontend_handle, void **backend_handle,
|
||||
char *err;
|
||||
Telnet telnet;
|
||||
|
||||
telnet = smalloc(sizeof(*telnet));
|
||||
telnet = snew(struct telnet_tag);
|
||||
telnet->fn = &fn_table;
|
||||
telnet->cfg = *cfg; /* STRUCTURE COPY */
|
||||
telnet->s = NULL;
|
||||
|
Reference in New Issue
Block a user