When building with -D_GLIBCXX_DEBUG, gcc-11 warns:
```
In file included from /usr/include/string.h:535,
from similar/main/net_udp.cpp:14:
In function 'void* memcpy(void*, const void*, size_t)',
inlined from 'virtual void d2x::multi::udp::dispatch_table::send_data_direct(std::span<const unsigned char>, dcx::playernum_t, int) const' at similar/main/net_udp.cpp:5731:8:
/usr/include/bits/string_fortified.h:29:33: error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
29 | return __builtin___memcpy_chk (__dest, __src, __len,
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
30 | __glibc_objsize0 (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
```
The warning is invalid: the destination buffer is not PTRDIFF_MAX bytes
long, and the requested length is not SIZE_MAX bytes. Both claimed
lengths are the result of excessively cautious value range tracking.
Eliminate the warning by adding a `cf_assert` to assure gcc that
`data.size() != std::dynamic_extent`.
Use printf `%.*s` with an appropriate length, instead of copying the
appropriate number of bytes into a temporary, null terminating it, and
relying on the terminator for printf.
Since this should never be invoked, simplify the definition. The new
version is slightly less informative in case a logic error causes it to
be called, but is far shorter and easier to understand.
Use a std::optional<vms_vector> to store the gun point and a flag of
whether the gun point is valid. This allows deferring computation of
the gun point until it is needed, and avoids recomputing it once it has
been computed. This also fixes an obscure case where a robot with its
gun positioned at 0,0,0 would be incorrectly considered too far away.
Gun point calculation is skipped in do_ai_frame if
dist_to_player >= 200 but a bot might still fire a homing weapon
if it is further away.
Add extra call to calc_gun_point in ai_do_actual_firing_stuff when
a homing weapon is fired without visibility to make sure a valid
gun point is used.
This is an original game bug, shown for example in this video:
https://www.youtube.com/watch?v=2dP51znGh7o
Python3 does not expose an attribute `message` on `Exception`. However,
`Exception` can implicitly convert to a string, and produces the
message. Switch to that.
object_create_muzzle_flash delegated to
object_create_explosion_without_damage, adding one parameter that
callers ought to provide instead. Inline object_create_muzzle_flash into
callers and change them to provide `Vclip`.
Observe that `nn` is at most `signal.size() - 1`, which occurs on the
final pass of the loop. Therefore, `std::min` will always pick `nn`
instead of `signal.size() - 1`, so simplify out the call.
Commit d2478d0708 made support for C++17 fallthrough mandatory, and
should have deleted this test. Delete it now.
Fixes: d2478d0708 ("Require support for C++17 attribute [[fallthrough]]")
Win32 aliases `size_t` to `unsigned int`, causing
`static_cast<size_t>(V)` to be a useless cast when `V` has type
`unsigned int`. Switch to using direct initialization, which is not a
cast and so does not trigger a warning, but does produce the correct
type. This form disallows narrowing, so inputs that might change in
value as a result of the conversion are an error. Since this is a
sanity checking macro, that is a useful safety measure.
Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/678#issue-1437577368>
bmread.cpp uses PRIuFAST32, so it should include inttypes.h to get the
definition of this macro. Some platforms happened to include inttypes.h
as an implementation detail, but for portability, it needs to be
included explicitly in this file.
Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/678#issuecomment-1304962448>