From 9c424ab741218238205e8d1f2644a3912fda250a Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Sun, 30 May 2021 12:47:50 +0200 Subject: Codechange: [ContentInfo] Use StringList for tags instead of custom allocations --- src/network/core/config.h | 1 + src/network/core/tcp_content.cpp | 6 ++---- src/network/core/tcp_content_type.h | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/network/core') diff --git a/src/network/core/config.h b/src/network/core/config.h index cacc907fa..ce614188d 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -65,6 +65,7 @@ static const uint NETWORK_CLIENT_NAME_LENGTH = 25; ///< The maxim static const uint NETWORK_RCONCOMMAND_LENGTH = 500; ///< The maximum length of a rconsole command, in bytes including '\0' static const uint NETWORK_GAMESCRIPT_JSON_LENGTH = COMPAT_MTU-3; ///< The maximum length of a gamescript json string, in bytes including '\0'. Must not be longer than COMPAT_MTU including header (3 bytes) static const uint NETWORK_CHAT_LENGTH = 900; ///< The maximum length of a chat message, in bytes including '\0' +static const uint NETWORK_CONTENT_TAG_LENGTH = 32; ///< The maximum length of a content's tag, in bytes including '\0'. static const uint NETWORK_GRF_NAME_LENGTH = 80; ///< Maximum length of the name of a GRF diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp index ddea9fd5e..041e932e4 100644 --- a/src/network/core/tcp_content.cpp +++ b/src/network/core/tcp_content.cpp @@ -25,7 +25,7 @@ ContentInfo::ContentInfo() : /* Temporary... will be removed later in the PR. */ type((ContentType)0), id((ContentID)0), filesize(0), filename(""), name(""), version(""), url(""), description(""), unique_id(0), md5sum(""), dependency_count(0), dependencies(nullptr), - tag_count(0), tags(nullptr), state((State)0), upgrade(false) + state((State)0), upgrade(false) { } @@ -33,7 +33,6 @@ ContentInfo::ContentInfo() ContentInfo::~ContentInfo() { free(this->dependencies); - free(this->tags); } /** @@ -44,10 +43,9 @@ void ContentInfo::TransferFrom(ContentInfo *other) { if (other != this) { free(this->dependencies); - free(this->tags); *this = *other; other->dependencies = nullptr; - other->tags = nullptr; + other->tags.clear(); } } diff --git a/src/network/core/tcp_content_type.h b/src/network/core/tcp_content_type.h index 739cf1379..93367746d 100644 --- a/src/network/core/tcp_content_type.h +++ b/src/network/core/tcp_content_type.h @@ -69,8 +69,7 @@ struct ContentInfo { byte md5sum[16]; ///< The MD5 checksum uint8 dependency_count; ///< Number of dependencies ContentID *dependencies; ///< Malloced array of dependencies (unique server side ids) - uint8 tag_count; ///< Number of tags - char (*tags)[32]; ///< Malloced array of tags (strings) + StringList tags; ///< Tags associated with the content State state; ///< Whether the content info is selected (for download) bool upgrade; ///< This item is an upgrade -- cgit v1.2.3-70-g09d2