4 Star 0 Fork 1

src-oepkgs/xen

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xen.git-ae417706870333bb52ebcf33c527809cdd2d7265.patch 2.85 KB
一键复制 编辑 原始数据 按行查看 历史
chen-jan 提交于 2022-11-05 16:30 . Package Init
From ae417706870333bb52ebcf33c527809cdd2d7265 Mon Sep 17 00:00:00 2001
From: Andrew Cooper <andrew.cooper3@citrix.com>
Date: Tue, 12 Jul 2022 11:25:40 +0200
Subject: [PATCH] xen/cmdline: Extend parse_boolean() to signal a name match
This will help parsing a sub-option which has boolean and non-boolean options
available.
First, rework 'int val' into 'bool has_neg_prefix'. This inverts it's value,
but the resulting logic is far easier to follow.
Second, reject anything of the form 'no-$FOO=' which excludes ambiguous
constructs such as 'no-$foo=yes' which have never been valid.
This just leaves the case where everything is otherwise fine, but parse_bool()
can't interpret the provided string.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: 382326cac528dd1eb0d04efd5c05363c453e29f4
master date: 2022-07-11 15:21:35 +0100
---
xen/common/kernel.c | 20 ++++++++++++++++----
xen/include/xen/lib.h | 3 ++-
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 7a345ae45e..daf9652665 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -272,9 +272,9 @@ int parse_bool(const char *s, const char *e)
int parse_boolean(const char *name, const char *s, const char *e)
{
size_t slen, nlen;
- int val = !!strncmp(s, "no-", 3);
+ bool has_neg_prefix = !strncmp(s, "no-", 3);
- if ( !val )
+ if ( has_neg_prefix )
s += 3;
slen = e ? ({ ASSERT(e >= s); e - s; }) : strlen(s);
@@ -286,11 +286,23 @@ int parse_boolean(const char *name, const char *s, const char *e)
/* Exact, unadorned name? Result depends on the 'no-' prefix. */
if ( slen == nlen )
- return val;
+ return !has_neg_prefix;
+
+ /* Inexact match with a 'no-' prefix? Not valid. */
+ if ( has_neg_prefix )
+ return -1;
/* =$SOMETHING? Defer to the regular boolean parsing. */
if ( s[nlen] == '=' )
- return parse_bool(&s[nlen + 1], e);
+ {
+ int b = parse_bool(&s[nlen + 1], e);
+
+ if ( b >= 0 )
+ return b;
+
+ /* Not a boolean, but the name matched. Signal specially. */
+ return -2;
+ }
/* Unrecognised. Give up. */
return -1;
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 1198c7c0b2..be74981351 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -80,7 +80,8 @@ int parse_bool(const char *s, const char *e);
/**
* Given a specific name, parses a string of the form:
* [no-]$NAME[=...]
- * returning 0 or 1 for a recognised boolean, or -1 for an error.
+ * returning 0 or 1 for a recognised boolean. Returns -1 for general errors,
+ * and -2 for "not a boolean, but $NAME= matches".
*/
int parse_boolean(const char *name, const char *s, const char *e);
--
2.30.2
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-oepkgs/xen.git
git@gitee.com:src-oepkgs/xen.git
src-oepkgs
xen
xen
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385