Permission: refactor getPermissionFromPassword() to return std::optional
This replaces the output parameter (which is bad API design). As a
side effect, it fixes the bad [[gnu::pure]] attribute added by commit
a636d2127
which caused optimizing compilers to miscompile calls to
that function. "Pure" functions can be assumed to have no output
arguments, so the compiler can assume the function doesn't modify
them.
Closes https://github.com/MusicPlayerDaemon/MPD/issues/1282
This commit is contained in:
@@ -58,13 +58,13 @@ handle_binary_limit(Client &client, Request args,
|
||||
CommandResult
|
||||
handle_password(Client &client, Request args, Response &r)
|
||||
{
|
||||
unsigned permission = 0;
|
||||
if (getPermissionFromPassword(args.front(), &permission) < 0) {
|
||||
const auto permission = GetPermissionFromPassword(args.front());
|
||||
if (!permission) {
|
||||
r.Error(ACK_ERROR_PASSWORD, "incorrect password");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
client.SetPermission(permission);
|
||||
client.SetPermission(*permission);
|
||||
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user