toxcore/other
Maxim Biro 55a76003b0
Replace memset(int32_t*, -1, _) with a for-loop
memset() treats the passed buffer as a char* array, assigning to every
1-byte of the array the value. So for a single 4-byte int32_t element,
it is assigning bytes 0, 1, 2 and 3 of it to -1. It happens that -1 is
0xFF, so in the end the uint32_t is set to 0xFFFFFFFF, which is -1 in
the two's complement, so the memset() actually produces the correct
result in the end, assuming the platform uses two's complement integers.

Assigning it in the loop is less error-prone, as using memset() on
non-1-byte wide arrays with a non-zero value is fishy, and it is more
portable as we don't have to assume the use of two's complement.

It looks like in a future version of the C standard, C23, two's
complement is the only integer format in C23 (thanks to @robinlinden on
IRC for pointing that out), so perhaps we shouldn't be as concerned with
the portability here? Though @iphydf says that it's still a good idea to
use a for-loop for this case.
2023-12-13 18:40:12 -05:00
..
analysis Clarify disabling of static assert checks 2023-12-05 06:56:27 -05:00
astyle fix: Fix some uninitialised memory errors found by valgrind and msan. 2022-01-13 20:15:21 +00:00
bootstrap_daemon Replace memset(int32_t*, -1, _) with a for-loop 2023-12-13 18:40:12 -05:00
docker chore: Cancel old PR builds on docker and sonar-scan workflows. 2023-11-22 23:38:50 +00:00
emscripten refactor: Use cmp instead of msgpack-c for events packing. 2022-03-26 23:57:15 +00:00
fun Fix memory leak in save-generator 2023-12-08 03:31:12 -05:00
pkgconfig update rpm spec and use variables in cmake instead of hardcoded paths (#624) 2018-01-15 14:23:33 +03:00
proxy cleanup: Remove explicit layering_check feature. 2023-11-23 23:55:57 +00:00
rpm Use the markdown GPLv3 license in the c-toxcore repo. 2018-02-08 16:08:09 +00:00
bootstrap_node_packets.c Make functions take const pointer to IP_Port wherever possible 2022-02-03 10:54:48 -05:00
bootstrap_node_packets.h cleanup: Remove uses of strcpy and sprintf. 2022-01-17 18:25:40 +00:00
BUILD.bazel cleanup: Remove explicit layering_check feature. 2023-11-23 23:55:57 +00:00
DHT_bootstrap.c fix: always respond to version packets with toxcore version 2023-11-13 15:45:17 +00:00
DHTnodes Link changes. 2015-07-07 22:57:11 -04:00
make_single_file refactor: Use cmp instead of msgpack-c for events packing. 2022-03-26 23:57:15 +00:00
Makefile.inc Avoid implementations in .h files or #including .c files. 2018-07-21 20:44:26 +00:00
osx_build_script_toxcore.sh
print-version chore: Add bootstrap daemon docker image build. 2021-12-23 15:54:24 +00:00
tox-warning.png [ImgBot] Optimize images 2020-04-24 21:55:23 +00:00
tox.png [ImgBot] Optimize images 2020-04-24 21:55:23 +00:00
version-sync Bump toxcore version to 0.2.0. 2018-01-08 19:36:00 +00:00
windows_build_script_toxcore.sh Update deps used in Windows build scripts 2021-02-25 13:59:18 +03:00