From 63983758e02c4002df8331339aeda0bac086d379 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Mon, 21 Oct 2002 02:06:03 +0000 Subject: [PATCH] * edit-widget.h: Add new field macro_depth to control depth of macro recursion. * edit.c (edit_execute_macro): Make static. Increment macro_depth on entry, decrement on exit, don't allow it to be too large. --- edit/ChangeLog | 6 ++++++ edit/edit-widget.h | 1 + edit/edit.c | 12 ++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/edit/ChangeLog b/edit/ChangeLog index 730650961..8b7bed207 100644 --- a/edit/ChangeLog +++ b/edit/ChangeLog @@ -1,5 +1,11 @@ 2002-10-20 Pavel Roskin + * edit-widget.h: Add new field macro_depth to control depth of + macro recursion. + * edit.c (edit_execute_macro): Make static. Increment + macro_depth on entry, decrement on exit, don't allow it to be + too large. + * wordproc.c (line_start): Remove incorrect optimization abusing static varaibles. Internal formatting should be usable now. diff --git a/edit/edit-widget.h b/edit/edit-widget.h index 22ac6b956..965e92ced 100644 --- a/edit/edit-widget.h +++ b/edit/edit-widget.h @@ -116,6 +116,7 @@ struct editor_widget { /* macro stuff */ int macro_i; /* -1 if not recording index to macro[] otherwise */ + int macro_depth; /* depth of the macro recursion */ struct macro macro[MAX_MACRO_LENGTH]; }; diff --git a/edit/edit.c b/edit/edit.c index 164092d2e..43d1077ad 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -1920,7 +1920,7 @@ static void check_and_wrap_line (WEdit * edit) } } -void edit_execute_macro (WEdit * edit, struct macro macro[], int n); +static void edit_execute_macro (WEdit *edit, struct macro macro[], int n); int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch) { @@ -2586,14 +2586,22 @@ int edit_execute_command (WEdit * edit, int command, int char_for_insertion) return r; } -void edit_execute_macro (WEdit * edit, struct macro macro[], int n) +static void +edit_execute_macro (WEdit *edit, struct macro macro[], int n) { int i = 0; + + if (edit->macro_depth++ > 256) { + edit_error_dialog (_(" Error "), _("Macro recursion is too deep")); + edit->macro_depth--; + return; + } edit->force |= REDRAW_PAGE; for (; i < n; i++) { edit_execute_cmd (edit, macro[i].command, macro[i].ch); } edit_update_screen (edit); + edit->macro_depth--; } /* User edit menu, like user menu (F2) but only in editor. */