[Akonadi] [Bug 362652] New: unnecessary getenv call

Markus Raab via KDE Bugzilla bugzilla_noreply at kde.org
Wed May 4 09:22:33 BST 2016


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 at kde.org
          Reporter: debian at 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.



More information about the Kdepim-bugs mailing list