[m-rev.] for review: Fix compilation with GCC 13.

Peter Wang novalazy at gmail.com
Tue Jul 11 18:07:22 AEST 2023


Convince GCC 13 that a sprintf() call will not overflow.
Fixes GitHub issue #123.

runtime/mercury_ml_expand_body.h:
    As above.
---
 runtime/mercury_ml_expand_body.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/runtime/mercury_ml_expand_body.h b/runtime/mercury_ml_expand_body.h
index 8858b6d6c..16d53899e 100644
--- a/runtime/mercury_ml_expand_body.h
+++ b/runtime/mercury_ml_expand_body.h
@@ -1138,8 +1138,7 @@ EXPAND_FUNCTION_NAME(MR_TypeInfo type_info, MR_Word *data_word_ptr,
             default:
                 // Print remaining control characters using octal escapes.
                 if (MR_is_control(data_word)) {
-                    sprintf(buf, "\'\\%03" MR_INTEGER_LENGTH_MODIFIER "o\\\'",
-                        data_word);
+                    sprintf(buf, "\'\\%03o\\\'", (int) (data_word & 0xff));
                 } else if (MR_is_ascii(data_word)) {
                     sprintf(buf, "\'%c\'", (char) data_word);
                 } else if (MR_is_surrogate(data_word)) {
-- 
2.39.0



More information about the reviews mailing list