Commit graph

3299 commits

Author SHA1 Message Date
Martin Janiczek efa5fb5c3a AK: Fix one-off error in BitmapView::find_first and find_one_anywhere
The mentioned functions used m_size / 8 instead of size_in_bytes()
(division with ceiling rounding mode), which resulted in an off-by-one
error such that the functions didn't search in the last not-fully-8-bits
byte.

Using size_in_bytes() instead of m_size / 8 fixes this.
2023-10-11 15:58:16 +02:00
Sam Atkins 253a96277e AK: Add FixedMemoryStream methods for reading values "in place"
When working with FixedMemoryStreams, and especially MappedFiles, you
may don't want to copy the underlying data when you read from the
stream. Pointing into that data is perfectly fine as long as you know
the lifetime of it is long enough.

This commit adds a couple of methods for reading either a single value,
or a span of them, in this way. As noted, for single values you sadly
get a raw pointer instead of a reference, but that's the only option
right now.
2023-10-10 14:36:25 +02:00
Tim Ledbetter f10db48bab AK: Avoid overflow when passing i64 minimum value to vformat() 2023-10-09 09:39:02 +03:30
Tim Ledbetter e4fddc75f8 AK/FuzzyMatch: Check every match for neighbor character bonuses
Previously, the first match index was not checked to see if the camel
case or separator bonuses applied. The camel case bonus could also be
incorrectly applied where strings had non-alphabetical characters.
2023-10-06 22:09:18 +02:00
Tim Ledbetter 292017d7bd AK/FuzzyMatch: Use a first letter bonus of 15 rather than 20
This matches the value used in the original `lib_fts` implementation
of the algorithm.
2023-10-06 22:09:18 +02:00
Tim Schumacher 87bcaa6151 AK: Implement printf's "period without precision value" correctly 2023-10-06 08:21:18 +02:00
Kemal Zebari 001abbcd66 AK: Rename URLParser:parse_host() param is_not_special to is_opaque
Since the spec renamed it to make it easier to read.
2023-10-01 14:35:40 +02:00
kleines Filmröllchen 4cefb02324 AK: Use secure SipHash-4-8 for IP addresses
Routing tables formed with IP address hashes should be DoS-resistant.
2023-10-01 11:06:36 +03:30
kleines Filmröllchen 9a026fc8d5 AK: Implement SipHash as the default hash algorithm for most use cases
SipHash is highly HashDoS-resistent, initialized with a random seed at
startup (i.e. non-deterministic) and usable for security-critical use
cases with large enough parameters. We just use it because it's
reasonably secure with parameters 1-3 while having excellent properties
and not being significantly slower than before.
2023-10-01 11:06:36 +03:30
Niklas Poslovski 485ae28ba7 AK: Add support for backtraces on Haiku 2023-09-29 15:11:52 +01:00
kleines Filmröllchen 5b2496e522 AK: Make writability violation of FixedMemoryStream non-fatal
Writing to a read-only file is not a program-crashing error either, so
we just return the standard EBADFD (see write(2)) here.
2023-09-27 03:22:56 +02:00
kleines Filmröllchen bbeabe929b AK: Allow specifying writability of a FixedMemoryStream 2023-09-27 03:22:56 +02:00
kleines Filmröllchen 644d9c784d AK: Make FixedMemoryStream non-final 2023-09-27 03:22:56 +02:00
Daniel Bertalan 4d2af7c3d6 AK: Implement reverse iterators for OrderedHashTable 2023-09-24 23:36:43 +02:00
Aliaksandr Kalenik 4b06cef93a AK: Add copy assignment operator for SourceLocation 2023-09-24 14:55:32 +02:00
Hendiadyoin1 3273ef1e3f AK: Add helper to make DistinctNumeric types comparable to enums 2023-09-22 18:39:37 -06:00
Ali Mohammad Pur 1b2007cc7f AK: Use outline Function storage if alignment requirements are not met
Instead of ballooning the size of the Function object, simply place the
callable on the heap with a properly aligned address.
This brings the alignment of Function down from ridiculous sizes like 64
bytes down to a manageable 8 bytes.
2023-09-22 22:10:16 +03:30
Ali Mohammad Pur 5e0a28c947 Revert "AK: Align Function storage to __BIGGEST_ALIGNMENT__ outside…
…kernel"
This reverts commit d4d92184b3.
The alignemnt requirements imposed by this are overkill at best and
ridiculous at worst, a future commit will tackle this problem in a
different, more space-efficient way.
2023-09-22 22:10:16 +03:30
Kemal Zebari f6c52f622d AK: Number the spec step comments in URL::serialize_path() 2023-09-19 21:51:31 +01:00
kleines Filmröllchen 8bcf25561b AK: Fix MemoryStream seek from end
The seek offset is still applied positively when seeking from the end;
see the Kernel's seek implementation.
2023-09-17 17:13:52 -06:00
nipos b99e0b95c0 AK: Defined _COARSE clocks as the normal ones on Haiku 2023-09-17 13:38:12 -06:00
nipos fa4357b7ea AK: Use the Linux implementation of StackInfo() on Haiku 2023-09-17 13:38:12 -06:00
nipos 479e57582a AK: Implement fill_with_random() for Haiku 2023-09-17 13:38:12 -06:00
nipos faa5660c7b AK: Add Haiku to platform detection 2023-09-17 13:38:12 -06:00
Andrew Kaster 10d7ec2027 AK: Enable backtrace() on Android API level 33 and higher
``<execinfo.h>`` was added to bionic in Android 13 (API 33)
2023-09-15 14:18:52 -06:00
Andrew Kaster 0c5a546dca AK: Send dbgln/outln/warnln to the NDK logger on Android
The embedding application is responsible for setting the android log
tag. If it doesn't a default of "Serenity" will be used for any Lagom
code.
2023-09-15 14:18:52 -06:00
Kemal Zebari b6b4e59bf7 AK: Implement URL::serialize_path() to spec
This commit also reverts db5ad0c since code outside of the web spec
expects serialized paths to be percent decoded.

Also, there are issues trying to implement the concept "opaque
path". For now, we still use the old cannot_be_a_base_url(), but its
usage needs to be removed in favor of a has_opaque_path() as the spec
has changed since then.
2023-09-15 11:15:43 -06:00
Jelle Raaijmakers 9240233378 Revert "AK: Refill a BufferedStream when it has less than the
...requested size"

This reverts commit 13573a6c4b.

Some clients of `BufferedStream` expect a non-blocking read by
`read_some` which the commit above made impossible by potentially
performing a blocking read. For example, the following command hangs:

    pro http://ipecho.net/plain

This is caused by the HTTP job expecting to read the body of the
response which is included in the active buffer, but since the buffered
data size is less than the buffer passed into `read_some`, another
blocking read is performed before anything is returned.

By reverting this commit, all tests still pass and `pro` no longer
hangs. Note that because of another bug related to `stdout` / `stderr`
mixing and the absence of a line ending, there is no output to the
command above except a progress update.
2023-09-11 21:38:24 -04:00
Bastiaan van der Plaat 494a8cb816 AK: Add to_radians and to_degrees math functions 2023-09-10 08:38:29 +01:00
kleines Filmröllchen b432674923 LibAudio: Prevent overflows during prediction
Saturating arithmetic leads to less screwed up audio in these cases.
2023-09-09 11:23:57 -06:00
Sergey Bugaev 54265cec1c AK: Add InvokeResult 2023-09-09 11:21:15 -06:00
Sergey Bugaev 79431b32b2 AK: Add AK_OS_GNU_HURD :^)
This is defined when building on GNU/Hurd, the GNU operating system with
the Hurd as its kernel (as it was designed originally, before Linux and
GNU/Linux came to be).

Also, define the corresponding part of User-Agent.
2023-09-06 11:41:16 -06:00
Andreas Kling e4d14e1afc AK: Add FlyString::operator<=>(FlyString const&)
Same as String already has.
2023-09-06 11:29:03 -04:00
Andreas Kling 1e820385d9 AK: Add case-insensitive hashing for the new String classes
Bringing over this functionality from DeprecatedString.
2023-09-06 11:29:03 -04:00
Sergey Bugaev 88a3b4da9e AK: Add back ARCH(I386)
This now checks whether the platform is i386-based (but not x86_64).
2023-09-06 07:21:07 -06:00
Hendiadyoin1 35e3e3d483 AK: Make FixedPoint work on platforms without __int128 2023-09-06 07:17:03 -06:00
Sergey Bugaev 4825919bcf AK, LibCore: Enable misc things on glibc
program_invocation_name, pthread_getattr_np(), EXECINFO_BACKTRACE are
all glibc specifics (that other libcs may also have).
2023-09-06 07:14:35 -06:00
Sergey Bugaev 0143e5a36d AK: Enable arc4random_buf on glibc 2.36+
We have arc4random starting from 2.36, no reason not to use it :^)
2023-09-06 07:14:35 -06:00
Sergey Bugaev 3f90e9a8a0 AK: Add AK_LIBC_GLIBC
This is defined when we're compiling against the GNU C Library, whether
on Linux or on other kernels that glibc works on. More AK_LIBC_xxxx
definitions could be potentially added in the future.

Also add AK_LIBC_GLIBC_PREREQ(), which checks for a specific glibc
version.
2023-09-06 07:14:35 -06:00
Niklas Poslovski d93e916d0c AK: Use arc4random_buf() for Random on all BSDs 2023-09-05 19:36:53 -04:00
Sam Atkins f527e55046 AK: Allow case-insensitive FlyString/StringView comparison 2023-09-05 14:27:23 +02:00
Andrew Kaster 6e8f1549a3 AK+LibCore: Don't use unsupported features on Android 2023-09-03 11:38:51 +02:00
Andrew Kaster aa03f73c2e AK: Demangle symbols on assertion failure on Linux as well
While macOS backtrace(3) puts a space directly after the mangled symbol
name, some versions of glibc put a + directly after it. This new logic
accounts for both situations when trying to demangle.

Co-Authored-By: Andreas Kling <kling@serenityos.org>
2023-09-03 07:51:03 +02:00
Andrew Kaster 4641af7873 AK: Always use our assertion failure method, and add backtrace to it
On platforms that support it, enable using ``<execinfo.h>`` to get
backtrace(3) to dump a backtrace on assertion failure. This should make
debugging things like WebContent crashes in Lagom much easier.
2023-09-01 11:50:47 +02:00
Shannon Booth 50d8ef94ba AK: Port percent_encode_after_encoding to String 2023-08-31 11:02:18 +02:00
Shannon Booth cb4c279e90 AK: Percent encode URL fragments when parsed
This fixes URL fragments containing characters in the fragment encoding
set that were not being correctly percent encoded.
2023-08-31 11:02:18 +02:00
Shannon Booth e233de1e48 AK: Report validation error for URLs with invalid percent encodings
This part of the spec is mostly useful for our debugging for now, but
could eventually be hooked up so that the user can see any reported
validation errors.
2023-08-31 11:02:18 +02:00
Shannon Booth f53dfdd6ac AK: Write scheme state of URL parsing closer to spec steps
The main change here is that we now follow the spec by asserting the URL
is not special. Previously I could not find a way to enable this without
getting assertions when browsing the web - but that seems to no longer
be the case (probably from some other fixes which have since been made).
2023-08-31 11:02:18 +02:00
Shannon Booth 23e82114b4 AK: Do not consider port of 0 as a null port
This fixes an issue where if a port number of 0 was given for a non
special scheme the port number was being dropped.
2023-08-31 11:02:18 +02:00
ronak69 2caf68fd03 AK: Add binary and octal mode formatting for FixedPoint 2023-08-29 11:10:45 +02:00