Skip to content

Commit 23b80cf

Browse files
committed
Optimize code
1 parent 3a5260c commit 23b80cf

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

format.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
clang-format -i src/php/*.cc

src/php/zklib.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ struct ACL_vector *convert_array_to_acl(Array *param_array) {
135135
return nullptr;
136136
}
137137
std::string std_scheme = scheme.toStdString();
138-
char *scheme_buf = (char *) emalloc(std_scheme.length() + 1);
139-
bzero(scheme_buf, strlen(scheme_buf) + 1);
140-
strcpy(scheme_buf, std_scheme.c_str());
141-
create_acl.id.scheme = scheme_buf;
138+
create_acl.id.scheme = estrndup(std_scheme.c_str(), std_scheme.length());
142139
Variant acl_struct_id = acl_array.get("id");
143140
if (scheme == nullptr) {
144141
return nullptr;
@@ -147,10 +144,7 @@ struct ACL_vector *convert_array_to_acl(Array *param_array) {
147144
return nullptr;
148145
}
149146
std::string std_acl_struct_id = acl_struct_id.toStdString();
150-
char *acl_struct_id_buf = (char *) emalloc(std_acl_struct_id.length() + 1);
151-
bzero(acl_struct_id_buf, (std_acl_struct_id.length()) + 1);
152-
strcpy(acl_struct_id_buf, std_acl_struct_id.c_str());
153-
create_acl.id.id = acl_struct_id_buf;
147+
create_acl.id.id = estrndup(std_acl_struct_id.c_str(), std_acl_struct_id.length());
154148

155149
//将结构体装入ACL
156150
acl_collect[i] = create_acl;

0 commit comments

Comments
 (0)