--- lbbs/src/user_priv.c 2025/06/21 02:15:18 1.21 +++ lbbs/src/user_priv.c 2025/11/04 13:49:51 1.23 @@ -1,18 +1,10 @@ -/*************************************************************************** - user_priv.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * user_priv + * - basic operations of user privilege + * + * Copyright (C) 2004-2025 by Leaflet + */ #include "bbs.h" #include "common.h" @@ -35,19 +27,24 @@ inline static int search_priv(BBS_user_p { mid = (left + right) / 2; - if (sid <= p_priv->s_priv_list[mid].sid) + if (sid < p_priv->s_priv_list[mid].sid) { - right = mid; + right = mid - 1; } - else + else if (sid > p_priv->s_priv_list[mid].sid) { left = mid + 1; } + else // if (sid == p_priv->s_priv_list[mid].sid) + { + left = mid; + break; + } } *p_offset = left; - return (left == right && sid == p_priv->s_priv_list[left].sid); + return (sid == p_priv->s_priv_list[left].sid); } int setpriv(BBS_user_priv *p_priv, int sid, int priv, int is_favor) @@ -61,7 +58,7 @@ int setpriv(BBS_user_priv *p_priv, int s return 0; } - if (search_priv(p_priv, sid, &offset)) //found + if (search_priv(p_priv, sid, &offset)) // found { p_priv->s_priv_list[offset].s_priv = priv; p_priv->s_priv_list[offset].is_favor = is_favor; @@ -93,7 +90,7 @@ int getpriv(BBS_user_priv *p_priv, int s { int offset; - if (search_priv(p_priv, sid, &offset)) //found + if (search_priv(p_priv, sid, &offset)) // found { *p_is_favor = p_priv->s_priv_list[offset].is_favor; return p_priv->s_priv_list[offset].s_priv;