[Mlir-commits] [mlir] a988a1f - Replace use of sprintf with snprint in SparseTensorRuntime.cpp (NFC)

Mehdi Amini llvmlistbot at llvm.org
Wed Jan 25 06:33:08 PST 2023


Author: Mehdi Amini
Date: 2023-01-25T06:32:44-08:00
New Revision: a988a1f81d0fc2a0f6f4bd6d97051e9b61975f40

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

LOG: Replace use of sprintf with snprint in SparseTensorRuntime.cpp (NFC)

This fixes a warning on MacOS:

warning: 'sprintf' is deprecated: This function is provided for compatibility
reasons only.  Due to security concerns inherent in the design of sprintf(3),
it is highly recommended that you use snprintf(3) instead.

Added: 
    

Modified: 
    mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp b/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
index c9c404ec2ddc..3a0e5104f840 100644
--- a/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp
@@ -821,8 +821,9 @@ MLIR_SPARSETENSOR_FOREVERY_V(IMPL_DELITER)
 #undef IMPL_DELITER
 
 char *getTensorFilename(index_type id) {
-  char var[80];
-  sprintf(var, "TENSOR%" PRIu64, id);
+  constexpr size_t BUF_SIZE = 80;
+  char var[BUF_SIZE];
+  snprintf(var, BUF_SIZE, "TENSOR%" PRIu64, id);
   char *env = getenv(var);
   if (!env)
     MLIR_SPARSETENSOR_FATAL("Environment variable %s is not set\n", var);


        


More information about the Mlir-commits mailing list