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:
Shannon Booth 2020-01-05 17:25:52 +13:00 committed by Andreas Kling
parent 4a6605bbe5
commit 47276a09dd
Notes: sideshowbarker 2024-07-19 10:19:13 +09:00

View file

@ -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";