From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: Srikanth Yalavarthi <syalavarthi@marvell.com>,
Anup Prabhu <aprabhu@marvell.com>
Subject: [PATCH v2 1/2] app/mldev: fix build with debug
Date: Mon, 20 Mar 2023 13:18:32 +0100 [thread overview]
Message-ID: <20230320121833.1385859-1-david.marchand@redhat.com> (raw)
In-Reply-To: <20230320102624.1258816-1-david.marchand@redhat.com>
Compiling with -O0 and -g triggers these warnings:
../app/test-mldev/test_inference_common.c: In function
‘ml_request_finish’:
../app/test-mldev/test_inference_common.c:946:51:
error: ‘.q.’ directive output may be truncated writing 3 bytes
into a region of size between 0 and 4095
[-Werror=format-truncation=]
946 | snprintf(str, sizeof(str) - 1, "%s.q.%d",
| ^~~
t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:946:48: note: using the range
[-2147483648, 2147483647] for directive argument
946 | snprintf(str, sizeof(str) - 1, "%s.q.%d",
| ^~~~~~~~~
t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:946:17: note: ‘snprintf’
output between 5 and 4110 bytes into a destination of size 4095
946 | snprintf(str, sizeof(str) - 1, "%s.q.%d",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:51: error: ‘.’ directive
output may be truncated writing 1 byte into a region of size
between 0 and 4095 [-Werror=format-truncation=]
952 | snprintf(str, sizeof(str) - 1, "%s.%d",
| ^
t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:48: note: using the range
[-2147483648, 2147483647] for directive argument
952 | snprintf(str, sizeof(str) - 1, "%s.%d",
| ^~~~~~~
t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:952:17: note: ‘snprintf’
output between 3 and 4108 bytes into a destination of size 4095
952 | snprintf(str, sizeof(str) - 1, "%s.%d",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t->cmn.opt->filelist[req->fid].output, obj_idx);
../app/test-mldev/test_inference_common.c:929:51: error: ‘.q’ directive
output may be truncated writing 2 bytes into a region of size
between 0 and 4095 [-Werror=format-truncation=]
929 | snprintf(str, sizeof(str) - 1, "%s.q",
| ^~
t->cmn.opt->filelist[req->fid].output);
../app/test-mldev/test_inference_common.c:929:17: note: ‘snprintf’
output between 3 and 4098 bytes into a destination of size 4095
929 | snprintf(str, sizeof(str) - 1, "%s.q",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t->cmn.opt->filelist[req->fid].output);
../app/test-mldev/test_inference_common.c:935:51: error: ‘snprintf’
output may be truncated before the last format character
[-Werror=format-truncation=]
935 | snprintf(str, sizeof(str) - 1, "%s",
| ^
t->cmn.opt->filelist[req->fid].output);
../app/test-mldev/test_inference_common.c:935:17: note: ‘snprintf’
output between 1 and 4096 bytes into a destination of size 4095
935 | snprintf(str, sizeof(str) - 1, "%s",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t->cmn.opt->filelist[req->fid].output);
Fix unsigned integer format, and switch to dynamic allocations.
Fixes: da6793390596 ("app/mldev: support inference validation")
Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
---
Changes since v1:
- updated integer format as mentionned in v1 commitlog,
---
app/test-mldev/test_inference_common.c | 29 ++++++++++++++++++--------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c
index e85f32be60..eba37c50e9 100644
--- a/app/test-mldev/test_inference_common.c
+++ b/app/test-mldev/test_inference_common.c
@@ -3,6 +3,7 @@
*/
#include <errno.h>
+#include <stdio.h>
#include <unistd.h>
#include <rte_common.h>
@@ -901,8 +902,8 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
struct test_inference *t = ml_test_priv((struct ml_test *)opaque);
struct ml_request *req = (struct ml_request *)obj;
struct ml_model *model = &t->model[req->fid];
- char str[PATH_MAX];
bool error = false;
+ char *dump_path;
RTE_SET_USED(mp);
@@ -926,14 +927,18 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
dump_output_pass:
if (obj_idx == 0) {
/* write quantized output */
- snprintf(str, PATH_MAX, "%s.q", t->cmn.opt->filelist[req->fid].output);
- ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error);
+ if (asprintf(&dump_path, "%s.q", t->cmn.opt->filelist[req->fid].output) == -1)
+ return;
+ ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model->out_qsize, error);
+ free(dump_path);
if (error)
return;
/* write dequantized output */
- snprintf(str, PATH_MAX, "%s", t->cmn.opt->filelist[req->fid].output);
- ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error);
+ if (asprintf(&dump_path, "%s", t->cmn.opt->filelist[req->fid].output) == -1)
+ return;
+ ML_OPEN_WRITE_GET_ERR(dump_path, model->output, model->out_dsize, error);
+ free(dump_path);
if (error)
return;
}
@@ -943,14 +948,20 @@ ml_request_finish(struct rte_mempool *mp, void *opaque, void *obj, unsigned int
dump_output_fail:
if (t->cmn.opt->debug) {
/* dump quantized output buffer */
- snprintf(str, PATH_MAX, "%s.q.%d", t->cmn.opt->filelist[req->fid].output, obj_idx);
- ML_OPEN_WRITE_GET_ERR(str, req->output, model->out_qsize, error);
+ if (asprintf(&dump_path, "%s.q.%u", t->cmn.opt->filelist[req->fid].output,
+ obj_idx) == -1)
+ return;
+ ML_OPEN_WRITE_GET_ERR(dump_path, req->output, model->out_qsize, error);
+ free(dump_path);
if (error)
return;
/* dump dequantized output buffer */
- snprintf(str, PATH_MAX, "%s.%d", t->cmn.opt->filelist[req->fid].output, obj_idx);
- ML_OPEN_WRITE_GET_ERR(str, model->output, model->out_dsize, error);
+ if (asprintf(&dump_path, "%s.%u", t->cmn.opt->filelist[req->fid].output,
+ obj_idx) == -1)
+ return;
+ ML_OPEN_WRITE_GET_ERR(dump_path, model->output, model->out_dsize, error);
+ free(dump_path);
if (error)
return;
}
--
2.39.2
next prev parent reply other threads:[~2023-03-20 12:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 10:26 [PATCH " David Marchand
2023-03-20 10:26 ` [PATCH 2/2] ci: test compilation " David Marchand
2023-03-20 10:40 ` [PATCH 1/2] app/mldev: fix build " David Marchand
2023-03-20 11:29 ` [EXT] " Srikanth Yalavarthi
2023-03-20 12:18 ` David Marchand [this message]
2023-03-20 12:18 ` [PATCH v2 2/2] ci: test compilation with debug in GHA David Marchand
2023-03-20 13:30 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230320121833.1385859-1-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=aprabhu@marvell.com \
--cc=dev@dpdk.org \
--cc=syalavarthi@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).