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 = #include +#include = #include = @@ -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 =3D ruby.readAllStandardOutput().split(' ')[1]; - QStringList version =3D output.split('.'); - if (version.size() > 1) { - if (version[0] =3D=3D "1") { - m_version =3D (version[1] =3D=3D "8") ? ruby18 : ruby19; - } else if (version[1] =3D=3D "0") { - m_version =3D ruby20; - } else { - m_version =3D ruby21; + QString path =3D QStandardPaths::findExecutable("ruby"); + if (!path.isEmpty()) { + QProcess ruby; + ruby.start(path, QStringList{ "--version" }); + ruby.waitForFinished(3000); + QList byteArr =3D ruby.readAllStandardOutput().split('= '); + if (byteArr.size() > 1) { + const QString &output =3D byteArr[1]; + QStringList version =3D output.split('.'); + if (version.size() > 1) { + if (version[0] =3D=3D "1") { + m_version =3D (version[1] =3D=3D "8") ? ruby18 : ruby1= 9; + } else if (version[1] =3D=3D "0") { + m_version =3D ruby20; + } else { + m_version =3D ruby21; + } + } } + } else { + qWarning() << "ruby might not be installed!"; } } =20