Commit graph

2170 commits

Author SHA1 Message Date
Andrew Kaster f32e185269 AK: Suppress false positive readability-non-const-parameter in Function
In AK::Function::CallableWrapper::init_and_swap(), clang-tidy wants us
to mark the destination argument as pointer to const, which doesn't work
because we use placement new to construct a move'd *this into.
2021-11-14 22:52:35 +01:00
Andrew Kaster 7014d37dd6 AK+Kernel: Suppress clang-tidy warnings from the cert-* category
cert-dcl50-cpp: No variadic functions, suppressed in RefCounted and
ThreadSafeRefCounted for implementing the magic one_ref_left and
will_be_destroyed functions.

cert-dcl58-cpp: No opening ::std, suppressed in the places we put names
in ::std to aid tools (move, forward, nullptr_t, align_val_t, etc).
2021-11-14 22:52:35 +01:00
Andrew Kaster 2b16ee742e AK: Avoid implicit conversion clang-tidy warnings in AK::Time 2021-11-14 22:52:35 +01:00
Andrew Kaster 2c4f7fae1e AK: Move StandardFormatter argument into base class initializer
Subclasses of StandardFormatter don't need to use the formatter argument
in their constructor, so move() it into the base class initializer.
2021-11-14 22:52:35 +01:00
Andrew Kaster 74e8aa73e5 AK: Avoid implicit conversions in TypeErasedParameter::to_size()
Refactor to a visitor+functor pattern that does an explicit static_cast
to size_t after performing suitable range checks for each type.
2021-11-14 22:52:35 +01:00
Andrew Kaster 762b92c650 AK: Resolve clang-tidy readability-qualified-auto warnings
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00
Andrew Kaster 64edf17eb2 AK: Mark StringView::find_any_of() as const 2021-11-14 22:52:35 +01:00
Andrew Kaster 163367da39 AK: Resolve clang-tidy warnings about unusual assignment operators
Either not returning *this, or in the case of Variant, not checking for
self assignment. In AK::Atomic, we can't return *this due to the wrapper
semantics Atomic implements.
2021-11-14 22:52:35 +01:00
Andrew Kaster 22feb9d47b AK: Resolve clang-tidy readability-bool-conversion warnings
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00
Andrew Kaster 10d0cac73c AK: Use capitalized literal suffixes for AK::abs() overloads
Using `l` for long double causes a clang-tidy warning, so use all caps
suffixes for all of the AK::abs() overloads for consistency. Also, avoid
leaking the internal __DEFINE_GENERIC_ABS macro.
2021-11-14 22:52:35 +01:00
Andrew Kaster e982253c33 AK: Avoid else after return in files commonly included by the Kernel 2021-11-14 22:52:35 +01:00
Andrew Kaster 07f4e91b94 AK: Use proper type for bool NumericLimits::min and max specialization
We had these declared as returning char, which looks like a copy paste
error. Found by clang-tidy.
2021-11-14 22:52:35 +01:00
Andrew Kaster 7e2ee2e725 AK: Suppress false-positive clang-tidy warning in Assertions.h
The definition of VERIFY_NOT_REACHED() as `assert(false)` causes the
tool to suggest converting it to a static_assert. Which doesn't make
any sense in context for what the macro is trying to do: crash the
program at runtime.
2021-11-14 22:52:35 +01:00
Andrew Kaster 3eeca784d2 Meta: Add basic clang-tidy configuration
Add a basic clang-tidy configuration that enables checks from the
following categories:

- bugprone
- cert
- clang-analyzer
- concurrency
- misc
- performance
- portability
- readability

The noisiest rules that have conflicts with the project style guide or
accepted practices have been turned off.

There's absolutely more work to be done here before we could consider
setting any of these warnings as errors and enforcing them in CI, but
committing a project clang-tidy configuration should help the rules
become more visible and let other contributors take a crack at tweaking
rules and/or finding possible bugs.

Sadly the cpp-core-guidelines and modernize categories are very, very
noisy. If we want to enable rules from these categories, they would need
to be on a rule by rule basis.
2021-11-14 22:52:35 +01:00
Brian Gianforcaro d1806d44fa AK: Swallow 'L' format specifier until it is properly implemented
Previously if code attempted to use the format specifier somewhere
(Ex: "%#4.3Lg"), the specifier would get dropped and we would just
print "g" instead of any value. Now at least we print a value.
2021-11-14 16:18:45 +00:00
Ali Mohammad Pur 7d1142e2c8 LibWasm: Implement module validation 2021-11-11 09:20:04 +01:00
Hendiadyoin1 f76241914c AK: Allow to clear HashTables/Maps with capacity 2021-11-11 09:19:17 +01:00
Andreas Kling 80d4e830a0 Everywhere: Pass AK::ReadonlyBytes by value 2021-11-11 01:27:46 +01:00
Andreas Kling 8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling 9d1f238450 AK: Make HashTable and HashMap try_* functions return ErrorOr<T>
This allows us to use TRY() and MUST() with them.
2021-11-11 01:27:46 +01:00
Andreas Kling a15ed8743d AK: Make ByteBuffer::try_* functions return ErrorOr<void>
Same as Vector, ByteBuffer now also signals allocation failure by
returning an ENOMEM Error instead of a bool, allowing us to use the
TRY() and MUST() patterns.
2021-11-10 21:58:58 +01:00
Andreas Kling 88b6428c25 AK: Make Vector::try_* functions return ErrorOr<void>
Instead of signalling allocation failure with a bool return value
(false), we now use ErrorOr<void> and return ENOMEM as appropriate.
This allows us to use TRY() and MUST() with Vector. :^)
2021-11-10 21:58:58 +01:00
Andreas Kling cd49f30bea AK+LibJS: Simplify MUST() and move it from LibJS to AK/Try.h
This is generally useful so let's move it to AK. Also it seems that we
don't need the temporary variable hack anymore, so let's lose that.
2021-11-10 21:58:58 +01:00
Andreas Kling 5f7d008791 AK+Everywhere: Stop including Vector.h from StringView.h
Preparation for using Error.h from Vector.h. This required moving some
things out of line.
2021-11-10 21:58:58 +01:00
Ben Wiederhake b7e6118098 AK: Properly declare inheritance of Bitmap from BitmapView
All the read-only methods of Bitmap simply defer to BitmapView. Let's
make this relationship official by using class inheritance. This might
even shave off a few instructions, although any sufficiently optimizing
compiler probably already optimized them away.
2021-11-10 14:39:42 +01:00
Ben Wiederhake bf7a2ff941 AK+Kernel: Make BitmapView read-only 2021-11-10 14:39:42 +01:00
Andreas Kling 79fa9765ca Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
2021-11-08 01:10:53 +01:00
Andreas Kling 7ee10c6926 AK: Add some more ways to construct Error and ErrorOr<T>
This is preparation for using Error in the kernel instead of KResult.
2021-11-08 00:36:35 +01:00
Andreas Kling 5e473a63d3 AK: Make Error.h pull in Try.h
Users of this API will want TRY().
2021-11-08 00:36:19 +01:00
Andreas Kling e841f3c283 AK: Add a variant of adopt_nonnull_own_or_enomem() for userspace
This variant returns ErrorOr<NonnullOwnPtr<T>> instead of KResultOr.
Eventually the KResultOr variant should go away once the kernel adopts
Error and ErrorOr<T>.
2021-11-08 00:35:27 +01:00
Andreas Kling 184810a581 AK: Remove now-unused OSError class
This has been superseded by the more generally useful AK::Error :^)
2021-11-08 00:35:27 +01:00
Andreas Kling e253cf694e AK: Allow subclassing Error 2021-11-08 00:35:27 +01:00
Andreas Kling 0f5477c721 AK: Use ErrorOr<T> for MappedFile factories
Replace Result<T, E> with ErrorOr<T> and propagate the error to callers.
2021-11-08 00:35:27 +01:00
Andreas Kling c837bd551e AK: Don't define ENABLE_COMPILETIME_FORMAT_CHECK when parsed by CLion 2021-11-08 00:35:27 +01:00
Andreas Kling 880964755b AK: Don't define AK_HAS_CONDITIONALLY_TRIVIAL when parsed by CLion IDE
This feature confuses CLion's parser, so let's turn it off if we see the
__CLION_IDE_ macro as well.
2021-11-08 00:35:27 +01:00
Andreas Kling 202950bb01 AK: Make Error and ErrorOr<T> work in Lagom as well :^)
ErrnoCode is not a thing outside __serenity__, so let's not make
assumptions about it existing.
2021-11-08 00:35:27 +01:00
Andreas Kling 2116620db8 AK: Add ErrorOr<T>::release_value_but_fixme_should_propagate_errors()
This is an alternative to ErrorOr<T>::release_value() that can be used
when converting code to signal that we're releasing the value without
error propagation as a way to move forward now.

This makes these cases much easier to find later on, once more paths for
error propagation are available.
2021-11-08 00:35:27 +01:00
Andreas Kling e5dde37e24 AK: Bring AK::Error into the global namespace 2021-11-08 00:35:27 +01:00
Andreas Kling 56992f90b7 AK: Add adopt_nonnull_ref_or_enomem() for userspace
We already had this mechanism in the kernel. Let's have it in userspace
as well. This return an ErrorOr<NonnullRefPt<T>>. :^)
2021-11-08 00:35:27 +01:00
Andreas Kling c4edb9f6c2 AK: Add Error and ErrorOr<T>
The goal with these is to eventually replace AK::Result, KResult and
KResultOr<T> with something that works (and makes sense) in both kernel
and userspace.

This first cut of Error can be made from an errno code, or from a string
literal (StringView)
2021-11-08 00:35:27 +01:00
Musab Kılıç f6a43c7cf5 AK: Add min and max functions to Statistics 2021-11-06 22:09:25 -07:00
Ben Wiederhake 03526a7f2b AK: Make BumpAllocator work in multi-threaded environments
Fixes #10578.
2021-10-31 18:43:03 +01:00
Daniel Bertalan fed9cb5d2d AK+Tests: Fix formatting of infinity and NaN values
When I added this code in 1472f6d, I forgot to add tests for it. That's
why I didn't realize that the values were appended to the wrong
FormatBuilder object, so an empty string was returned instead of the
expected "nan"/"inf". This made debugging some FPU issues with the
ScummVM port significantly more difficult.
2021-10-31 12:15:34 +01:00
Andreas Kling 47c140610d AK: Prefix debug log messages with current-time-since-boot
This is very helpful when trying to better understand how long certain
things take. :^)
2021-10-26 01:00:54 +02:00
Leandro Pereira 368e74fdf8 AK: Allow seed value to be specified in string_hash()
For some algorithms, such as bloom filters, it's possible to reuse a
hash function (rather than having different hashing functions) if the
seed is different each time the hash function is used.

Modify AK::string_hash() to take a seed parameter, which defaults to 0
(the value the hash value was originally initialized to).
2021-10-25 23:37:18 +02:00
Andreas Kling b4c0e27d26 AK: Always inline Optional::release_value()
This allows the compiler to optimize away the VERIFY(m_has_value) in
many cases.
2021-10-25 14:31:46 +02:00
Andreas Kling b2f15537bb AK: Add fast path for constructing StringImpl from "" literal 2021-10-25 13:29:44 +02:00
Ben Wiederhake cb868cfa41 AK+Everywhere: Make Base64 decoding fallible 2021-10-23 19:16:40 +01:00
Ben Wiederhake 3bf1f7ae87 AK: Don't crash on invalid Base64 input
In the long-term, we should probably have a way to signal decoding
failure. For now, it should suffice to at least not crash. This is
particularly relevant because apparently this can be triggered while
parsing a PEM certificate, which happens during every TLS connection.

Found by OSS Fuzz
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38979
2021-10-23 19:16:40 +01:00
Ben Wiederhake 50698a0db4 AK: Prevent accidental misuse of BumpAllocator
In particular, we implicitly required that the caller initializes the
returned instances themselves (solved by making
UniformBumpAllocator::allocate call the constructor), and BumpAllocator
itself cannot handle classes that are not trivially deconstructible
(solved by deleting the method).

Co-authored-by: Ali Mohammad Pur <ali.mpfard@gmail.com>
2021-10-23 19:02:54 +01:00