aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/channels.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/channels.c b/src/channels.c
index ef140ba2..f01d52e8 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -304,24 +304,25 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
return err;
}
-/* get ssh channel from local session? */
+/* return channel with corresponding local id, or NULL if not found */
ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id) {
- ssh_channel initchan = session->channels;
- ssh_channel channel;
-
- /* We assume we are always the local */
- if (initchan == NULL) {
- return NULL;
- }
+ ssh_channel initchan = session->channels;
+ ssh_channel channel = initchan;
- for (channel = initchan; channel->local_channel != id;
- channel=channel->next) {
- if (channel->next == initchan) {
- return NULL;
+ for (;;) {
+ if (channel == NULL) {
+ return NULL;
+ }
+ if (channel->local_channel == id) {
+ return channel;
+ }
+ if (channel->next == initchan) {
+ return NULL;
+ }
+ channel = channel->next;
}
- }
- return channel;
+ return NULL;
}
/**