38 Commits

Author SHA1 Message Date
iphydf
6f735b51be chore: Happy new year 2026! 2026-01-27 22:35:47 +00:00
iphydf
8e8b352abc refactor: Add nullable annotations to struct members.
Also add a bunch of casts where needed. I've tried to model everything
in such a way that it minimises casts. The casts *should* be safe, but
it's not always obvious. In the obvious cases, we should have a linter
that validates it. In the non-obvious cases, that linter should warn and
require that we add a null check. I've added some null checks in some
cases but not all.

Also, refactored some of the constructor functions to never assign a
maybe-null value to a non-null struct member, instead using a temporary
local variable to check if construction/allocation succeeded.
2026-01-04 23:38:38 +00:00
iphydf
40b3f0b463 refactor: Use clang's nullability qualifiers instead of attributes. 2025-07-13 00:26:24 +00:00
iphydf
f81e30679b refactor: Use per-parameter nullability annotations.
This is less error-prone.
2025-07-12 09:20:18 +00:00
iphydf
bc43cec062 chore: Happy new year! 2025-01-05 23:24:52 +00:00
iphydf
511bfe39c8 cleanup: Use Bazel modules to enforce proper #include hygiene. 2024-01-30 23:51:43 +00:00
iphydf
0426624dcb refactor: Assign malloc return to a local variable first. 2024-01-10 11:46:41 +00:00
iphydf
fad6e4e173 cleanup: Make all .c files include the headers they need. 2023-12-27 01:21:47 +00:00
iphydf
a549807df7 refactor: Add mem module to allow tests to override allocators.
This will allow us to do more interesting things with memory allocation
within toxcore, and allow fuzzers to explore various allocation failure
paths.
2023-08-30 22:55:05 +00:00
iphydf
cc31ff07fa feat: Add support for custom random number generator.
This can be used by fuzzers to make RNG-driven code deterministic (i.e.
based on the fuzzer input).
2022-04-01 14:06:05 +00:00
iphydf
e1e92c1ac1 docs: Clean up doxygen comments to be more doxygen-like. 2022-03-05 22:30:48 +00:00
iphydf
cff9a18e39 cleanup: Split util.c out of the network library.
Also, don't include ccompat.h in header files. Instead, explicitly
include it in .c files.
2022-03-04 10:33:11 +00:00
iphydf
c20f878934 cleanup: Remove some more implicit bool conversions.
Also removed one explicit bool cast.
Also avoid using the same name for struct fields and global functions.
2022-03-01 18:16:11 +00:00
iphydf
10f86f6c00 cleanup: Add more nonnull and nullable annotations. 2022-02-09 20:03:34 +00:00
iphydf
074051078d chore: Make all top level comments doxygen style /**.
This allows tokstyle to match them between header and source.
2022-02-04 22:43:02 +00:00
iphydf
73484d8995 cleanup: Use calloc instead of malloc for struct allocations.
`malloc` is used only for byte/int arrays. Also, we no longer allow plain
`void *` allocations. Every allocation should have a real value type.
2022-01-09 22:42:50 +00:00
iphydf
f49168e209 chore: Make all function comments doxygen style /** comments.
This way, they become eligible for the tokstyle comment sync check.
2021-12-22 10:48:53 +00:00
iphydf
fd32c87707 cleanup: Don't include "config.h" unless needed.
Currently only `crypto_core_mem.c` needs this. We should try not to
depend on configure'd values. Also note: config.h is only created and
used in the autotools build. In CMake, we pass `-D` flags directly.
2021-12-12 22:18:38 +00:00
iphydf
2570ddcb17 Fix errors on error paths found by oomer.
* Use-after-free because we free network before dht in one case.
* Various unchecked allocs in tests (not so important).
* We used to not check whether ping arrays were actually allocated in DHT.
* `ping_kill` and `ping_array_kill` used to crash when passing NULL.

Also:
* Added an assert in all public API functions to ensure tox isn't NULL.
  The error message you get from that is a bit nicer than "Segmentation
  fault" when clients (or our tests) do things wrong.
* Decreased the sleep time in iterate_all_wait from 20ms to 5ms.
  Everything seems to still work with 5ms, and this greatly decreases
  the amount of time spent per test run, making oomer run much faster.
2020-05-02 21:47:08 +01:00
iphydf
11ad5471b9 Use spdx license identifier instead of GPL blurb. 2020-03-14 13:06:19 +00:00
iphydf
473cde24d8 Update copyright to 2018. 2018-08-26 18:57:29 +00:00
iphydf
a1035cf814 Add some tests for ping_array.
No timeout test here yet, because we don't yet have the ability to
manipulate time at will, so we would have to actually sleep.
2018-08-26 17:32:19 +00:00
iphydf
d6d305feeb Use per-instance Mono_Time for Messenger and onion. 2018-08-16 21:01:43 +00:00
iphydf
abc17b0f89 Factor out time keeping code into its own module: mono_time.c.
It turns out, `unix_time` is also monotonic, and is used as such, so I've
renamed the new functions to `mono_time_*`.

2018-07-08:
```
00:01 <@irungentoo> the idea used to be that the unix_time() function
  could go backward in time but I think I might have started using it like
  if it could not after I changed it so that it would never go back in time
```
2018-07-09 21:04:50 +00:00
iphydf
2b49f80395 Rename BS_LIST to BS_List to follow the naming conventions.
`BS_LIST` would be a constant. `BS_List` is a type name.
2018-07-08 19:03:52 +00:00
iphydf
be797d4b03 Move system header includes from network.h to network.c 2018-05-20 15:42:42 +00:00
iphydf
92ffad1a72 Use nullptr as NULL pointer constant instead of NULL or 0.
This changes only code, no string literals or comments.
2018-01-30 23:35:50 +00:00
iphydf
da739a9438 Add random_u16 function and rename the others to match. 2018-01-14 21:08:02 +00:00
iphydf
e775b5533b Make Ping_Array a module-private type. 2018-01-13 23:55:08 +00:00
iphydf
8f96ca6d86 Update license headers and remove redundant file name comment.
"All rights reserved" was incorrect. The project was licensed under GPL3,
which means a lot of rights are licensed to everybody in the world, i.e.
not reserved to the "Tox Project".
2017-01-19 00:01:44 +00:00
iphydf
15cb426166 Make toxcore code C++ compatible.
It is still C code, so still compatible with C compilers as well. This
change lets us see more clearly where implicit conversions occur by
making them explicit.
2016-09-24 21:53:50 +01:00
iphydf
0aa2840164 Group #include directives in 3-4 groups.
1. Current module (if C file).
2. Headers from current library.
3. Headers from other library (e.g. toxcore includes in toxav).
4. System headers.
2016-09-13 00:32:02 +01:00
iphydf
77db27331e Sort #includes in all source files. 2016-09-01 16:35:46 +01:00
iphydf
633da98ae6 Add braces to all if statements. 2016-08-31 20:04:16 +01:00
kyle condon
a13bc5e70c Update ping_array.c
Change calloc call on line 138 from empty_array->entries = calloc(size * sizeof(Ping_Array_Entry), 1);, to empty_array->entries = calloc(size, sizeof(Ping_Array_Entry));
2014-07-06 09:55:46 +01:00
Marc Schütz
99d5940140 Const correctness in various interdependent files 2014-06-10 20:54:48 +02:00
irungentoo
5b58da35f9 Fixed segfault. 2014-05-12 19:48:19 -04:00
irungentoo
10da970e0d Added ping_array, a special efficient array for use in operations
that require sending ping type packets.

Made ping packets use it.
2014-05-12 14:07:03 -04:00