[tensor] add warning in get_shape_string snprintf
authorPaul Brossier <piem@piem.org>
Wed, 29 Dec 2021 16:22:00 +0000 (11:22 -0500)
committerPaul Brossier <piem@piem.org>
Wed, 29 Dec 2021 16:52:03 +0000 (11:52 -0500)
Prevent gcc from emitting -Wformat-truncation warning

src/ai/tensor.c

index a15818e..8be5928 100644 (file)
@@ -181,8 +181,10 @@ const char_t *aubio_tensor_get_shape_string(aubio_tensor_t *t) {
         add_coma ? "," : "", add_space ? " " : "");
     strncpy(shape_str_previous, shape_str, len);
   }
-  snprintf(shape_str, strnlen(shape_str, STRN_LENGTH - offset - 1) + offset,
-      "%s)", shape_str_previous);
+  if (snprintf(shape_str,
+      strnlen(shape_str, STRN_LENGTH - offset - 1) + offset,
+      "%s)", shape_str_previous) < 0)
+    AUBIO_WRN("aubio_tensor_get_shape_string snprintf failed");
   return shape_str;
 }