From: ben Date: Sun, 12 Jan 2003 13:50:04 +0000 (+0000) Subject: Correct code to insert into a doubly-linked list. X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/b89053c0750e42d88ff92e3efc3d546f18a6d435 Correct code to insert into a doubly-linked list. git-svn-id: svn://svn.tartarus.org/sgt/putty@2553 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/mac/macterm.c b/mac/macterm.c index b38c3ece..014260c1 100644 --- a/mac/macterm.c +++ b/mac/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.40 2003/01/12 01:25:34 ben Exp $ */ +/* $Id: macterm.c,v 1.41 2003/01/12 13:50:04 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999, 2002 Ben Harris @@ -188,7 +188,8 @@ void mac_startsession(Session *s) ShowWindow(s->window); s->next = sesslist; s->prev = s->next->prev; - s->next->prev = &s->next; + if (ret->next != NULL) + s->next->prev = &s->next; sesslist = s; } diff --git a/mac/mtcpnet.c b/mac/mtcpnet.c index 9d40051d..543caa14 100644 --- a/mac/mtcpnet.c +++ b/mac/mtcpnet.c @@ -504,7 +504,8 @@ Socket mactcp_new(SockAddr addr, int port, int privport, int oobinline, /* Add this to the list of all sockets */ ret->next = mactcp.socklist; ret->prev = &mactcp.socklist; - ret->next->prev = &ret->next; + if (ret->next != NULL) + ret->next->prev = &ret->next; mactcp.socklist = ret; return (Socket)ret; diff --git a/mac/otnet.c b/mac/otnet.c index 4c9ec4b4..baa7a8a5 100644 --- a/mac/otnet.c +++ b/mac/otnet.c @@ -313,6 +313,8 @@ Socket ot_new(SockAddr addr, int port, int privport, int oobinline, /* Add this to the list of all sockets */ ret->next = ot.socklist; ret->prev = &ot.socklist; + if (ret->next != NULL) + ret->next->prev = &ret->next; ot.socklist = ret; return (Socket) ret; @@ -462,9 +464,13 @@ void ot_recv(Actual_Socket s) if (s->frozen) return; - while ((o = OTRcv(s->ep, buf, sizeof(buf), &flags)) != kOTNoDataErr) { - plug_receive(s->plug, 0, buf, sizeof(buf)); - } + do { + o = OTRcv(s->ep, buf, sizeof(buf), &flags); + if (o > 0) + plug_receive(s->plug, 0, buf, sizeof(buf)); + if (o < 0 && o != kOTNoDataErr) + plug_closing(s->plug, NULL, 0, 0); /* XXX Error msg */ + } while (o > 0); }