提交 9e2e59c8 编写于 作者: Z zzulilyw

Fix irregular code writing

Issue: https://gitee.com/openharmony/third_party_musl/issues/I7OSP8

test: libc-test
Signed-off-by: Nzzulilyw <liuyawei10@huawei.com>
上级 9eab551a
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
#define RR_PTR 12 #define RR_PTR 12
#define BREAK 0 #define BREAK 0
#define CONTINUE 1 #define CONTINUE 1
#define FIXED_HOSTS_MAX_LENGTH 2
#define FIXED_HOSTS_STR_MAX_LENGTH 23
extern char fixed_hosts[][23]; extern char fixed_hosts[FIXED_HOSTS_MAX_LENGTH][FIXED_HOSTS_STR_MAX_LENGTH];
static char *itoa(char *p, unsigned x) { static char *itoa(char *p, unsigned x) {
p += 3*sizeof(int); p += 3*sizeof(int);
...@@ -51,7 +53,7 @@ static inline int get_hosts_str(char *line, int length, FILE *f, int *i) ...@@ -51,7 +53,7 @@ static inline int get_hosts_str(char *line, int length, FILE *f, int *i)
if (f) { if (f) {
return fgets(line, sizeof line, f); return fgets(line, sizeof line, f);
} }
if (*i < 2) { if (*i < FIXED_HOSTS_MAX_LENGTH) {
memcpy(line, fixed_hosts[*i], strlen(fixed_hosts[*i])); memcpy(line, fixed_hosts[*i], strlen(fixed_hosts[*i]));
(*i)++; (*i)++;
return 1; return 1;
...@@ -71,7 +73,7 @@ static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, i ...@@ -71,7 +73,7 @@ static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, i
a = atmp; a = atmp;
} }
int i = 0; int i = 0;
while (i < 2 && get_hosts_str(line, sizeof line, f, &i)) { while (i < FIXED_HOSTS_MAX_LENGTH && get_hosts_str(line, sizeof line, f, &i)) {
if ((p=strchr(line, '#'))) *p++='\n', *p=0; if ((p=strchr(line, '#'))) *p++='\n', *p=0;
for (p=line; *p && !isspace(*p); p++); for (p=line; *p && !isspace(*p); p++);
......
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
#if OHOS_PERMISSION_INTERNET #if OHOS_PERMISSION_INTERNET
uint8_t is_allow_internet(void); uint8_t is_allow_internet(void);
#endif #endif
#define FIXED_HOSTS_MAX_LENGTH 2
#define FIXED_HOSTS_STR_MAX_LENGTH 23
char fixed_hosts[][23] = { char fixed_hosts[][FIXED_HOSTS_STR_MAX_LENGTH] = {
"127.0.0.1 localhost\r\n\0", "127.0.0.1 localhost\r\n\0",
"::1 ip6-localhost\r\n\0" "::1 ip6-localhost\r\n\0"
}; };
...@@ -61,7 +63,7 @@ static inline int get_hosts_str(char *line, int length, FILE *f, int *i) ...@@ -61,7 +63,7 @@ static inline int get_hosts_str(char *line, int length, FILE *f, int *i)
if (f) { if (f) {
return fgets(line, sizeof line, f); return fgets(line, sizeof line, f);
} }
if (*i < 2) { if (*i < FIXED_HOSTS_MAX_LENGTH) {
memcpy(line, fixed_hosts[*i], strlen(fixed_hosts[*i])); memcpy(line, fixed_hosts[*i], strlen(fixed_hosts[*i]));
(*i)++; (*i)++;
return 1; return 1;
...@@ -77,7 +79,7 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati ...@@ -77,7 +79,7 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati
unsigned char _buf[1032]; unsigned char _buf[1032];
FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
int i = 0; int i = 0;
while (i < 2 && get_hosts_str(line, sizeof line, f, &i) && cnt < MAXADDRS) { while (i < FIXED_HOSTS_MAX_LENGTH && get_hosts_str(line, sizeof line, f, &i) && cnt < MAXADDRS) {
char *p, *z; char *p, *z;
if ((p=strchr(line, '#'))) *p++='\n', *p=0; if ((p=strchr(line, '#'))) *p++='\n', *p=0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册