https://bugs.kde.org/show_bug.cgi?id=362652

            Bug ID: 362652
           Summary: unnecessary getenv call
           Product: Akonadi
           Version: unspecified
          Platform: Other
                OS: Linux
            Status: UNCONFIRMED
          Severity: minor
          Priority: NOR
         Component: server
          Assignee: kdepim-bugs@kde.org
          Reporter: deb...@markus-raab.org

src/server/utils.cpp in function Utils::preferredSocketDirectory calls getenv
even in cases when the userName actually is not needed.

  const QString userName = QString::fromLocal8Bit( qgetenv( "USER" ) );
  if ( socketDir.contains( QLatin1String( "$USER" ) ) && !userName.isEmpty() )
{
    socketDir.replace( QLatin1String( "$USER" ), userName );
  }


Reproducible: Always


Actual Results:  
getenv is called every time, even if no $USER should be resolved.

Expected Results:  
No call to getenv if not needed. It is also questionable if we want to keep
$USER literally if USER was not found in environment.

diff --git a/src/server/utils.cpp b/src/server/utils.cpp
index 46d5063..5268f9d 100644
--- a/src/server/utils.cpp
+++ b/src/server/utils.cpp
@@ -72,9 +72,11 @@ QString Utils::preferredSocketDirectory(const QString
&defaultDirectory)
         socketDir =
serverSettings.value(QStringLiteral("Connection/SocketDirectory"),
defaultDirectory).toString();
     }

-    const QString userName = QString::fromLocal8Bit(qgetenv("USER"));
-    if (socketDir.contains(QLatin1String("$USER")) && !userName.isEmpty()) {
-        socketDir.replace(QLatin1String("$USER"), userName);
+    if (socketDir.contains(QLatin1String("$USER"))) {
+        const QString userName = QString::fromLocal8Bit(qgetenv("USER"));
+        if (!userName.isEmpty()) {
+          socketDir.replace(QLatin1String("$USER"), userName);
+        }
     }

     if (socketDir[0] != QLatin1Char('/')) {

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Kdepim-bugs mailing list
Kdepim-bugs@kde.org
https://mail.kde.org/mailman/listinfo/kdepim-bugs

Reply via email to