G++ warnings for set-control-group-knob from nosh-1.37

From: Guillermo <gdiazhartusch_at_gmail.com>
Date: Sun, 11 Mar 2018 12:06:01 -0300

Hello,

1) G++ says:

set-control-group-knob.cpp: In function 'void
set_control_group_knob(const char*&, std::vector<const char*>&,
ProcessEnvironment&)':
set-control-group-knob.cpp:179:5: warning: 'hundred' may be used
uninitialized in this function [-Wmaybe-uninitialized]
     if (hundred > std::numeric_limits<uint_least64_t>::max() / 100U)
     ^~

The only reference to 'hundred' after its definition is the call
'read_first_line_number (percent_of, hundred)', where 'percent_of'
holds the filename passed to set-control-group-knob(1) via its
--percent-of option. read_first_line_number() is defined as this set
of overloaded functions:

bool read_first_line_number (std::istream & i, uint_least64_t v);
bool read_first_line_number (const char * filename, uint_least64_t & v);

The second one is basically a wrapper for the first one. Looking at
the code, shouldn't the 'v' parameter of the first one also have a
reference type?

2) G++ also says:

set-control-group-knob.cpp:153:13: warning: In the GNU C Library,
"major" is defined
 by <sys/sysmacros.h>. For historical compatibility, it is
 currently defined by <sys/types.h> as well, but we plan to
 remove this soon. To use "major", include <sys/sysmacros.h>
 directly. If you did not intend to use a system-defined macro
 "major", you should undefine it after including <sys/types.h>.

set-control-group-knob.cpp:153:13: warning: In the GNU C Library,
"minor" is defined
 by <sys/sysmacros.h>. For historical compatibility, it is
 currently defined by <sys/types.h> as well, but we plan to
 remove this soon. To use "minor", include <sys/sysmacros.h>
 directly. If you did not intend to use a system-defined macro
 "minor", you should undefine it after including <sys/types.h>.

This warning is present for GNU libc >= 2.25, so may I suggest adding
the following to source/set-control-group-knob.cpp?

#if defined(__LINUX__) || defined(__linux__)
#include <sys/sysmacros.h>
#endif

I believe this should work even for Debian jessie's GNU libc 2.19.

Thanks,
G.
Received on Sun Mar 11 2018 - 15:06:01 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC