[ox] Remove some unnecessary const_casts
This commit is contained in:
4
deps/ox/src/ox/fs/test/tests.cpp
vendored
4
deps/ox/src/ox/fs/test/tests.cpp
vendored
@@ -175,8 +175,8 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
|||||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||||
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
||||||
ox::FileStore32 fileStore(list, buffLen);
|
ox::FileStore32 fileStore(list, buffLen);
|
||||||
oxAssert(fileStore.write(4, const_cast<char*>(str1), str1Len, 1), "FileStore::write 1 failed.");
|
oxAssert(fileStore.write(4, str1, str1Len, 1), "FileStore::write 1 failed.");
|
||||||
oxAssert(fileStore.write(5, const_cast<char*>(str2), str2Len, 1), "FileStore::write 2 failed.");
|
oxAssert(fileStore.write(5, str2, str2Len, 1), "FileStore::write 2 failed.");
|
||||||
|
|
||||||
char str1Read[str1Len];
|
char str1Read[str1Len];
|
||||||
size_t str1ReadSize = 0;
|
size_t str1ReadSize = 0;
|
||||||
|
|||||||
25
deps/ox/src/ox/std/strops.cpp
vendored
25
deps/ox/src/ox/std/strops.cpp
vendored
@@ -7,9 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "def.hpp"
|
#include "def.hpp"
|
||||||
|
#include "span.hpp"
|
||||||
#include "strops.hpp"
|
#include "strops.hpp"
|
||||||
|
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
|
||||||
|
|
||||||
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
|
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
|
||||||
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
|
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
|
||||||
@@ -19,30 +19,25 @@ static_assert(ox::strcmp("resize", "resize") == 0, "resize == resize");
|
|||||||
static_assert(ox::strcmp("", "") == 0, "\"\" == \"\"");
|
static_assert(ox::strcmp("", "") == 0, "\"\" == \"\"");
|
||||||
|
|
||||||
static_assert([] {
|
static_assert([] {
|
||||||
auto testStr = "asdf";
|
auto constexpr testStr = ox::Span{"asdf"};
|
||||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
return ox::strchr(testStr.data(), 0, 4) == &testStr[4];
|
||||||
return ox::strchr(testStr, 0, 4) == &testStr[4];
|
|
||||||
OX_CLANG_NOWARN_END
|
|
||||||
}(), "ox::strchr 0");
|
}(), "ox::strchr 0");
|
||||||
|
|
||||||
static_assert([] {
|
static_assert([] {
|
||||||
int retval = 0;
|
auto constexpr testStr = "aaaa";
|
||||||
auto testStr = "aaaa";
|
|
||||||
// test the const and non-const versions of ox::lastIndexOf
|
// test the const and non-const versions of ox::lastIndexOf
|
||||||
retval |= !(ox::lastIndexOf(const_cast<char*>(testStr), 'a', ox::strlen(testStr)) == 3);
|
return ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3;
|
||||||
retval |= !(ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3);
|
|
||||||
return retval == 0;
|
|
||||||
}(), "ox::lastIndexOf aaaa a");
|
}(), "ox::lastIndexOf aaaa a");
|
||||||
|
|
||||||
#ifndef OX_USE_STDLIB
|
#ifndef OX_USE_STDLIB
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
std::size_t strlen(const char *str) {
|
size_t strlen(const char *str) {
|
||||||
std::size_t len = 0;
|
size_t len{};
|
||||||
for (; str[len]; len++);
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
|
while (str[len]) { ++len; }
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
|
||||||
Reference in New Issue
Block a user