Commit graph

665 commits

Author SHA1 Message Date
Alexander Akulich 6d9284adc1 Port some code to str_copy() template 2022-07-09 19:40:58 +03:00
Alexander Akulich c4f188a0e7 system: Add str_copy() template for fixed array destinations 2022-07-09 19:19:21 +03:00
Chairn 32318a7c90 Reworked color system
Removed duplicate structs. Replaced 4 floats array with appropriate
struct where applicable
2022-07-06 11:39:51 +02:00
Chairn 27da8391dc Replace 2 floats array with vec2 where it makes sense 2022-07-06 11:39:43 +02:00
Chairn 96e9364fb0 Fix more unsafe define 2022-06-29 23:52:03 +02:00
Chairn a9ee57aeb7 Fix unsafe defines 2022-06-27 18:51:02 +02:00
bors[bot] 6315af0729
Merge #5504
5504: Remove useless typedef in c++ r=Jupeyy a=Chairn

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Chairn <chairn.nq@hotmail.fr>
2022-06-26 06:49:01 +00:00
Chairn a3a85bee5f Remove useless typedef in c++ 2022-06-25 21:05:54 +02:00
Chairn a50ddb75ff clang-format 2022-06-25 15:30:39 +02:00
Chairn 5f5b80ae57 Use [[fallthrough]] attribute rather than comment 2022-06-25 15:21:44 +02:00
Jupeyy a22a8dce1c Fix Android build 2022-06-25 10:43:24 +02:00
Robert Müller 0813fbb537 Move android log include to correct file 2022-06-17 17:39:25 +02:00
Robert Müller 557ee84001 Organize base includes 2022-06-17 17:39:25 +02:00
Robert Müller da5ec5a0d2 Include <iterator> instead of <array> for std::size
As `std::size` nominally resides in `<iterator>`.
2022-06-17 17:39:24 +02:00
Robert Müller c7fb013607 Add io_read_all, io_read_all_str and mem_has_null:
- `io_read_all` reads all bytes from a file handle into a new buffer. It should only need one allocation per file in cases where the actual file size matches the expected file size. Otherwise it falls back to doubling the buffer size if the actual file size is larger than expected to avoid TOCTOU problems.
- `io_read_all_str` reads all bytes from a file handle into a new buffer and also ensures that the buffer is null-terminated and contains no other null-characters.
- `mem_has_null` is a utility used by `io_read_all_str` to ensure that no null-characters exist in the bytes read from the file.
2022-06-16 10:19:36 +02:00
Chairn c9345e7d32 More vector naming format 2022-06-15 19:37:37 +02:00
bors[bot] caf889d04a
Merge #5406
5406: Remove namespace tw r=Jupeyy a=heinrich5991

It didn't have a clear role, it just acted as a distinguisher between
two functions with the same name.

Rename `tw::time_get` to `time_get_nanoseconds` and delete the old
`time_get_nanoseconds`. Move `CCmdlineFix` and the typed
`net_socket_read_wait` function to the global namespace.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
2022-06-14 17:46:17 +00:00
Robert Müller 92699de86c Add log_set_loglevel instead of depending on engine config 2022-06-13 23:21:41 +02:00
heinrich5991 b3a3604c36 Remove namespace tw
It didn't have a clear role, it just acted as a distinguisher between
two functions with the same name.

Rename `tw::time_get` to `time_get_nanoseconds` and delete the old
`time_get_nanoseconds`. Move `CCmdlineFix` and the typed
`net_socket_read_wait` function to the global namespace.
2022-06-13 18:07:29 +02:00
Chairn 01edaec628 Format vector variables names (fixes #5209) 2022-06-11 21:38:49 +02:00
Robert Müller de199d08c0 Fix doxygen comments 2022-06-06 12:50:08 +02:00
Robert Müller e6bd84d4fd Extract CCmdlineFix to call cmdline_fix and cmdline_free automatically 2022-06-06 12:46:58 +02:00
bors[bot] d49b7b1561
Merge #5351
5351: Refactoring: Use MultiByteToWideChar instead of str_utf16le_encode r=heinrich5991 a=Robyt3



## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-06-06 08:41:14 +00:00
Robert Müller fca867702e Add error messages when log message encoding cannot be converted 2022-06-06 10:28:47 +02:00
def 8623381529 Don't write null byte
Thanks to heinrich5991 for noticing
2022-06-06 09:47:12 +02:00
bors[bot] ef5501c4da
Merge #5332
5332: Pass output parameter to WriteFile that is required on Windows 7 r=heinrich5991 a=Robyt3

Maybe closes #5322. I can't reproduce the crash. Can you try if this fixes it, `@Chairn?`

Looks like Windows 7 needs this parameter.

Alternative to #5331.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-06-05 20:52:42 +00:00
Robert Müller 3dd2df285a Use MultiByteToWideChar instead of str_utf16le_encode 2022-06-05 20:51:56 +02:00
def ea5999d1da Don't write aAnsi when it's not filled (fixe #5340) 2022-06-05 11:30:54 +02:00
Robert Müller e5d2b815eb Pass output parameter to WriteFile that is required on Windows 7 2022-06-03 15:55:57 +02:00
bors[bot] ce795572d2
Merge #5327
5327: Add CLockScope r=heinrich5991 a=def-

Remove unused lock and scope in threading.h

Not sure if this is preferred

We could also try switching to std::mutex and lock_guard

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
2022-06-03 10:58:17 +00:00
Dennis Felsing 129205d6b9 Reset colors at end of line (fixes #5324) 2022-06-03 12:22:37 +02:00
Dennis Felsing 51909c19ab Add CLockScope
Remove unused lock and scope in threading.h

Not sure if this is preferred

We could also try switching to std::mutex
2022-06-03 12:21:23 +02:00
bors[bot] 9dd46eb764
Merge #5260
5260: Pr thread safety negative r=heinrich5991 a=def-

WorkerThread is hard because `REQUIRES(!((CJobPool *)pUser)->m_Lock)` would require alias analysis or the function using that everywhere.

https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#negative

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
2022-06-01 11:17:30 +00:00
bors[bot] eab87e0d52
Merge #5291
5291: Windows: Use current console background color, restore original color on exit, refactoring r=heinrich5991 a=Robyt3

- Remember initial console foreground and background color.
- Use the original background color with the message specific foreground color, so it looks better when the console background color isn't black.
- Restore the initial console foreground and background color on exit instead of leaving the color be whatever was last used.
- Add locks to ensure `Log`-calls from different threads don't overlap their output/color.
- Refactoring: Replace numbers with color constants defined in `wincon.h` (4312d20923/include/wincon.h (L51-L67)).
- Refactoring: Slightly reorder the `if`s and remove redundant checks which are ensured by the `else-if` structure.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-06-01 10:25:43 +00:00
Robert Müller 2a8b2ad455 Add locks to windows loggers 2022-05-31 19:21:40 +02:00
Robert Müller 2d7f67ddec Use current console background color, restore original color on exit 2022-05-31 17:48:28 +02:00
Robert Müller 95f244913f Remove duplicate conditional expressions 2022-05-31 17:48:28 +02:00
Robert Müller 2c04c00756 Use color constants in color_hsv_to_windows_console_color 2022-05-31 17:48:28 +02:00
heinrich5991 eb2823231f Work around Windows's definition of min/max
This allows us to use `std::min`/`std::max`.
2022-05-31 17:26:35 +02:00
bors[bot] 4183ad6b47
Merge #5179
5179: Add loglevel config (fixes #5178, fixes #5174) r=heinrich5991 a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
2022-05-31 08:21:03 +00:00
Robert Müller 0af146eb3b Remove unused includes from base 2022-05-29 19:49:38 +02:00
bors[bot] 1abe73c2ec
Merge #5272
5272: Handle failed socket creation (fixes #5267) r=heinrich5991 a=def-

by returning nullpointer, as the calling functions expect

Broken in 471bb441a1

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
2022-05-29 08:50:00 +00:00
def d6c1c7790c Handle failed socket creation (fixes #5267)
by returning nullpointer, as the calling functions expect

Broken in 471bb441a1
2022-05-29 00:43:07 +02:00
Alexander Akulich a5f4c66fd5 vmath: Make vector2_base() constructors constexpr 2022-05-28 20:58:22 +03:00
bors[bot] 719e3e4385
Merge #5264 #5266
5264: Prevent users from setting port 1-1023 r=Jupeyy a=def-

Following user report that they set cl_port 1 and it didn't work

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


5266: Use std::make_unique (fixes #5166) r=Jupeyy a=def-

No idea why clang-tidy's modernize-... didn't work

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
2022-05-28 16:01:32 +00:00
def 19dcd44fbe Use std::make_unique (fixes #5166)
No idea why clang-tidy's modernize-... didn't work
2022-05-28 14:46:55 +02:00
bors[bot] ccf0622984
Merge #5252
5252: Use std::vector instead of array, remove base/tl/array.h, algorithm.h, allocator.h, range.h r=def- a=Robyt3

Replaces all usages of `array` with `std::vector`.

I adjusted variable names of variables I changed to use the `v` prefix. Not so in the editor however, as there are already many changes due to clang-tidy enforcing the use of for-each loops.

This allows us to remove all remaining `base/tl` headers except `threading.h`.

Clang-tidy now finds `clang-analyzer-cplusplus.NewDelete` (Use of memory after it is freed), which is also fixed here, though it appears to be a false-positive.

This last remaining usages of `goto` are also removed.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-05-28 10:56:21 +00:00
Chairn 39e3f52bf3 clang-format 2022-05-28 02:22:43 +02:00
Chairn 4cba284b68 Fix possible misuse of comma 2022-05-28 02:15:42 +02:00
Dennis Felsing 174b855774 Enable -Wthread-safety-negative (as suggested by Chairn) 2022-05-28 02:14:46 +02:00