]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
If someone calls newtFormWatchFd multiple times with the same fd, overwrite the exist...
authorsopwith <sopwith>
Tue, 3 Apr 2001 21:53:14 +0000 (21:53 +0000)
committersopwith <sopwith>
Tue, 3 Apr 2001 21:53:14 +0000 (21:53 +0000)
form.c

diff --git a/form.c b/form.c
index 952f879475642478e553f4043336d36ed007f160..2d95d2aefa783d0adfafd67ec31e779ee34b09c9 100644 (file)
--- a/form.c
+++ b/form.c
@@ -1115,10 +1115,17 @@ void newtFormSetBackground(newtComponent co, int color) {
 
 void newtFormWatchFd(newtComponent co, int fd, int fdFlags) {
     struct form * form = co->data;
+    int i;
+
+    for (i = 0; i < form->numFds; i++)
+      if (form->fds[i].fd == fd)
+       break;
+
+    if(i >= form->numFds)
+      form->fds = realloc(form->fds, (++form->numFds) * sizeof(*form->fds));
 
-    form->fds = realloc(form->fds, (form->numFds + 1) * sizeof(*form->fds));
-    form->fds[form->numFds].fd = fd;
-    form->fds[form->numFds++].flags = fdFlags;
+    form->fds[i].fd = fd;
+    form->fds[i].flags = fdFlags;
     if (form->maxFd < fd) form->maxFd = fd;
 }