Commit c5b8f52c authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

inserting: don't bother zero-terminating every single character

Just let read_line() zero-terminate the intermediate buffer when
the line is complete.
parent bcdc90e8
Showing with 2 additions and 4 deletions
+2 -4
...@@ -685,6 +685,7 @@ filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode) ...@@ -685,6 +685,7 @@ filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode)
/* Convert nulls to newlines. buf_len is the string's real length. */ /* Convert nulls to newlines. buf_len is the string's real length. */
unsunder(buf, buf_len); unsunder(buf, buf_len);
buf[buf_len] = '\0';
assert(openfile->fileage != NULL && strlen(buf) == buf_len); assert(openfile->fileage != NULL && strlen(buf) == buf_len);
...@@ -778,8 +779,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw ...@@ -778,8 +779,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
fileptr = read_line(buf, len, fileptr); fileptr = read_line(buf, len, fileptr);
num_lines++; num_lines++;
/* Reset buffer and length in preparation for the next line. */ /* Reset the length in preparation for the next line. */
buf[0] = '\0';
len = 0; len = 0;
#ifndef NANO_TINY #ifndef NANO_TINY
/* If it's a Mac file ('\r' without '\n' on the first line if we /* If it's a Mac file ('\r' without '\n' on the first line if we
...@@ -800,7 +800,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw ...@@ -800,7 +800,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
/* Store the character after the \r as the first character /* Store the character after the \r as the first character
* of the next line. */ * of the next line. */
buf[0] = input; buf[0] = input;
buf[1] = '\0';
len = 1; len = 1;
#endif #endif
} else { } else {
...@@ -816,7 +815,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw ...@@ -816,7 +815,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
} }
buf[len - 1] = input; buf[len - 1] = input;
buf[len] = '\0';
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment