From b6314b4c4b48305e56b2ea5c9aaa1ba008780955 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 6 May 2024 15:21:42 +0200 Subject: [PATCH] lib/nfs/Base: use std::array --- src/lib/nfs/Base.cxx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lib/nfs/Base.cxx b/src/lib/nfs/Base.cxx index 9dc96440f..18728ccc8 100644 --- a/src/lib/nfs/Base.cxx +++ b/src/lib/nfs/Base.cxx @@ -3,12 +3,13 @@ #include "Base.hxx" +#include #include #include -static char nfs_base_server[64]; -static char nfs_base_export_name[256]; +static std::array nfs_base_server; +static std::array nfs_base_export_name; static size_t nfs_base_export_name_length; void @@ -20,12 +21,12 @@ nfs_set_base(const char *server, const char *export_name) noexcept const size_t server_length = strlen(server); const size_t export_name_length = strlen(export_name); - if (server_length >= sizeof(nfs_base_server) || - export_name_length > sizeof(nfs_base_export_name)) + if (server_length >= nfs_base_server.size() || + export_name_length > nfs_base_export_name.size()) return; - memcpy(nfs_base_server, server, server_length + 1); - memcpy(nfs_base_export_name, export_name, export_name_length); + memcpy(nfs_base_server.data(), server, server_length + 1); + memcpy(nfs_base_export_name.data(), export_name, export_name_length); nfs_base_export_name_length = export_name_length; } @@ -35,9 +36,9 @@ nfs_check_base(const char *server, const char *path) noexcept assert(server != nullptr); assert(path != nullptr); - return strcmp(nfs_base_server, server) == 0 && - memcmp(nfs_base_export_name, path, - nfs_base_export_name_length) == 0 && + return strcmp(nfs_base_server.data(), server) == 0 && + memcmp(nfs_base_export_name.data(), path, + nfs_base_export_name_length) == 0 && (path[nfs_base_export_name_length] == 0 || path[nfs_base_export_name_length] == '/') ? path + nfs_base_export_name_length