Merge lp:~embik/pantheon-calculator/index into lp:~elementary-apps/pantheon-calculator/trunk

Proposed by Marvin Beckers
Status: Merged
Approved by: Corentin Noël
Approved revision: 128
Merged at revision: 135
Proposed branch: lp:~embik/pantheon-calculator/index
Merge into: lp:~elementary-apps/pantheon-calculator/trunk
Diff against target: 73 lines (+9/-9)
1 file modified
src/Core/Scanner.vala (+9/-9)
To merge this branch: bzr merge lp:~embik/pantheon-calculator/index
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+255239@code.launchpad.net

Commit message

fixed out of range problem

Description of the change

Updated version of a branch proposed for merging some time ago. It fixes a - at least to me - nasty bug when determining the index values for tokens.

To post a comment you must log in.
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

The range-check should be done before applying it on the array.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Core/Scanner.vala'
2--- src/Core/Scanner.vala 2015-02-09 19:41:46 +0000
3+++ src/Core/Scanner.vala 2015-04-05 08:19:33 +0000
4@@ -24,7 +24,7 @@
5
6 public class Scanner : Object {
7 public unowned string str;
8- public int pos;
9+ public ssize_t pos;
10 public unichar[] uc;
11
12 private unichar decimal_symbol;
13@@ -43,7 +43,7 @@
14 bool next_number_negative = false;
15 Evaluation e = new Evaluation ();
16
17- for (int i = 0; input.get_next_char(ref index, out c); i++) {
18+ for (int i = 0; input.get_next_char (ref index, out c); i++) {
19 if (c != ' ') {
20 scanner.uc.resize (scanner.uc.length + 1);
21 scanner.uc[scanner.uc.length - 1] = c;
22@@ -68,7 +68,7 @@
23
24 Token t = new Token (substr, type);
25
26- //identifying multicharacter tokens via Evaluation class.
27+ //identifying multicharacter tokens via Evaluation class.
28 if (t.token_type == TokenType.ALPHA) {
29 if (e.is_operator (t))
30 t.token_type = TokenType.OPERATOR;
31@@ -98,7 +98,7 @@
32 * checking if last token was a number or parenthesis right
33 * and token now is a function, constant or parenthesis (left)
34 */
35- if (last_token != null &&
36+ if (last_token != null &&
37 (last_token.token_type == TokenType.NUMBER || last_token.token_type == TokenType.P_RIGHT) &&
38 (t.token_type == TokenType.FUNCTION || t.token_type == TokenType.CONSTANT
39 || t.token_type == TokenType.P_LEFT || t.token_type == TokenType.NUMBER))
40@@ -115,20 +115,20 @@
41 start = pos;
42 if (uc[pos] == this.decimal_symbol) {
43 pos++;
44- while (uc[pos].isdigit ())
45+ while (uc[pos].isdigit () && pos < uc.length)
46 pos++;
47 len = pos - start;
48 return TokenType.NULL_NUMBER;
49 } else if (uc[pos].isdigit ()) {
50- while (uc[pos].isdigit ())
51+ while (uc[pos].isdigit () && pos < uc.length)
52 pos++;
53 if (uc[pos] == this.decimal_symbol)
54 pos++;
55- while (uc[pos].isdigit ())
56+ while (uc[pos].isdigit () && pos < uc.length)
57 pos++;
58 len = pos - start;
59 return TokenType.NUMBER;
60- } else if (uc[pos] == '+' || uc[pos] == '-' || uc[pos] == '*' ||
61+ } else if (uc[pos] == '+' || uc[pos] == '-' || uc[pos] == '*' ||
62 uc[pos] == '/' || uc[pos] == '^' || uc[pos] == '%' ||
63 uc[pos] == '÷' || uc[pos] == '×' || uc[pos] == '−') {
64 pos++;
65@@ -143,7 +143,7 @@
66 len = 1;
67 return TokenType.CONSTANT;
68 } else if (uc[pos].isalpha ()) {
69- while (uc[pos].isalpha ())
70+ while (uc[pos].isalpha () && pos < uc.length)
71 pos++;
72 len = pos - start;
73 return TokenType.ALPHA;

Subscribers

People subscribed via source and target branches

to all changes: