[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdev-ruby] /: Fix segfault when ruby was not installed
From: Leslie Zhai <xiangzhai83 () gmail ! com>
Date: 2016-12-06 8:40:58
Message-ID: E1cEBJ4-00085s-DF () code ! kde ! org
[Download RAW message or body]
Git commit 5c330b1180cecaaaace54f47124496a2804e1ed1 by Leslie Zhai.
Committed on 06/12/2016 at 08:39.
Pushed by lesliezhai into branch 'master'.
Fix segfault when ruby was not installed
Reviewers: brauch, #kdevelop
REVIEW: 129599
M +21 -12 languagesupport.cpp
https://commits.kde.org/kdev-ruby/5c330b1180cecaaaace54f47124496a2804e1ed1
diff --git a/languagesupport.cpp b/languagesupport.cpp
index d618d7d..42aaa7c 100644
--- a/languagesupport.cpp
+++ b/languagesupport.cpp
@@ -22,6 +22,7 @@
#include <languagesupport.h>
#include <QProcess>
+#include <QStandardPaths>
#include <KPluginFactory>
@@ -68,19 +69,27 @@ LanguageSupport::LanguageSupport(QObject *parent, const QVariantList &)
new CodeCompletion(this, rModel, "Ruby");
/* Retrieving Ruby version */
- QProcess ruby;
- ruby.start("/usr/bin/env", QStringList{ "ruby", "--version" });
- ruby.waitForFinished();
- const QString &output = ruby.readAllStandardOutput().split(' ')[1];
- QStringList version = output.split('.');
- if (version.size() > 1) {
- if (version[0] == "1") {
- m_version = (version[1] == "8") ? ruby18 : ruby19;
- } else if (version[1] == "0") {
- m_version = ruby20;
- } else {
- m_version = ruby21;
+ QString path = QStandardPaths::findExecutable("ruby");
+ if (!path.isEmpty()) {
+ QProcess ruby;
+ ruby.start(path, QStringList{ "--version" });
+ ruby.waitForFinished(3000);
+ QList<QByteArray> byteArr = ruby.readAllStandardOutput().split(' ');
+ if (byteArr.size() > 1) {
+ const QString &output = byteArr[1];
+ QStringList version = output.split('.');
+ if (version.size() > 1) {
+ if (version[0] == "1") {
+ m_version = (version[1] == "8") ? ruby18 : ruby19;
+ } else if (version[1] == "0") {
+ m_version = ruby20;
+ } else {
+ m_version = ruby21;
+ }
+ }
}
+ } else {
+ qWarning() << "ruby might not be installed!";
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic