Replace sprintf() by safer snprintf() to format ISA error
message, silencing -Wdeprecated-declarations produced by
Apple clang 17.0.0.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 target/xtensa/xtensa-isa.c | 50 +++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/target/xtensa/xtensa-isa.c b/target/xtensa/xtensa-isa.c
index c564af340fa9..f589a7cffe01 100644
--- a/target/xtensa/xtensa-isa.c
+++ b/target/xtensa/xtensa-isa.c
@@ -519,7 +519,8 @@ xtensa_format xtensa_format_lookup(xtensa_isa isa, const 
char *fmtname)
     }
 
     xtisa_errno = xtensa_isa_bad_format;
-    sprintf(xtisa_error_msg, "format \"%s\" not recognized", fmtname);
+    snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+             "format \"%s\" not recognized", fmtname);
     return XTENSA_UNDEFINED;
 }
 
@@ -646,7 +647,8 @@ xtensa_opcode xtensa_opcode_lookup(xtensa_isa isa, const 
char *opname)
 
     if (!result) {
         xtisa_errno = xtensa_isa_bad_opcode;
-        sprintf(xtisa_error_msg, "opcode \"%s\" not recognized", opname);
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+                 "opcode \"%s\" not recognized", opname);
         return XTENSA_UNDEFINED;
     }
 
@@ -692,7 +694,7 @@ int xtensa_opcode_encode(xtensa_isa isa, xtensa_format fmt, 
int slot,
     encode_fn = intisa->opcodes[opc].encode_fns[slot_id];
     if (!encode_fn) {
         xtisa_errno = xtensa_isa_wrong_slot;
-        sprintf(xtisa_error_msg,
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
                 "opcode \"%s\" is not allowed in slot %d of format \"%s\"",
                 intisa->opcodes[opc].name, slot, intisa->formats[fmt].name);
         return -1;
@@ -809,7 +811,8 @@ xtensa_funcUnit_use *xtensa_opcode_funcUnit_use(xtensa_isa 
isa,
     CHECK_OPCODE(intisa, opc, NULL);
     if (u < 0 || u >= intisa->opcodes[opc].num_funcUnit_uses) {
         xtisa_errno = xtensa_isa_bad_funcUnit;
-        sprintf(xtisa_error_msg, "invalid functional unit use number (%d); "
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+                 "invalid functional unit use number (%d); "
                 "opcode \"%s\" has %d", u, intisa->opcodes[opc].name,
                 intisa->opcodes[opc].num_funcUnit_uses);
         return NULL;
@@ -825,7 +828,8 @@ xtensa_funcUnit_use *xtensa_opcode_funcUnit_use(xtensa_isa 
isa,
     do { \
         if ((OPND) < 0 || (OPND) >= (ICLASS)->num_operands) { \
             xtisa_errno = xtensa_isa_bad_operand; \
-            sprintf(xtisa_error_msg, "invalid operand number (%d); " \
+            snprintf(xtisa_error_msg, sizeof(xtisa_error_msg), \
+                     "invalid operand number (%d); " \
                     "opcode \"%s\" has %d operands", (OPND), \
                     (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_operands); \
             return ERRVAL; \
@@ -938,7 +942,7 @@ int xtensa_operand_get_field(xtensa_isa isa, xtensa_opcode 
opc, int opnd,
     get_fn = intisa->slots[slot_id].get_field_fns[intop->field_id];
     if (!get_fn) {
         xtisa_errno = xtensa_isa_wrong_slot;
-        sprintf(xtisa_error_msg,
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
                 "operand \"%s\" does not exist in slot %d of format \"%s\"",
                 intop->name, slot, intisa->formats[fmt].name);
         return -1;
@@ -974,7 +978,7 @@ int xtensa_operand_set_field(xtensa_isa isa, xtensa_opcode 
opc, int opnd,
     set_fn = intisa->slots[slot_id].set_field_fns[intop->field_id];
     if (!set_fn) {
         xtisa_errno = xtensa_isa_wrong_slot;
-        sprintf(xtisa_error_msg,
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
                 "operand \"%s\" does not exist in slot %d of format \"%s\"",
                 intop->name, slot, intisa->formats[fmt].name);
         return -1;
@@ -1050,7 +1054,8 @@ int xtensa_operand_encode(xtensa_isa isa, xtensa_opcode 
opc, int opnd,
         (test_val = *valp, (*intop->decode)(&test_val)) ||
         test_val != orig_val) {
         xtisa_errno = xtensa_isa_bad_value;
-        sprintf(xtisa_error_msg, "cannot encode operand value 0x%08x", *valp);
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+                 "cannot encode operand value 0x%08x", *valp);
         return -1;
     }
 
@@ -1076,7 +1081,8 @@ int xtensa_operand_decode(xtensa_isa isa, xtensa_opcode 
opc, int opnd,
 
     if ((*intop->decode)(valp)) {
         xtisa_errno = xtensa_isa_bad_value;
-        sprintf(xtisa_error_msg, "cannot decode operand value 0x%08x", *valp);
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+                 "cannot decode operand value 0x%08x", *valp);
         return -1;
     }
     return 0;
@@ -1186,7 +1192,7 @@ int xtensa_operand_do_reloc(xtensa_isa isa, xtensa_opcode 
opc, int opnd,
 
     if ((*intop->do_reloc)(valp, pc)) {
         xtisa_errno = xtensa_isa_bad_value;
-        sprintf(xtisa_error_msg,
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
                 "do_reloc failed for value 0x%08x at PC 0x%08x", *valp, pc);
         return -1;
     }
@@ -1218,7 +1224,7 @@ int xtensa_operand_undo_reloc(xtensa_isa isa, 
xtensa_opcode opc, int opnd,
 
     if ((*intop->undo_reloc)(valp, pc)) {
         xtisa_errno = xtensa_isa_bad_value;
-        sprintf(xtisa_error_msg,
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
                 "undo_reloc failed for value 0x%08x at PC 0x%08x", *valp, pc);
         return -1;
     }
@@ -1234,7 +1240,8 @@ int xtensa_operand_undo_reloc(xtensa_isa isa, 
xtensa_opcode opc, int opnd,
     do { \
         if ((STOP) < 0 || (STOP) >= (ICLASS)->num_stateOperands) { \
             xtisa_errno = xtensa_isa_bad_operand; \
-            sprintf(xtisa_error_msg, "invalid state operand number (%d); " \
+            snprintf(xtisa_error_msg, sizeof(xtisa_error_msg), \
+                     "invalid state operand number (%d); " \
                     "opcode \"%s\" has %d state operands", (STOP), \
                     (INTISA)->opcodes[(OPC)].name, \
                     (ICLASS)->num_stateOperands); \
@@ -1279,7 +1286,7 @@ char xtensa_stateOperand_inout(xtensa_isa isa, 
xtensa_opcode opc, int stOp)
     do { \
         if ((IFOP) < 0 || (IFOP) >= (ICLASS)->num_interfaceOperands) { \
             xtisa_errno = xtensa_isa_bad_operand; \
-            sprintf(xtisa_error_msg, \
+            snprintf(xtisa_error_msg, sizeof(xtisa_error_msg), \
                     "invalid interface operand number (%d); " \
                     "opcode \"%s\" has %d interface operands", (IFOP), \
                     (INTISA)->opcodes[(OPC)].name, \
@@ -1337,7 +1344,8 @@ xtensa_regfile xtensa_regfile_lookup(xtensa_isa isa, 
const char *name)
     }
 
     xtisa_errno = xtensa_isa_bad_regfile;
-    sprintf(xtisa_error_msg, "regfile \"%s\" not recognized", name);
+    snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+             "regfile \"%s\" not recognized", name);
     return XTENSA_UNDEFINED;
 }
 
@@ -1369,7 +1377,8 @@ xtensa_regfile xtensa_regfile_lookup_shortname(xtensa_isa 
isa,
     }
 
     xtisa_errno = xtensa_isa_bad_regfile;
-    sprintf(xtisa_error_msg, "regfile shortname \"%s\" not recognized",
+    snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+             "regfile shortname \"%s\" not recognized",
             shortname);
     return XTENSA_UNDEFINED;
 }
@@ -1453,7 +1462,8 @@ xtensa_state xtensa_state_lookup(xtensa_isa isa, const 
char *name)
 
     if (!result) {
         xtisa_errno = xtensa_isa_bad_state;
-        sprintf(xtisa_error_msg, "state \"%s\" not recognized", name);
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+                 "state \"%s\" not recognized", name);
         return XTENSA_UNDEFINED;
     }
 
@@ -1555,7 +1565,8 @@ xtensa_sysreg xtensa_sysreg_lookup_name(xtensa_isa isa, 
const char *name)
 
     if (!result) {
         xtisa_errno = xtensa_isa_bad_sysreg;
-        sprintf(xtisa_error_msg, "sysreg \"%s\" not recognized", name);
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+                 "sysreg \"%s\" not recognized", name);
         return XTENSA_UNDEFINED;
     }
 
@@ -1626,7 +1637,8 @@ xtensa_interface xtensa_interface_lookup(xtensa_isa isa, 
const char *ifname)
 
     if (!result) {
         xtisa_errno = xtensa_isa_bad_interface;
-        sprintf(xtisa_error_msg, "interface \"%s\" not recognized", ifname);
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
+                 "interface \"%s\" not recognized", ifname);
         return XTENSA_UNDEFINED;
     }
 
@@ -1716,7 +1728,7 @@ xtensa_funcUnit xtensa_funcUnit_lookup(xtensa_isa isa, 
const char *fname)
 
     if (!result) {
         xtisa_errno = xtensa_isa_bad_funcUnit;
-        sprintf(xtisa_error_msg,
+        snprintf(xtisa_error_msg, sizeof(xtisa_error_msg),
                 "functional unit \"%s\" not recognized", fname);
         return XTENSA_UNDEFINED;
     }
-- 
2.55.0


Reply via email to