]> 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:26:27 +0000 (03:26 +0000)
committerChris Allegretta <chrisa@asty.org>
Mon, 25 Mar 2002 03:26:27 +0000 (03:26 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1143 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
nano.c

index 10295efa7bae7d9ac00b8ec359e26ef3d9bfd39b..11fcb2a5934bb1fbeaeb6bf8cd306c7c7082152e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,8 @@ CVS code -
 - nano.c:
   do_justify()
        - More fixes for indented justify (David Benbennick).
+  do_int_speller()
+       - Fix zombie processes and spelling buffer issues (Rocco Corsi).
   help_init()
        - Capitalize Meta altkeys.
        - Various fixes and string changes.
diff --git a/nano.c b/nano.c
index 7ae1f11a6eba0b703eac22ccca310d0bab1f375c..05ea73009ec4966ec40c9c0644b02da30d67964a 100644 (file)
--- a/nano.c
+++ b/nano.c
@@ -1487,11 +1487,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 */
 
@@ -1560,40 +1559,48 @@ int do_int_speller(char *tempfile_name)
        return FALSE;
     }
 
-    read_buff = charalloc(pipe_buff_size + 1);
+    /* Read-in the returned spelling errors */
 
-    /* Process the returned spelling errors */
+    read_buff_read = 0;
+    read_buff_size = pipe_buff_size + 1;
+    read_buff = read_buff_ptr = charalloc(read_buff_size);
 
-    while ((bytesread = read(in_fd[0], read_buff, pipe_buff_size)) > 0) {
+    while ((bytesread = read(in_fd[0], read_buff_ptr, pipe_buff_size)) > 0) {
 
-       read_buff[bytesread] = (char) NULL;
-       read_buff_word = read_buff_ptr = read_buff;
+       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;
+    }
 
-       while (*read_buff_ptr != (char) NULL) {
+    *read_buff_ptr = (char) NULL;
+    close(in_fd[0]);
 
-           /* Windows version may need to process additional char '\r' */
+    /* Process the spelling errors */
 
-           /* Possible problem here if last word not followed by '\n' */
+    read_buff_word = read_buff_ptr = read_buff;
 
-           if (*read_buff_ptr == '\n') {
-               *read_buff_ptr = (char) NULL;
-               if (!do_int_spell_fix(read_buff_word)) {
+    while (*read_buff_ptr) {
 
-                   close(in_fd[0]);
-                   free(read_buff);
-                   replace_abort();
-
-                   return TRUE;
+       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;
-               read_buff_word++;
            }
 
-           read_buff_ptr++;
+           read_buff_word = read_buff_ptr + 1;
        }
+
+       read_buff_ptr++;
     }
 
-    close(in_fd[0]);
+    /* 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();