runmodes: work around format truncation warnings

util-runmodes.c: In function 'RunModeSetLiveCaptureAutoFp':
util-runmodes.c:167:30: warning: '%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 3 and 4 [-Wformat-truncation=]
  167 |                          "%s#%02d-%s", thread_name, thread+1,
      |                              ^~~~
util-runmodes.c:167:26: note: directive argument in the range [-2147483647, 2147483647]
  167 |                          "%s#%02d-%s", thread_name, thread+1,
      |                          ^~~~~~~~~~~~
util-runmodes.c:167:26: note: assuming directive output of 1 byte
util-runmodes.c:166:17: note: 'snprintf' output 5 or more bytes (assuming 16) into a destination of size 5
  166 |                 snprintf(printable_threadname, strlen(thread_name)+5+strlen(dev),
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167 |                          "%s#%02d-%s", thread_name, thread+1,
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168 |                          dev);
      |                          ~~~~
util-runmodes.c: In function 'RunModeSetLiveCaptureWorkersForDevice':
util-runmodes.c:280:88: warning: '%02d' directive output may be truncated writing between 2 and 10 bytes into a region of size between 3 and 4 [-Wformat-truncation=]
  280 |             snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#%02d-%s",
      |                                                                                        ^~~~
util-runmodes.c:280:84: note: directive argument in the range [1, 2147483647]
  280 |             snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#%02d-%s",
      |                                                                                    ^~~~~~~~~~~~
util-runmodes.c:280:84: note: assuming directive output of 1 byte
util-runmodes.c:280:13: note: 'snprintf' output 5 or more bytes (assuming 15) into a destination of size 5
  280 |             snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#%02d-%s",
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  281 |                      thread_name, thread+1, live_dev);
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util-runmodes.c:275:91: warning: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size between 0 and 1 [-Wformat-truncation=]
  275 |             snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#01-%s",
      |                                                                                           ^~
util-runmodes.c:275:84: note: assuming directive output of 1 byte
  275 |             snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#01-%s",
      |                                                                                    ^~~~~~~~~~
util-runmodes.c:275:13: note: 'snprintf' output 5 or more bytes (assuming 7) into a destination of size 5
  275 |             snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#01-%s",
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  276 |                      thread_name, live_dev);
      |                      ~~~~~~~~~~~~~~~~~~~~~~

Ticket: #7905.
pull/13926/head
Victor Julien 2 months ago committed by Victor Julien
parent 1f46e2ba09
commit 5817afa356

@ -157,15 +157,15 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
int threads_count = ModThreadsCount(aconf);
for (int thread = 0; thread < threads_count; thread++) {
char *printable_threadname = SCMalloc(sizeof(char) * (strlen(thread_name)+5+strlen(dev)));
const size_t printable_threadname_size = strlen(thread_name) + 10 + strlen(dev) + 1;
char *printable_threadname = SCMalloc(printable_threadname_size);
if (unlikely(printable_threadname == NULL)) {
FatalError("failed to alloc printable thread name: %s", strerror(errno));
}
snprintf(tname, sizeof(tname), "%s#%02d-%s", thread_name,
thread+1, visual_devname);
snprintf(printable_threadname, strlen(thread_name)+5+strlen(dev),
"%s#%02d-%s", thread_name, thread+1,
dev);
snprintf(printable_threadname, printable_threadname_size, "%s#%02d-%s", thread_name,
thread + 1, dev);
ThreadVars *tv_receive =
TmThreadCreatePacketHandler(tname,
@ -264,7 +264,8 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod
char tname[TM_THREAD_NAME_MAX];
TmModule *tm_module = NULL;
const char *visual_devname = LiveGetShortName(live_dev);
char *printable_threadname = SCMalloc(sizeof(char) * (strlen(thread_name)+5+strlen(live_dev)));
const size_t printable_threadname_size = strlen(thread_name) + 10 + strlen(live_dev) + 1;
char *printable_threadname = SCMalloc(printable_threadname_size);
if (unlikely(printable_threadname == NULL)) {
FatalError("failed to alloc printable thread name: %s", strerror(errno));
exit(EXIT_FAILURE);
@ -272,13 +273,13 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod
if (single_mode) {
snprintf(tname, sizeof(tname), "%s#01-%s", thread_name, visual_devname);
snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#01-%s",
thread_name, live_dev);
snprintf(printable_threadname, printable_threadname_size, "%s#01-%s", thread_name,
live_dev);
} else {
snprintf(tname, sizeof(tname), "%s#%02d-%s", thread_name,
thread+1, visual_devname);
snprintf(printable_threadname, strlen(thread_name)+5+strlen(live_dev), "%s#%02d-%s",
thread_name, thread+1, live_dev);
snprintf(printable_threadname, printable_threadname_size, "%s#%02d-%s", thread_name,
thread + 1, live_dev);
}
ThreadVars *tv = TmThreadCreatePacketHandler(tname,
"packetpool", "packetpool",

Loading…
Cancel
Save