Skip to content

Commit b332410

Browse files
yonghuahlijinxia
authored andcommitted
HV: Fix coding style violation of MISRA in string.c
- update 'strtol_deci()' & 'strtoul_hex()' Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent b76c92b commit b332410

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

hypervisor/lib/string.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ long strtol_deci(const char *nptr)
2727
* Skip white space and pick up leading +/- sign if any.
2828
*/
2929
do {
30-
c = *s++;
30+
c = *s;
31+
s++;
3132
} while (ISSPACE(c));
3233
if (c == '-') {
3334
neg = 1;
34-
c = *s++;
35-
} else if (c == '+')
36-
c = *s++;
35+
c = *s;
36+
s++;
37+
} else if (c == '+') {
38+
c = *s;
39+
s++;
40+
}
3741
/*
3842
* Compute the cutoff value between legal numbers and illegal
3943
* numbers. That is the largest legal value, divided by the
@@ -54,7 +58,9 @@ long strtol_deci(const char *nptr)
5458
cutoff = (neg != 0) ? -(uint64_t)LONG_MIN : LONG_MAX;
5559
cutlim = cutoff % (uint64_t)base;
5660
cutoff /= (uint64_t)base;
57-
for (acc = 0, any = 0;; c = *s++) {
61+
acc = 0;
62+
any = 0;
63+
do {
5864
if (c >= '0' && c <= '9')
5965
c -= '0';
6066
else
@@ -68,7 +74,11 @@ long strtol_deci(const char *nptr)
6874
acc *= base;
6975
acc += c;
7076
}
71-
}
77+
78+
c = *s;
79+
s++;
80+
} while (true);
81+
7282
if (any < 0)
7383
acc = (neg != 0) ? LONG_MIN : LONG_MAX;
7484
else if (neg != 0)
@@ -101,7 +111,9 @@ uint64_t strtoul_hex(const char *nptr)
101111

102112
cutoff = (uint64_t)ULONG_MAX / (uint64_t)base;
103113
cutlim = (uint64_t)ULONG_MAX % (uint64_t)base;
104-
for (acc = 0, any = 0;; c = *s++) {
114+
acc = 0;
115+
any = 0;
116+
do {
105117
if (c >= '0' && c <= '9')
106118
c -= '0';
107119
else if (c >= 'A' && c <= 'F')
@@ -119,7 +131,10 @@ uint64_t strtoul_hex(const char *nptr)
119131
acc *= base;
120132
acc += c;
121133
}
122-
}
134+
135+
c = *s;
136+
s++;
137+
} while (true);
123138

124139
if (any <= 0)
125140
acc = ULONG_MAX;

0 commit comments

Comments
 (0)