aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-10-02 20:31:05 +0800
committerChris Lahey <clahey@src.gnome.org>2001-10-02 20:31:05 +0800
commitf6be515182c311c81b108d992597dc66aa401227 (patch)
tree13c32a8cc9ddd05795fc2032964d9777e96947f0
parentce45d995aa3984e0180e0c1ee83fadfeaa0deccf (diff)
downloadgsoc2013-evolution-f6be515182c311c81b108d992597dc66aa401227.tar.gz
gsoc2013-evolution-f6be515182c311c81b108d992597dc66aa401227.tar.zst
gsoc2013-evolution-f6be515182c311c81b108d992597dc66aa401227.zip
Added a max length of 2047 to the standard ETextModel. Fixes Ximian bug
2001-10-02 Christopher James Lahey <clahey@ximian.com> * gal/e-text/e-text-model.c (MAX_LENGTH): Added a max length of 2047 to the standard ETextModel. Fixes Ximian bug #3021. svn path=/trunk/; revision=13298
-rw-r--r--widgets/text/e-text-model.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/widgets/text/e-text-model.c b/widgets/text/e-text-model.c
index 6d96f0769c..af67def74e 100644
--- a/widgets/text/e-text-model.c
+++ b/widgets/text/e-text-model.c
@@ -27,6 +27,8 @@
#define CLASS(obj) (E_TEXT_MODEL_CLASS (GTK_OBJECT (obj)->klass))
+#define MAX_LENGTH (2047)
+
enum {
E_TEXT_MODEL_CHANGED,
E_TEXT_MODEL_REPOSITION,
@@ -235,7 +237,7 @@ e_text_model_real_set_text (ETextModel *model, const gchar *text)
} else if (model->priv->text == NULL || strcmp (model->priv->text, text)) {
g_free (model->priv->text);
- model->priv->text = g_strdup (text);
+ model->priv->text = g_strndup (text, MAX_LENGTH);
model->priv->len = -1;
changed = TRUE;
@@ -254,10 +256,18 @@ e_text_model_real_insert (ETextModel *model, gint position, const gchar *text)
{
EReposInsertShift repos;
gchar *new_text;
- gint ins_len;
+ gint length;
- new_text = g_strdup_printf ("%.*s%s%s", position, model->priv->text, text, model->priv->text + position);
- ins_len = strlen (text);
+ if (model->priv->len < 0)
+ e_text_model_real_get_text_length (model);
+ length = strlen(text);
+
+ if (length + model->priv->len > MAX_LENGTH)
+ length = MAX_LENGTH - model->priv->len;
+ if (length <= 0)
+ return;
+
+ new_text = g_strdup_printf ("%.*s%.*s%s", position, model->priv->text, length, text, model->priv->text + position);
if (model->priv->text)
g_free (model->priv->text);
@@ -265,13 +275,13 @@ e_text_model_real_insert (ETextModel *model, gint position, const gchar *text)
model->priv->text = new_text;
if (model->priv->len >= 0)
- model->priv->len += ins_len;
+ model->priv->len += length;
e_text_model_changed (model);
repos.model = model;
repos.pos = position;
- repos.len = ins_len;
+ repos.len = length;
e_text_model_reposition (model, e_repos_insert_shift, &repos);
}
@@ -280,7 +290,17 @@ static void
e_text_model_real_insert_length (ETextModel *model, gint position, const gchar *text, gint length)
{
EReposInsertShift repos;
- gchar *new_text = g_strdup_printf ("%.*s%.*s%s", position, model->priv->text, length, text, model->priv->text + position);
+ gchar *new_text;
+
+ if (model->priv->len < 0)
+ e_text_model_real_get_text_length (model);
+
+ if (length + model->priv->len > MAX_LENGTH)
+ length = MAX_LENGTH - model->priv->len;
+ if (length <= 0)
+ return;
+
+ new_text = g_strdup_printf ("%.*s%.*s%s", position, model->priv->text, length, text, model->priv->text + position);
if (model->priv->text)
g_free (model->priv->text);