Replace sprintf() by safer snprintf() to format hexadecimal
debug, silencing -Wdeprecated-declarations produced by Apple
clang 17.0.0.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 libdecnumber/dpd/decimal128.c | 4 ++--
 libdecnumber/dpd/decimal32.c  | 4 ++--
 libdecnumber/dpd/decimal64.c  | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libdecnumber/dpd/decimal128.c b/libdecnumber/dpd/decimal128.c
index 1064fb25e01d..e4ff39c90bd2 100644
--- a/libdecnumber/dpd/decimal128.c
+++ b/libdecnumber/dpd/decimal128.c
@@ -543,7 +543,7 @@ void decimal128Show(const decimal128 *d128) {
 
   if (DECLITEND) {
     for (i=0; i<DECIMAL128_Bytes; i++, j+=2) {
-      sprintf(&buf[j], "%02x", d128->bytes[15-i]);
+      snprintf(&buf[j], sizeof(buf) - j, "%02x", d128->bytes[15-i]);
       }
     printf(" D128> %s [S:%d Cb:%02x Ec:%02x] LittleEndian\n", buf,
           d128->bytes[15]>>7, (d128->bytes[15]>>2)&0x1f,
@@ -552,7 +552,7 @@ void decimal128Show(const decimal128 *d128) {
     }
    else {
     for (i=0; i<DECIMAL128_Bytes; i++, j+=2) {
-      sprintf(&buf[j], "%02x", d128->bytes[i]);
+      snprintf(&buf[j], sizeof(buf) - j, "%02x", d128->bytes[i]);
       }
     printf(" D128> %s [S:%d Cb:%02x Ec:%02x] BigEndian\n", buf,
           decimal128Sign(d128), decimal128Comb(d128),
diff --git a/libdecnumber/dpd/decimal32.c b/libdecnumber/dpd/decimal32.c
index 34ff0fe95991..bc16361c82de 100644
--- a/libdecnumber/dpd/decimal32.c
+++ b/libdecnumber/dpd/decimal32.c
@@ -470,7 +470,7 @@ void decimal32Show(const decimal32 *d32) {
 
   if (DECLITEND) {
     for (i=0; i<DECIMAL32_Bytes; i++, j+=2) {
-      sprintf(&buf[j], "%02x", d32->bytes[3-i]);
+      snprintf(&buf[j], sizeof(buf) - j, "%02x", d32->bytes[3-i]);
       }
     printf(" D32> %s [S:%d Cb:%02x Ec:%02x] LittleEndian\n", buf,
           d32->bytes[3]>>7, (d32->bytes[3]>>2)&0x1f,
@@ -478,7 +478,7 @@ void decimal32Show(const decimal32 *d32) {
     }
    else {
     for (i=0; i<DECIMAL32_Bytes; i++, j+=2) {
-      sprintf(&buf[j], "%02x", d32->bytes[i]);
+      snprintf(&buf[j], sizeof(buf) - j, "%02x", d32->bytes[i]);
       }
     printf(" D32> %s [S:%d Cb:%02x Ec:%02x] BigEndian\n", buf,
           decimal32Sign(d32), decimal32Comb(d32), decimal32ExpCon(d32));
diff --git a/libdecnumber/dpd/decimal64.c b/libdecnumber/dpd/decimal64.c
index 11e0674fa7c8..18438c1de1c3 100644
--- a/libdecnumber/dpd/decimal64.c
+++ b/libdecnumber/dpd/decimal64.c
@@ -530,7 +530,7 @@ void decimal64Show(const decimal64 *d64) {
 
   if (DECLITEND) {
     for (i=0; i<DECIMAL64_Bytes; i++, j+=2) {
-      sprintf(&buf[j], "%02x", d64->bytes[7-i]);
+      snprintf(&buf[j], sizeof(buf) - j, "%02x", d64->bytes[7-i]);
       }
     printf(" D64> %s [S:%d Cb:%02x Ec:%02x] LittleEndian\n", buf,
           d64->bytes[7]>>7, (d64->bytes[7]>>2)&0x1f,
@@ -538,7 +538,7 @@ void decimal64Show(const decimal64 *d64) {
     }
    else { /* big-endian */
     for (i=0; i<DECIMAL64_Bytes; i++, j+=2) {
-      sprintf(&buf[j], "%02x", d64->bytes[i]);
+      snprintf(&buf[j], sizeof(buf) - j, "%02x", d64->bytes[i]);
       }
     printf(" D64> %s [S:%d Cb:%02x Ec:%02x] BigEndian\n", buf,
           decimal64Sign(d64), decimal64Comb(d64), decimal64ExpCon(d64));
-- 
2.55.0


Reply via email to