[Lldb-commits] [lldb] 5871cba - [lldb] Avoid snprintf in PlatformRemoteDarwinDevice

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 26 06:14:57 PST 2019


Author: Pavel Labath
Date: 2019-11-26T15:16:26+01:00
New Revision: 5871cba86172c5bd947952a9441acf80332455ea

URL: https://github.com/llvm/llvm-project/commit/5871cba86172c5bd947952a9441acf80332455ea
DIFF: https://github.com/llvm/llvm-project/commit/5871cba86172c5bd947952a9441acf80332455ea.diff

LOG: [lldb] Avoid snprintf in PlatformRemoteDarwinDevice

This quashes a -Wformat-truncation warning.

Added: 
    

Modified: 
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
index e9bb29293189..0aa129c808d4 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
@@ -449,12 +449,10 @@ Status PlatformRemoteDarwinDevice::GetSymbolFile(const FileSpec &platform_file,
   Status error;
   char platform_file_path[PATH_MAX];
   if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path))) {
-    char resolved_path[PATH_MAX];
-
     const char *os_version_dir = GetDeviceSupportDirectoryForOSVersion();
     if (os_version_dir) {
-      ::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", os_version_dir,
-                 platform_file_path);
+      std::string resolved_path =
+          (llvm::Twine(os_version_dir) + "/" + platform_file_path).str();
 
       local_file.SetFile(resolved_path, FileSpec::Style::native);
       FileSystem::Instance().Resolve(local_file);
@@ -466,31 +464,28 @@ Status PlatformRemoteDarwinDevice::GetSymbolFile(const FileSpec &platform_file,
         return error;
       }
 
-      ::snprintf(resolved_path, sizeof(resolved_path), "%s/Symbols.Internal/%s",
-                 os_version_dir, platform_file_path);
+      resolved_path = (llvm::Twine(os_version_dir) + "/Symbols.Internal/" +
+                       platform_file_path)
+                          .str();
 
       local_file.SetFile(resolved_path, FileSpec::Style::native);
       FileSystem::Instance().Resolve(local_file);
       if (FileSystem::Instance().Exists(local_file)) {
-        if (log) {
-          LLDB_LOGF(
-              log,
-              "Found a copy of %s in the DeviceSupport dir %s/Symbols.Internal",
-              platform_file_path, os_version_dir);
-        }
+        LLDB_LOGF(
+            log,
+            "Found a copy of %s in the DeviceSupport dir %s/Symbols.Internal",
+            platform_file_path, os_version_dir);
         return error;
       }
-      ::snprintf(resolved_path, sizeof(resolved_path), "%s/Symbols/%s",
-                 os_version_dir, platform_file_path);
+      resolved_path =
+          (llvm::Twine(os_version_dir) + "/Symbols/" + platform_file_path)
+              .str();
 
       local_file.SetFile(resolved_path, FileSpec::Style::native);
       FileSystem::Instance().Resolve(local_file);
       if (FileSystem::Instance().Exists(local_file)) {
-        if (log) {
-          LLDB_LOGF(log,
-                    "Found a copy of %s in the DeviceSupport dir %s/Symbols",
-                    platform_file_path, os_version_dir);
-        }
+        LLDB_LOGF(log, "Found a copy of %s in the DeviceSupport dir %s/Symbols",
+                  platform_file_path, os_version_dir);
         return error;
       }
     }


        


More information about the lldb-commits mailing list