Replace sprintf by snprintf
authorCarlos Eduardo Seo <carlos.seo@linaro.org>
Thu, 29 Jun 2023 14:08:10 +0000 (11:08 -0300)
committerCarlos Eduardo Seo <carlos.seo@linaro.org>
Thu, 29 Jun 2023 16:48:44 +0000 (16:48 +0000)
The macOS toolchain deprecated sprintf in favor of snprintf. This was blocking
the build on macOS. Replaced all instances of sprintf by snprintf.

flang/unittests/Decimal/quick-sanity-test.cpp
flang/unittests/Decimal/thorough-test.cpp

index ef745df..74434c1 100644 (file)
@@ -53,7 +53,7 @@ void testReadback(float x, int flags) {
       ++expo;
     }
     if (q >= buffer && q < buffer + sizeof buffer) {
-      std::sprintf(q + result.length, "e%d", expo);
+      std::snprintf(q + result.length, sizeof buffer, "e%d", expo);
     }
     const char *p{q};
     auto rflags{ConvertDecimalToFloat(&p, &y, RoundNearest)};
index f8416bf..2261a1c 100644 (file)
@@ -51,7 +51,7 @@ void testReadback(float x, int flags) {
       if (*q == '-' || *q == '+') {
         ++expo;
       }
-      std::sprintf(q + result.length, "e%d", expo);
+      std::snprintf(q + result.length, sizeof buffer, "e%d", expo);
     }
     const char *p{q};
     auto rflags{ConvertDecimalToFloat(&p, &y, RoundNearest)};