gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] [SCM] Gnash branch, master, updated. bc5014d77c4168c79663


From: Benjamin Wolsey
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. bc5014d77c4168c79663263980a2377ab226c533
Date: Wed, 15 Dec 2010 12:12:19 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  bc5014d77c4168c79663263980a2377ab226c533 (commit)
       via  1b1d3e4cee4bc1d0623057b5b7dad39310c51aaa (commit)
      from  7b9f12c490e496fe66fabd48c4f1dd555c954301 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=bc5014d77c4168c79663263980a2377ab226c533


commit bc5014d77c4168c79663263980a2377ab226c533
Author: Benjamin Wolsey <address@hidden>
Date:   Wed Dec 15 13:00:29 2010 +0100

    Adjust selection to text length.

diff --git a/libcore/TextField.cpp b/libcore/TextField.cpp
index 17c8546..29fa862 100644
--- a/libcore/TextField.cpp
+++ b/libcore/TextField.cpp
@@ -486,21 +486,27 @@ TextField::setRestrict(const std::string& restrict)
 void
 TextField::replaceSelection(const std::string& replace)
 {
-
     const int version = getSWFVersion(*getObject(this));
     const std::wstring& wstr = utf8::decodeCanonicalString(replace, version);
     
+    assert(_selection.second >= _selection.first);
+    assert(_selection.second <= _text.size());
+    assert(_selection.first <= _text.size());
+
+    // If the text has changed but the selection hasn't, make sure we
+    // don't access it out of bounds.
     const size_t start = _selection.first;
+    const size_t end = _selection.second;
+
     const size_t replaceLength = wstr.size();
 
-    _text.replace(start, _selection.second - start, wstr);
+    _text.replace(start, end - start, wstr);
     _selection = std::make_pair(start + replaceLength, start + replaceLength);
 }
 
 void
 TextField::setSelection(int start, int end)
 {
-
     if (_text.empty()) {
         _selection = std::make_pair(0, 0);
         return;
@@ -804,12 +810,15 @@ void
 TextField::updateText(const std::wstring& wstr)
 {
     _textDefined = true;
-
     if (_text == wstr) return;
 
     set_invalidated();
 
     _text = wstr;
+
+    _selection.first = std::min(_selection.first, _text.size());
+    _selection.second = std::min(_selection.second, _text.size());
+
     format_text();
 }
 
diff --git a/libcore/TextField.h b/libcore/TextField.h
index e0f72bf..f625ad8 100644
--- a/libcore/TextField.h
+++ b/libcore/TextField.h
@@ -19,16 +19,16 @@
 #ifndef GNASH_TEXTFIELD_H
 #define GNASH_TEXTFIELD_H
 
-#include "InteractiveObject.h" // for inheritance
-#include "LineStyle.h" // for LineStyle
-#include "snappingrange.h"
-#include "SWFRect.h" // for inlines
-
 #include <boost/intrusive_ptr.hpp>
 #include <map>
 #include <string>
 #include <vector>
 
+#include "InteractiveObject.h" // for inheritance
+#include "LineStyle.h" // for LineStyle
+#include "snappingrange.h"
+#include "SWFRect.h" // for inlines
+
 // Forward declarations
 namespace gnash {
     namespace SWF {
@@ -164,6 +164,9 @@ public:
     }
 
        /// Get a std::pair of size_t with start/end of selection
+    //
+    /// Both start and end should invariably be within the
+    /// range of the text.
     const std::pair<size_t, size_t>& getSelection() const {
         return _selection;
     }

http://git.savannah.gnu.org/cgit//commit/?id=1b1d3e4cee4bc1d0623057b5b7dad39310c51aaa


commit 1b1d3e4cee4bc1d0623057b5b7dad39310c51aaa
Author: Benjamin Wolsey <address@hidden>
Date:   Wed Dec 15 13:00:18 2010 +0100

    Add tests for crasher in replaceSel().

diff --git a/testsuite/actionscript.all/Selection.as 
b/testsuite/actionscript.all/Selection.as
index 10283d0..5554e60 100644
--- a/testsuite/actionscript.all/Selection.as
+++ b/testsuite/actionscript.all/Selection.as
@@ -295,6 +295,20 @@ check_equals(ret, false);
  ret = Selection.getCaretIndex();
  check_equals(ret, 1);
 
+ Selection.setFocus(text1);
+ text1.text = "Some relatively long text";
+ Selection.setSelection(10, 15);
+ check_equals(Selection.getBeginIndex(), 10);
+ text1.text = "Some slightly shorter te";
+ check_equals(Selection.getBeginIndex(), 10);
+ text1.text = "too short";
+ check_equals(Selection.getBeginIndex(), 9);
+ text1.text = "";
+ check_equals(Selection.getBeginIndex(), 0);
+ // This triggers a bug in Gnash 0.8.8 due to 
+ // the selection being outside the text bounds.
+ text1.replaceSel("hello");
+
 #endif // OUTPUT_VERSION >= 6
 
 totals();

-----------------------------------------------------------------------

Summary of changes:
 libcore/TextField.cpp                   |   17 +++++++++++++----
 libcore/TextField.h                     |   13 ++++++++-----
 testsuite/actionscript.all/Selection.as |   14 ++++++++++++++
 3 files changed, 35 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

[Prev in Thread] Current Thread [Next in Thread]