1 Star 0 Fork 10

jinlun/dim

forked from src-openEuler/dim 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Add-warpper-for-strncmp-and-strncpy.patch 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
jinlun 提交于 2024-04-16 10:12 . backport some patches
From f41760b3595c893ac0d3f0238401a2aae94224a7 Mon Sep 17 00:00:00 2001
From: Huaxin Lu <luhuaxin1@huawei.com>
Date: Tue, 20 Feb 2024 10:58:12 +0800
Subject: [PATCH 22/26] Add warpper for strncmp and strncpy
---
src/common/dim_baseline.c | 2 +-
src/common/dim_safe_func.h | 8 ++++++++
src/core/policy/dim_core_policy_complex.c | 2 +-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/common/dim_baseline.c b/src/common/dim_baseline.c
index e79458d..3fae1f9 100644
--- a/src/common/dim_baseline.c
+++ b/src/common/dim_baseline.c
@@ -106,7 +106,7 @@ int dim_baseline_add(struct dim_baseline_tree *root, const char *name,
if (ret < 0)
goto err;
- strncpy((char *)baseline->name, name, buf_len - 1);
+ dim_strncpy((char *)baseline->name, name, buf_len - 1);
((char *)baseline->name)[buf_len - 1] = '\0';
write_lock(&root->lock);
diff --git a/src/common/dim_safe_func.h b/src/common/dim_safe_func.h
index 3e97f4e..15c716c 100644
--- a/src/common/dim_safe_func.h
+++ b/src/common/dim_safe_func.h
@@ -132,4 +132,12 @@ static inline int dim_strncmp(const char *cs, const char *ct, size_t count)
return strncmp(cs, ct, count);
}
+static inline char *dim_strncpy(char *dest, const char *src, size_t count)
+{
+ if (dest == NULL || src == NULL)
+ return NULL;
+
+ return strncpy(dest, src, count);
+}
+
#endif
\ No newline at end of file
diff --git a/src/core/policy/dim_core_policy_complex.c b/src/core/policy/dim_core_policy_complex.c
index 18a9e58..8c02227 100644
--- a/src/core/policy/dim_core_policy_complex.c
+++ b/src/core/policy/dim_core_policy_complex.c
@@ -63,7 +63,7 @@ static int policy_get_key(const char *s, const char **val)
for (; i < DIM_POLICY_KEY_LAST; i++) {
len = strlen(dim_policy_key_str[i]);
- if (strncmp(s, dim_policy_key_str[i], len) == 0) {
+ if (dim_strncmp(s, dim_policy_key_str[i], len) == 0) {
*val = s + len;
return i;
}
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jinlun123123/dim.git
git@gitee.com:jinlun123123/dim.git
jinlun123123
dim
dim
master

搜索帮助