mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibC: Remove dubious String ends_with usage
As mentioned in #917, the String destructor could potentially be clobbering the errno. Use memcpy so that we do not need String at all.
This commit is contained in:
parent
4a6605bbe5
commit
47276a09dd
Notes:
sideshowbarker
2024-07-19 10:19:13 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/47276a09dd1 Pull-request: https://github.com/SerenityOS/serenity/pull/1026
1 changed files with 4 additions and 5 deletions
|
@ -1,7 +1,6 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
@ -104,16 +103,16 @@ static inline T strtol_impl(const char* nptr, char** endptr, int base)
|
|||
return num;
|
||||
}
|
||||
|
||||
[[nodiscard]] int __generate_unique_filename(char* pattern)
|
||||
__attribute__((warn_unused_result)) int __generate_unique_filename(char* pattern)
|
||||
{
|
||||
int length = strlen(pattern);
|
||||
size_t length = strlen(pattern);
|
||||
|
||||
if (length < 6 || !String(pattern).ends_with("XXXXXX")) {
|
||||
if (length < 6 || memcmp(pattern + length - 6, "XXXXXX", 6)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int start = length - 6;
|
||||
size_t start = length - 6;
|
||||
|
||||
static constexpr char random_characters[] = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue