[gnome-calculator] Fixes a crash in gnome-calculator when calculating nested pows.
- From: Arth Patel <arthpatel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Fixes a crash in gnome-calculator when calculating nested pows.
- Date: Thu, 25 Apr 2013 06:50:57 +0000 (UTC)
commit 4a0e2c068dfaa7c0752b7fbf171b620c34a433bd
Author: Santiago Saavedra <santiagosaavedra gmail com>
Date: Mon Apr 15 22:56:31 2013 +0200
Fixes a crash in gnome-calculator when calculating nested pows.
Example test case:
Input: 2³ ²
Outcome: segfault
Expected output: 512 (consistent with 2^3^2)
Checking against right.token in the calculatin allows us to know whether
we are in a nested calculation and should avoid atoi (as it should have
already been done) or not.
src/equation-parser.vala | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/src/equation-parser.vala b/src/equation-parser.vala
index d3cf977..acbdd9d 100644
--- a/src/equation-parser.vala
+++ b/src/equation-parser.vala
@@ -509,6 +509,9 @@ public class XPowYNode : LRNode
}
}
+/**
+ * This class is a XPowY in which the right token is an nsup number.
+ */
public class XPowYIntegerNode : ParseNode
{
public XPowYIntegerNode (Parser parser, LexerToken? token, uint precedence, Associativity associativity)
@@ -519,7 +522,20 @@ public class XPowYIntegerNode : ParseNode
public override Number? solve ()
{
var val = left.solve ();
- var pow = super_atoi (right.token.text);
+
+ // Are we inside a nested pow?
+ if (val == null)
+ {
+ val = new Number.integer (super_atoi (left.token.text));
+ }
+
+ int64 pow;
+
+ if (right.token != null)
+ pow = super_atoi (right.token.text);
+ else
+ pow = right.solve ().to_integer ();
+
if (val == null)
return null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]