From cb73d9df3258eaf59e4799c9e54d5f865e891734 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 22 Sep 2019 14:07:24 +0200 Subject: [PATCH] Fixed another issue --- src/Error.h | 20 ++++++++------ src/PermissionManager.cpp | 58 ++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/Error.h b/src/Error.h index 3cccc55..195c7a4 100644 --- a/src/Error.h +++ b/src/Error.h @@ -8,6 +8,8 @@ #include #include +#define _NDEBUG + namespace ts { namespace permission { enum PermissionType : uint16_t; @@ -174,7 +176,7 @@ namespace ts { * bits [64 - sizeof(error::type);64] => error type | Usually evaluates to [48;64] * bits [64 - sizeof(error::type) - sizeof(permission::PermissionType);64 - sizeof(error::type)] => permission id | Usually evaluates to [32;48] */ - uint64_t data; + uint64_t data = 0; /* Test for mode 1 as described before */ static_assert(sizeof(permission::PermissionType) * 8 + sizeof(error::type) * 8 <= 63); @@ -192,7 +194,7 @@ namespace ts { } inline bool is_detailed() { - return (this->data & 0x1) == 0; + return (this->data & 0x1UL) == 0; } inline detailed_command_result* release_details() { @@ -201,7 +203,7 @@ namespace ts { return result; } -#ifndef NDEBUG /* We dont need to secure that because gcc deduct us to an uint64_t and the only advantage is the mem leak test which is deactivated anyways */ +#ifndef _NDEBUG /* We dont need to secure that because gcc deduct us to an uint64_t and the only advantage is the mem leak test which is deactivated anyways */ command_result(command_result&) = delete; command_result(const command_result&) = delete; command_result(command_result&& other) : data(other.data) { @@ -209,9 +211,7 @@ namespace ts { } #endif - command_result() { - this->data = 0; - } + command_result() = default; explicit command_result(permission::PermissionType permission) { this->data = 0x01; /* the the type to 1 */ @@ -237,7 +237,7 @@ namespace ts { details_ptr->extra_properties["extra_msg"] = message; } -#ifndef NDEBUG +#ifndef _NDEBUG /* if we're not using any debug we dont have to use a deconstructor. A deconstructor prevent a direct uint64_t return as described above */ ~command_result() { if((this->data & 0x01) == 0x00) { @@ -246,8 +246,8 @@ namespace ts { } } #endif - }; + static_assert(sizeof(command_result) == 8); struct ErrorType { public: @@ -330,4 +330,6 @@ namespace ts { public: CommandResultPermissionError(permission::PermissionType error, const std::string &extraMsg = ""); }; -} \ No newline at end of file +} + +#undef _NDEBUG \ No newline at end of file diff --git a/src/PermissionManager.cpp b/src/PermissionManager.cpp index 0e9c483..2a6c095 100644 --- a/src/PermissionManager.cpp +++ b/src/PermissionManager.cpp @@ -1269,7 +1269,6 @@ void v2::PermissionManager::set_channel_permission(const PermissionType &permiss } else if(action_value == v2::PermissionUpdateType::delete_value) { permission_container->flags.value_set = false; permission_container->flags.flag_value_update = true; - permission_container->values.value = permNotGranted; /* required for the database else it does not "deletes" the value */ } if(action_grant == v2::PermissionUpdateType::set_value) { @@ -1279,7 +1278,6 @@ void v2::PermissionManager::set_channel_permission(const PermissionType &permiss } else if(action_grant == v2::PermissionUpdateType::delete_value) { permission_container->flags.grant_set = false; permission_container->flags.flag_grant_update = true; - permission_container->values.grant = permNotGranted; /* required for the database else it does not "deletes" the value */ } if(flag_skip >= 0) { @@ -1395,18 +1393,19 @@ const std::vector v2::PermissionManager::flush_db_u /* we only need an update it the permission has a DB reference or we will set the permission */ if(permission.flags.database_reference || permission.flags.permission_set()) { /* - PermissionType permission; - ChannelId channel_id; + PermissionType permission; + ChannelId channel_id; - PermissionValues values; - PermissionUpdateType update_value; - PermissionUpdateType update_grant; + PermissionValues values; + PermissionUpdateType update_value; + PermissionUpdateType update_grant; - bool flag_new: 1; + bool flag_db: 1; + bool flag_delete: 1; bool flag_skip: 1; bool flag_negate: 1; */ - result.push_back(v2::PermissionDBUpdateEntry{ + auto& entry = result.emplace_back(v2::PermissionDBUpdateEntry{ (PermissionType) (block_index * PERMISSIONS_BULK_ENTRY_COUNT + permission_index), (ChannelId) 0, @@ -1419,6 +1418,14 @@ const std::vector v2::PermissionManager::flush_db_u (bool) permission.flags.skip, (bool) permission.flags.negate }); + + /* required for the database */ + if(!permission.flags.value_set) + entry.values.value = permNotGranted; + + if(!permission.flags.grant_set) + entry.values.grant = permNotGranted; + permission.flags.database_reference = permission.flags.permission_set(); } @@ -1437,21 +1444,28 @@ const std::vector v2::PermissionManager::flush_db_u /* we only need an update it the permission has a DB reference or we will set the permission */ if(permission->flags.database_reference || permission->flags.permission_set()) { - result.push_back( - v2::PermissionDBUpdateEntry{ - permission->permission, - permission->channel_id, - permission->values, - permission->flags.flag_value_update ? (permission->flags.value_set ? PermissionUpdateType::set_value : PermissionUpdateType::delete_value) : PermissionUpdateType::do_nothing, - permission->flags.flag_grant_update ? (permission->flags.grant_set ? PermissionUpdateType::set_value : PermissionUpdateType::delete_value) : PermissionUpdateType::do_nothing, + auto& entry = result.emplace_back(v2::PermissionDBUpdateEntry{ + permission->permission, + permission->channel_id, + + permission->values, + (PermissionUpdateType) (permission->flags.flag_value_update ? (permission->flags.value_set ? PermissionUpdateType::set_value : PermissionUpdateType::delete_value) : PermissionUpdateType::do_nothing), + (PermissionUpdateType) (permission->flags.flag_grant_update ? (permission->flags.grant_set ? PermissionUpdateType::set_value : PermissionUpdateType::delete_value) : PermissionUpdateType::do_nothing), + + (bool) permission->flags.database_reference, + (bool) !permission->flags.permission_set(), /* db delete */ + (bool) permission->flags.skip, + (bool) permission->flags.negate + }); + + /* required for the database */ + if(!permission->flags.value_set) + entry.values.value = permNotGranted; + + if(!permission->flags.grant_set) + entry.values.grant = permNotGranted; - (bool) permission->flags.database_reference, - (bool) !permission->flags.permission_set(), /* db delete */ - (bool) permission->flags.skip, - (bool) permission->flags.negate - } - ); permission->flags.database_reference = permission->flags.permission_set(); }