[utilities/kcalc] /: BUG: 515379 - fixed infinity loop when degree token is found in calculation

Albert Astals Cid <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 20cb18b6ec20b4f6fa7659bb1a4914453b5dfa13 by Albert Astals Cid, on behalf of Jan Miksa.
Committed on 27/07/2026 at 00:04.
Pushed by aacid into branch 'master'.

BUG: 515379 - fixed infinity loop when degree token is found in calculation

Fix a bug causing an infinite loop when degree token is found in calculation, which causes the app to freeze completely. In this case, degree token has type set to KNumberType (maybe a default type for tokens) so kcalc_core tries to insert next token after it and it fails. As a simple solution, Degree token is completely removed from the parser because it is not used at all in the program

BUG: 515379

Closes #515379

M  +0    -7    kcalc_parser.cpp
M  +0    -1    kcalc_parser.h
M  +0    -1    kcalc_token.cpp
M  +0    -1    kcalc_token.h

https://invent.kde.org/utilities/kcalc/-/commit/20cb18b6ec20b4f6fa7659bb1a4914453b5dfa13

diff --git a/kcalc_parser.cpp b/kcalc_parser.cpp
index d79df8c1..27c61a31 100644
--- a/kcalc_parser.cpp
+++ b/kcalc_parser.cpp
@@ -238,10 +238,6 @@ KCalcToken::TokenCode KCalcParser::stringToToken(const QString &buffer, int &ind
         return KCalcToken::TokenCode::Multiplication;
     }
 
-    if (s.startsWith(degreeStr)) {
-        index++;
-        return KCalcToken::TokenCode::Degree;
-    }
     if (s.startsWith(andStr)) {
         index++;
         return KCalcToken::TokenCode::And;
@@ -659,9 +655,6 @@ const QString KCalcParser::tokenToString(KCalcToken::TokenCode tokenCode)
     case KCalcToken::TokenCode::CubicRoot:
         return cubicRootStr;
         break;
-    case KCalcToken::TokenCode::Degree:
-        return degreeStr;
-        break;
     case KCalcToken::TokenCode::Gradian:
         return gradianStr;
         break;
diff --git a/kcalc_parser.h b/kcalc_parser.h
index 8ed9c9a5..fe23416f 100644
--- a/kcalc_parser.h
+++ b/kcalc_parser.h
@@ -138,7 +138,6 @@ private:
     static const inline QString gammaStr = QStringLiteral("Γ");
     static const inline QString invertSignStr = QStringLiteral("–");
 
-    static const inline QString degreeStr = QStringLiteral("°");
     static const inline QString gradianStr = QStringLiteral("gon");
     static const inline QString radianStr = QStringLiteral("rad");
     static const inline QString sinStr = QStringLiteral("sin");
diff --git a/kcalc_token.cpp b/kcalc_token.cpp
index 547b4b77..3c31d976 100644
--- a/kcalc_token.cpp
+++ b/kcalc_token.cpp
@@ -279,7 +279,6 @@ void KCalcToken::setToken(TokenCode tokenCode)
     case Permille:
     case TwosComplement:
     case DoubleFactorial:
-    case Degree:
     case Gradian:
     case Radian:
     default:
diff --git a/kcalc_token.h b/kcalc_token.h
index 4ac6532b..0b70ad29 100644
--- a/kcalc_token.h
+++ b/kcalc_token.h
@@ -35,7 +35,6 @@ public:
         Cube,
         SquareRoot,
         CubicRoot,
-        Degree,
         Gradian,
         Radian,
         Sin,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.