fixed segfault when trying to edit a non-file
Этот коммит содержится в:
родитель
c0cc06ad60
Коммит
0f67d72266
@ -216,18 +216,21 @@ void edit_set_space_width (int s)
|
||||
|
||||
#endif
|
||||
|
||||
/* fills in the edit struct. returns 0 on fail. Pass edit as NULL for this function to do an malloc for you */
|
||||
/* fills in the edit struct. returns 0 on fail. Pass edit as NULL for this */
|
||||
WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size)
|
||||
{
|
||||
char *f;
|
||||
int to_free = 0;
|
||||
#ifndef MIDNIGHT
|
||||
if (option_long_whitespace)
|
||||
edit_set_space_width (per_char[' '] * 2);
|
||||
else
|
||||
edit_set_space_width (per_char[' ']);
|
||||
#endif
|
||||
if (!edit)
|
||||
if (!edit) {
|
||||
edit = malloc (sizeof (WEdit));
|
||||
to_free = 1;
|
||||
}
|
||||
if (!edit) {
|
||||
edit_error_dialog (_(" Error "), _(" Error allocating memory "));
|
||||
return 0;
|
||||
@ -249,7 +252,8 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
|
||||
f = catstrs (dir, filename, 0);
|
||||
if (edit_load_file (edit, f, text, text_size)) {
|
||||
/* edit_load_file already gives an error message */
|
||||
free (edit);
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
edit->force |= REDRAW_PAGE;
|
||||
@ -265,7 +269,8 @@ WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, co
|
||||
edit->undo_stack = malloc ((edit->stack_size + 10) * sizeof (long));
|
||||
if (!edit->undo_stack) {
|
||||
edit_error_dialog (_(" Error "), _(" Error allocating memory "));
|
||||
free (edit);
|
||||
if (to_free)
|
||||
free (edit);
|
||||
return 0;
|
||||
}
|
||||
edit->total_lines = edit_count_lines (edit, 0, edit->last_byte);
|
||||
@ -323,7 +328,7 @@ int edit_renew (WEdit * edit)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* returns 1 on success */
|
||||
/* returns 1 on success, if returns 0, the edit struct would have been free'd */
|
||||
int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size)
|
||||
{
|
||||
int lines = edit->num_widget_lines;
|
||||
|
@ -810,7 +810,8 @@ int edit_load_file_from_filename (WEdit *edit, char *exp)
|
||||
int file;
|
||||
if ((file = open ((char *) exp, O_RDONLY, MY_O_TEXT)) != -1) {
|
||||
close (file);
|
||||
edit_reload (edit, exp, 0, "", 0);
|
||||
if (!edit_reload (edit, exp, 0, "", 0))
|
||||
return 1;
|
||||
edit_split_filename (edit, exp);
|
||||
edit->modified = 0;
|
||||
return 0;
|
||||
|
@ -317,7 +317,7 @@ CWidget *CDrawEditor (const char *identifier, Window parent, int x, int y,
|
||||
mkdir (catstrs (home_dir, EDIT_DIR, 0), 0700);
|
||||
made_directory = 1;
|
||||
}
|
||||
e = w->editor = CMalloc (sizeof (WEdit));
|
||||
e = w->editor = edit_init (0, height / FONT_PIX_PER_LINE, width / FONT_MEAN_WIDTH, filename, text, starting_directory, text_size);
|
||||
w->funcs = mouse_funcs_new (w->editor, &edit_mouse_funcs);
|
||||
|
||||
if (!w->editor) {
|
||||
@ -326,7 +326,6 @@ CWidget *CDrawEditor (const char *identifier, Window parent, int x, int y,
|
||||
return 0;
|
||||
}
|
||||
w->editor->widget = w;
|
||||
e = w->editor = edit_init (e, height / FONT_PIX_PER_LINE, width / FONT_MEAN_WIDTH, filename, text, starting_directory, text_size);
|
||||
w->funcs->data = (void *) w->editor;
|
||||
if (!e) {
|
||||
CDestroyWidget (w->ident);
|
||||
|
@ -29,6 +29,9 @@ int edit_translate_key (unsigned int x_keycode, long x_key, int x_state, int *cm
|
||||
void gtk_edit_alloc_colors (GtkEdit *edit, GdkColormap *colormap);
|
||||
static void gtk_edit_set_position (GtkEditable *editable, gint position);
|
||||
void edit_mouse_mark (WEdit * edit, XEvent * event, int double_click);
|
||||
void edit_move_to_prev_col (WEdit * edit, long p);
|
||||
int edit_load_file_from_filename (WEdit *edit, char *exp);
|
||||
|
||||
|
||||
guchar gtk_edit_font_width_per_char[256];
|
||||
int gtk_edit_option_text_line_spacing;
|
||||
@ -275,7 +278,10 @@ static void gtk_edit_destroy (GtkObject * object)
|
||||
gtk_timeout_remove (edit->timer);
|
||||
edit->timer = 0;
|
||||
}
|
||||
edit_destroy_callback (edit->editor->widget);
|
||||
if (edit->funcs) {
|
||||
free (edit->funcs);
|
||||
}
|
||||
edit_destroy_callback (edit);
|
||||
|
||||
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||
}
|
||||
@ -961,7 +967,7 @@ static void gtk_edit_set_position (GtkEditable * editable, gint position)
|
||||
/* returns 1 on error */
|
||||
gint gtk_edit_load_file_from_filename (GtkWidget * edit, const gchar * filename)
|
||||
{
|
||||
return edit_load_file_from_filename (GTK_EDIT (edit)->editor, filename);
|
||||
return edit_load_file_from_filename (GTK_EDIT (edit)->editor, (char *) filename);
|
||||
}
|
||||
|
||||
void gtk_edit_set_top_line (GtkWidget * e, int line)
|
||||
@ -1090,14 +1096,14 @@ static GtkWidget *create_toolbar (GtkWidget * window, GtkEdit * edit)
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
|
||||
/* returns 1 on error */
|
||||
int edit (const char *file, int line)
|
||||
{
|
||||
GtkWidget *app;
|
||||
GtkWidget *edit, *statusbar;
|
||||
|
||||
edit = gtk_edit_new (NULL, NULL);
|
||||
app = gnome_app_new ("mcedit", file ? file : "Mcedit");
|
||||
app = gnome_app_new ("mcedit", (char *) (file ? file : "Mcedit"));
|
||||
|
||||
{
|
||||
GnomeUIInfo file_menu[] =
|
||||
@ -1202,7 +1208,10 @@ int edit (const char *file, int line)
|
||||
gtk_widget_realize (edit);
|
||||
if (file)
|
||||
if (*file)
|
||||
gtk_edit_load_file_from_filename (edit, file);
|
||||
if (gtk_edit_load_file_from_filename (edit, file)) {
|
||||
gtk_widget_destroy (app);
|
||||
return 1;
|
||||
}
|
||||
gtk_edit_set_cursor_line (edit, line);
|
||||
gtk_widget_show (app);
|
||||
gtk_widget_grab_focus (edit);
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user