compilerplugins/clang/pluginhandler.cxx |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

New commits:
commit 7533d93cdcf3b6076275167b53450a1cbde045a7
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Sat Nov 5 15:55:28 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Sun Nov 6 01:14:05 2022 +0100

    -Werror,-Wdeprecated-declarations (sprintf, macOS 13 SDK): compilerplugins
    
    Change-Id: I9a4d20cd42d6c836aa74837688a272f849d9d373
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142322
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/compilerplugins/clang/pluginhandler.cxx 
b/compilerplugins/clang/pluginhandler.cxx
index ffa4e3668def..f5d27dd76b2b 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -21,8 +21,8 @@
 #include <clang/Frontend/CompilerInstance.h>
 #include <clang/Frontend/FrontendPluginRegistry.h>
 #include <clang/Lex/PPCallbacks.h>
+#include <llvm/ADT/StringExtras.h>
 #include <llvm/Support/TimeProfiler.h>
-#include <stdio.h>
 
 #if defined _WIN32
 #include <process.h>
@@ -384,8 +384,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& 
context )
             report( DiagnosticsEngine::Warning, pathWarning ) << name;
         if( bSkip )
             continue;
-        char* filename = new char[ modifyFile.length() + 100 ];
-        sprintf( filename, "%s.new.%d", modifyFile.c_str(), getpid());
+        auto const filename = modifyFile + ".new." + itostr(getpid());
         std::string error;
         bool bOk = false;
         std::error_code ec;
@@ -395,16 +394,15 @@ void PluginHandler::HandleTranslationUnit( ASTContext& 
context )
         {
             it->second.write( *ostream );
             ostream->close();
-            if( !ostream->has_error() && rename( filename, modifyFile.c_str()) 
== 0 )
+            if( !ostream->has_error() && rename( filename.c_str(), 
modifyFile.c_str()) == 0 )
                 bOk = true;
         }
         else
             error = "error: " + ec.message();
         ostream->clear_error();
-        unlink( filename );
+        unlink( filename.c_str() );
         if( !bOk )
             report( DiagnosticsEngine::Error, "cannot write modified source to 
%0 (%1)" ) << modifyFile << error;
-        delete[] filename;
     }
 #endif
  }

Reply via email to