[moserial] fix bug 687230 - Segmentation fault on HexTextBuffer.vala
- From: Michael J. Chudobiak <mjc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [moserial] fix bug 687230 - Segmentation fault on HexTextBuffer.vala
- Date: Tue, 18 Dec 2012 15:29:11 +0000 (UTC)
commit 4d613acc2cd4dd44d3056842e22ea09f9b02eeb1
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Tue Dec 18 10:28:32 2012 -0500
fix bug 687230 - Segmentation fault on HexTextBuffer.vala
src/HexTextBuffer.vala | 89 +++++++++++++++++++++++++++++++----------------
1 files changed, 59 insertions(+), 30 deletions(-)
---
diff --git a/src/HexTextBuffer.vala b/src/HexTextBuffer.vala
index f74af68..e9a0392 100644
--- a/src/HexTextBuffer.vala
+++ b/src/HexTextBuffer.vala
@@ -58,100 +58,129 @@ public class moserial.HexTextBuffer : TextBuffer
TextIter nextHexIter;
TextIter nextCharIter;
string incomingHexBuffer = "";
+
+ // Every insert or delete operation invalidates TextIters and they must be recovered.
+
if((hexBytes % 16)==0 ){
+ // Mark start
TextIter startIter;
this.get_iter_at_mark(out nextCharIter, nextCharMark);
TextMark startMark = new TextMark("startMark", true);
this.add_mark(startMark, nextCharIter);
+
+ // Insert offset info (hexBytes)
#if VALA_0_16
- this.insert(ref nextCharIter, "\n%08x".printf(hexBytes), 9);
+ this.insert(ref nextCharIter, "\n%08x".printf(hexBytes), 9);
#else
this.insert(nextCharIter, "\n%08x".printf(hexBytes), 9);
#endif
+ this.get_iter_at_offset(out nextCharIter, this.cursor_position);
+
+ // Format offset info
this.get_iter_at_mark(out startIter, startMark);
this.apply_tag_by_name("hex_address", startIter, nextCharIter);
this.delete_mark(startMark);
+
+ // Blank space
#if VALA_0_16
- this.insert(ref nextCharIter, " ", 1);
+ this.insert(ref nextCharIter, " ", 1);
#else
this.insert(nextCharIter, " ", 1);
#endif
+ this.get_iter_at_offset(out nextCharIter, this.cursor_position);
+
+ // Save current position in nextHexMark
this.delete_mark(nextHexMark);
- nextHexIter=nextCharIter;
+ nextHexIter = nextCharIter;
nextHexMark = new TextMark("nextHex", true);
this.add_mark(nextHexMark, nextHexIter);
+
+ // Put 51 blank spaces
#if VALA_0_16
- this.insert(ref nextCharIter, " ", 51);
+ this.insert(ref nextCharIter, " ", 51);
#else
this.insert(nextCharIter, " ", 51);
#endif
+ this.get_iter_at_offset(out nextCharIter, this.cursor_position);
+ // Save current nextCharMark
this.delete_mark(nextCharMark);
nextCharMark = new TextMark("nextChar", true);
this.add_mark(nextCharMark, nextCharIter);
}
else if((hexBytes % 8)==0) {
+ // Every 8 characters put a separation of 2 spaces
this.get_iter_at_mark(out nextHexIter, nextHexMark);
#if VALA_0_16
- this.insert(ref nextHexIter, " ", 2);
+ this.insert(ref nextHexIter, " ", 2);
#else
- this.insert(nextHexIter, " ", 2);
+ this.insert(nextHexIter, " ", 2);
#endif
+ this.get_iter_at_mark(out nextHexIter, nextHexMark);
+ nextHexIter.forward_chars(2);
+ // Save current nextHexMark
+ this.delete_mark(nextHexMark);
+ nextHexMark = new TextMark("nextHex", true);
+ this.add_mark(nextHexMark, nextHexIter);
+ // Remove space to align chars
TextIter tempIter;
- //remove space to align chars
tempIter = nextHexIter;
tempIter.forward_chars(2);
#if VALA_0_16
- this.delete(ref nextHexIter, ref tempIter);
+ this.delete(ref nextHexIter, ref tempIter);
#else
this.delete(nextHexIter, tempIter);
#endif
- this.delete_mark(nextHexMark);
- nextHexMark = new TextMark("nextHex", true);
- this.add_mark(nextHexMark, nextHexIter);
}
+ // Put hex data at nextHexMark
this.get_iter_at_mark(out nextHexIter, nextHexMark);
- incomingHexBuffer+="%02X ".printf(data);
+ incomingHexBuffer += "%02X ".printf(data);
#if VALA_0_16
- this.insert(ref nextHexIter, incomingHexBuffer, (int)incomingHexBuffer.length);
+ this.insert(ref nextHexIter, incomingHexBuffer, (int)incomingHexBuffer.length);
#else
this.insert(nextHexIter, incomingHexBuffer, (int)incomingHexBuffer.length);
#endif
- //remove space to align chars
+
+ this.get_iter_at_mark(out nextHexIter, nextHexMark);
+ nextHexIter.forward_chars(incomingHexBuffer.length);
+ // Save current nextHexMark
+ this.delete_mark(nextHexMark);
+ nextHexMark = new TextMark("nextHex", true);
+ this.add_mark(nextHexMark, nextHexIter);
+ // Remove space to align chars
TextIter tempIter;
tempIter = nextHexIter;
tempIter.forward_chars(3);
#if VALA_0_16
- this.delete(ref nextHexIter, ref tempIter);
+ this.delete(ref nextHexIter, ref tempIter);
#else
this.delete(nextHexIter, tempIter);
-#endif
- //add odd coloring
- /*if(((hexBytes+1)%2)==0) {
- tempIter.backward_chars(3);
- this.apply_tag_by_name("hex_odd", tempIter, nextHexIter);
- }*/
- incomingHexBuffer="";
+#endif
+ incomingHexBuffer = "";
hexBytes++;
- this.delete_mark(nextHexMark);
- nextHexMark = new TextMark("nextHex", true);
- this.add_mark(nextHexMark, nextHexIter);
+ // Place character at nextCharMark
this.get_iter_at_mark(out nextCharIter, nextCharMark);
unichar c = "%c".printf(data).get_char();
string s = "%c".printf(data);
- if(s.validate() && c.isprint())
+ if (s.validate() && c.isprint()) {
#if VALA_0_16
- this.insert(ref nextCharIter, s, (int)s.length);
+ this.insert(ref nextCharIter, s, (int)s.length);
#else
this.insert(nextCharIter, s, (int)s.length);
#endif
- else
+ this.get_iter_at_mark(out nextCharIter, nextCharMark);
+ nextCharIter.forward_chars(s.length);
+ }
+ else {
#if VALA_0_16
- this.insert(ref nextCharIter, ".", 1);
+ this.insert(ref nextCharIter, ".", 1);
#else
this.insert(nextCharIter, ".", 1);
#endif
-
+ this.get_iter_at_mark(out nextCharIter, nextCharMark);
+ nextCharIter.forward_chars(1);
+ }
+ // Save current nextCharMark
this.delete_mark(nextCharMark);
nextCharMark = new TextMark("nextChar", true);
this.add_mark(nextCharMark, nextCharIter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]