Project

General

Profile

Bug #4365

Truncation warning in operator<<(std::ostream&, const LoggerTimestamp&)

Added by Davide Pesavento over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Low
Category:
Utils
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:

Description

On Ubuntu 17.10, release mode:

../src/util/logger.cpp: In function ‘std::ostream& ndn::util::operator<<(std::ostream&, const ndn::util::LoggerTimestamp&)’:
../src/util/logger.cpp:113:1: warning: ‘%06ld’ directive output may be truncated writing between 6 and 7 bytes into a region of size between 6 and 16 [-Wformat-truncation=]
 operator<<(std::ostream& os, const LoggerTimestamp&)
 ^~~~~~~~
../src/util/logger.cpp:113:1: note: directive argument in the range [-999999, 999999]
In file included from /usr/include/stdio.h:862:0,
                 from /usr/include/c++/7/cstdio:42,
                 from /usr/include/c++/7/ext/string_conversions.h:43,
                 from /usr/include/c++/7/bits/basic_string.h:6349,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/stdexcept:39,
                 from /usr/include/c++/7/array:39,
                 from /usr/include/c++/7/tuple:39,
                 from /usr/include/c++/7/functional:54,
                 from ./../src/common.hpp:56,
                 from ./../src/common-pch.hpp:28,
                 from <command-line>:0:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:65:44: note: ‘__builtin___snprintf_chk’ output between 9 and 20 bytes into a destination of size 18
        __bos (__s), __fmt, __va_arg_pack ());
                                            ^
#1

Updated by Davide Pesavento about 3 years ago

  • Status changed from New to In Progress
  • Assignee set to Davide Pesavento
  • Priority changed from Normal to Low

The compiler derives a lower bound of -999999 because it does not know that "time since epoch" cannot be negative, therefore it calculates that an additional char could be needed for the minus sign.

#2

Updated by Davide Pesavento about 3 years ago

  • Description updated (diff)
  • Status changed from In Progress to Code review
  • % Done changed from 0 to 100

abs() silences the warning: https://gerrit.named-data.net/4455

#3

Updated by Davide Pesavento about 3 years ago

  • Status changed from Code review to Closed

Also available in: Atom PDF