refactor: Use std::size instead of sizeof/sizeof (#1819)
## Summary Simplify code calculating compile-time array sizes with `sizeof(array)/sizeof(element)` to use `std::size`. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**PARTIALLY**_
This commit is contained in:
@@ -22,8 +22,7 @@
|
||||
namespace {
|
||||
// Folders/files to hide from the web interface file browser
|
||||
// Note: Items starting with "." are automatically hidden
|
||||
const char* HIDDEN_ITEMS[] = {"System Volume Information", "XTCache"};
|
||||
constexpr size_t HIDDEN_ITEMS_COUNT = sizeof(HIDDEN_ITEMS) / sizeof(HIDDEN_ITEMS[0]);
|
||||
constexpr const char* HIDDEN_ITEMS[] = {"System Volume Information", "XTCache"};
|
||||
constexpr uint16_t UDP_PORTS[] = {54982, 48123, 39001, 44044, 59678};
|
||||
constexpr uint16_t LOCAL_UDP_PORT = 8134;
|
||||
|
||||
@@ -75,8 +74,8 @@ bool isProtectedItemName(const String& name) {
|
||||
if (name.startsWith(".")) {
|
||||
return true;
|
||||
}
|
||||
for (size_t i = 0; i < HIDDEN_ITEMS_COUNT; i++) {
|
||||
if (name.equals(HIDDEN_ITEMS[i])) {
|
||||
for (const auto* item : HIDDEN_ITEMS) {
|
||||
if (name.equals(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -389,8 +388,8 @@ void CrossPointWebServer::scanFiles(const char* path, const std::function<void(F
|
||||
|
||||
// Check against explicitly hidden items list
|
||||
if (!shouldHide) {
|
||||
for (size_t i = 0; i < HIDDEN_ITEMS_COUNT; i++) {
|
||||
if (fileName.equals(HIDDEN_ITEMS[i])) {
|
||||
for (const auto* item : HIDDEN_ITEMS) {
|
||||
if (fileName.equals(item)) {
|
||||
shouldHide = true;
|
||||
break;
|
||||
}
|
||||
@@ -497,8 +496,8 @@ void CrossPointWebServer::handleDownload() const {
|
||||
server->send(403, "text/plain", "Cannot access system files");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < HIDDEN_ITEMS_COUNT; i++) {
|
||||
if (itemName.equals(HIDDEN_ITEMS[i])) {
|
||||
for (const auto* item : HIDDEN_ITEMS) {
|
||||
if (itemName.equals(item)) {
|
||||
server->send(403, "text/plain", "Cannot access protected items");
|
||||
return;
|
||||
}
|
||||
@@ -1033,8 +1032,8 @@ void CrossPointWebServer::handleDelete() const {
|
||||
|
||||
// Check against explicitly protected items
|
||||
bool isProtected = false;
|
||||
for (size_t i = 0; i < HIDDEN_ITEMS_COUNT; i++) {
|
||||
if (itemName.equals(HIDDEN_ITEMS[i])) {
|
||||
for (const auto* item : HIDDEN_ITEMS) {
|
||||
if (itemName.equals(item)) {
|
||||
isProtected = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user