Commit 08f16e2f authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

in free_chararray(), assert that array isn't NULL, for consistency with

the other free_.*() functions; also fix potential memory corruption
problem when copying text


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3500 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent bbabf956
Showing with 17 additions and 4 deletions
+17 -4
...@@ -106,6 +106,9 @@ CVS code - ...@@ -106,6 +106,9 @@ CVS code -
writing one for prepending fails. (DLR) writing one for prepending fails. (DLR)
- Simplify the routine for closing the file just before we - Simplify the routine for closing the file just before we
indicate success on the statusbar. (DLR) indicate success on the statusbar. (DLR)
free_chararray()
- Assert that array isn't NULL, for consistency with the other
free_.*() functions. (DLR)
- global.c: - global.c:
shortcut_init() shortcut_init()
- Change the cursor position display help text to use "display" - Change the cursor position display help text to use "display"
......
...@@ -114,6 +114,9 @@ void do_cut_text( ...@@ -114,6 +114,9 @@ void do_cut_text(
filestruct *cb_save = NULL; filestruct *cb_save = NULL;
/* The current end of the cutbuffer, before we add text to /* The current end of the cutbuffer, before we add text to
* it. */ * it. */
size_t cb_save_len = 0;
/* The length of the string at the current end of the cutbuffer,
* before we add text to it. */
bool old_mark_set = openfile->mark_set; bool old_mark_set = openfile->mark_set;
bool old_no_newlines = ISSET(NO_NEWLINES); bool old_no_newlines = ISSET(NO_NEWLINES);
#endif #endif
...@@ -138,7 +141,7 @@ void do_cut_text( ...@@ -138,7 +141,7 @@ void do_cut_text(
/* If the cutbuffer isn't empty, save where it currently /* If the cutbuffer isn't empty, save where it currently
* ends. This is where the new text will be added. */ * ends. This is where the new text will be added. */
cb_save = cutbottom; cb_save = cutbottom;
cb_save->data += strlen(cb_save->data); cb_save_len = strlen(cb_save->data);
} }
/* Set NO_NEWLINES to TRUE, so that we don't disturb the last /* Set NO_NEWLINES to TRUE, so that we don't disturb the last
...@@ -173,9 +176,14 @@ void do_cut_text( ...@@ -173,9 +176,14 @@ void do_cut_text(
* there is one, back into the filestruct. This effectively * there is one, back into the filestruct. This effectively
* uncuts the text we just cut without marking the file as * uncuts the text we just cut without marking the file as
* modified. */ * modified. */
if (cutbuffer != NULL) if (cutbuffer != NULL) {
copy_from_filestruct((cb_save != NULL) ? cb_save : if (cb_save != NULL) {
cutbuffer, cutbottom); cb_save->data += cb_save_len;
copy_from_filestruct(cb_save, cutbottom);
cb_save->data -= cb_save_len;
} else
copy_from_filestruct(cutbuffer, cutbottom);
}
/* Set NO_NEWLINES back to what it was before, since we're done /* Set NO_NEWLINES back to what it was before, since we're done
* disturbing the text. */ * disturbing the text. */
......
...@@ -1968,6 +1968,8 @@ int diralphasort(const void *va, const void *vb) ...@@ -1968,6 +1968,8 @@ int diralphasort(const void *va, const void *vb)
* elements. */ * elements. */
void free_chararray(char **array, size_t len) void free_chararray(char **array, size_t len)
{ {
assert(array != NULL);
for (; len > 0; len--) for (; len > 0; len--)
free(array[len - 1]); free(array[len - 1]);
free(array); free(array);
......
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