]> git.wh0rd.org Git - nano.git/commitdiff
- nano.c:do_int_speller() - Fix zombie processes and spelling buffer issues (Rocco...
authorChris Allegretta <chrisa@asty.org>
Mon, 25 Mar 2002 03:37:19 +0000 (03:37 +0000)
committerChris Allegretta <chrisa@asty.org>
Mon, 25 Mar 2002 03:37:19 +0000 (03:37 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_1_0_branch/nano@1144 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

nano.c

diff --git a/nano.c b/nano.c
index 91ea1f9e8c128e5c602bb1c96ea0f6bb143b075b..9ff6ec107a64b906d3c93a0cd27898a7501ed1f6 100644 (file)
--- a/nano.c
+++ b/nano.c
@@ -1351,11 +1351,10 @@ int do_int_spell_fix(char *word)
 int do_int_speller(char *tempfile_name)
 {
     char *read_buff, *read_buff_ptr, *read_buff_word;
-    long pipe_buff_size;
+    size_t pipe_buff_size, read_buff_size, read_buff_read, bytesread;
     int in_fd[2], tempfile_fd;
     int spell_status;
     pid_t pid_spell;
-    ssize_t bytesread;
 
     /* Create a pipe to spell program */
 
@@ -1423,43 +1422,51 @@ int do_int_speller(char *tempfile_name)
        close(in_fd[0]);
        return FALSE;
     }
-
-    read_buff = nmalloc( pipe_buff_size + 1 );
-
-    /* Process the returned spelling errors */
-
-    while ( (bytesread = read(in_fd[0], read_buff, pipe_buff_size)) > 0) {
-
-       read_buff[bytesread] = (char) NULL;
-       read_buff_word = read_buff_ptr = read_buff;
-
-       while (*read_buff_ptr != (char) NULL) {
-
-           /* Windows version may need to process additional char '\r' */
-
-           /* Possible problem here if last word not followed by '\n' */
-
-           if (*read_buff_ptr == '\n') {
-               *read_buff_ptr = (char) NULL;
-               if (!do_int_spell_fix(read_buff_word)) { 
-
-                   close(in_fd[0]);
-                   free(read_buff);
-                   replace_abort();
-
-                   return TRUE;
-               }
-               read_buff_word = read_buff_ptr;
-               read_buff_word++;
-           }
-
-           read_buff_ptr++;
-       }
+  
+    /* Read-in the returned spelling errors */
+  
+    read_buff_read = 0;
+    read_buff_size = pipe_buff_size + 1;
+    read_buff = read_buff_ptr = nmalloc(read_buff_size * sizeof(char *));
+  
+    while ((bytesread = read(in_fd[0], read_buff_ptr, pipe_buff_size)) > 0) {
+  
+       read_buff_read += bytesread;
+       read_buff_size += pipe_buff_size;
+       read_buff = read_buff_ptr = nrealloc(read_buff, read_buff_size);
+       read_buff_ptr += read_buff_read;
     }
-
+  
+    *read_buff_ptr = (char) NULL;
     close(in_fd[0]);
-    free(read_buff);
-    replace_abort();
+  
+    /* Process the spelling errors */
+  
+    read_buff_word = read_buff_ptr = read_buff;
+  
+    while (*read_buff_ptr) {
+  
+       if ((*read_buff_ptr == '\n') || (*read_buff_ptr == '\r')) {
+           *read_buff_ptr = (char) NULL;
+           if (read_buff_word != read_buff_ptr) {
+               if (!do_int_spell_fix(read_buff_word)) {
+                   read_buff_word = read_buff_ptr;
+                   break;
+               }
+           }
+  
+           read_buff_word = read_buff_ptr + 1;
+       }
+
+       read_buff_ptr++;
+      }
+  
+    /* special case where last word doesn't end with \n or \r */
+    if (read_buff_word != read_buff_ptr)
+       do_int_spell_fix(read_buff_word);
+
+      free(read_buff);
+      replace_abort();
 
     /* Process end of spell process */