From 7927d87c0a6c983ceadac8e67949a5e314a05708 Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Sat, 25 Jul 2026 10:20:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=BE=AA=E7=8E=AF=E5=86=85=E5=85=88?= =?UTF-8?q?=E5=B0=86=20char=20c=20=E8=BD=AC=E4=B8=BA=20unsigned=20char=20u?= =?UTF-8?q?c=EF=BC=8C=E5=86=8D=E4=BC=A0=E5=85=A5=20std::isupper=20/=20std:?= =?UTF-8?q?:islower=20/=20std::isdigit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway/src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gateway/src/main.cpp b/gateway/src/main.cpp index 8ab814c..8f1a462 100644 --- a/gateway/src/main.cpp +++ b/gateway/src/main.cpp @@ -152,9 +152,12 @@ public: bool has_upper = false, has_lower = false, has_digit = false, has_special = false; for (char c : password) { - if (std::isupper(c)) has_upper = true; - else if (std::islower(c)) has_lower = true; - else if (std::isdigit(c)) has_digit = true; + // std::isupper 等函数参数为 int,char 为有符号且非 ASCII 时是 UB + // 必须 static_cast 后再传入(P1-2) + unsigned char uc = static_cast(c); + if (std::isupper(uc)) has_upper = true; + else if (std::islower(uc)) has_lower = true; + else if (std::isdigit(uc)) has_digit = true; else has_special = true; }