Closed maxsharabayko closed 2 weeks ago
The warning is shown on any type with a size of 1 byte (char, uint8_t, bool, etc.), and not shown on, e.g. uint16_t
.
To check comment out all importOption calls in CGroup::deriveSettings(..)
and experiment with the type of v
:
uint8_t v = 32;
importOption(m_config, SRTO_TLPKTDROP, v);
std::copy
Is UsedThe warning is not shown if std::copy
is replaced with memcpy
or a manual byte copy:
ConfigItem(SRT_SOCKOPT o, const void* val, int size)
: so(o)
{
value.resize(size);
unsigned char* begin = (unsigned char*)val;
// No warning with memcpy:
//memcpy(value.data(), begin, size);
// No warning with this kind of copy:
//for (int i = 0; i < size; ++i)
// value[i] = begin[i];
// This produces the warning:
std::copy(begin, begin + size, value.begin());
}
The warning is not shown if the following if-statement is removed
template <class ValueType>
static void importOption(vector<CUDTGroup::ConfigItem>& storage, SRT_SOCKOPT optname, const ValueType& field)
{
ValueType default_opt = ValueType();
int default_opt_size = sizeof(ValueType);
ValueType opt = field;
// No warning if we remove this `if`, but keep the `push_back` that follows.
if (!getOptDefault(optname, (&default_opt), (default_opt_size)) || default_opt != opt)
{
// Store the option when:
// - no default for this option is found
// - the option value retrieved from the field is different than default
storage.push_back(CUDTGroup::ConfigItem(optname, &opt, default_opt_size));
}
}
It looks like passing the default_opt_size
by reference and potentially changing it makes the compiler produce the warning.
The length is determined by the return value of the following template function:
template <class Type>
struct Value
{
static int fill(void* optval, int, Type value)
{
// XXX assert size >= sizeof(Type) ?
*(Type*)optval = value;
return sizeof(Type);
}
};
Although it seems to return 1
for a Boolean, but the compiler is not happy with such a manipulation.
produces the following warning with GCC 13.2 (Ubuntu 24.04)