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>
This commit is contained in:
Yonghua Huang 2018-07-04 23:14:04 +08:00 committed by lijinxia
parent b76c92bf3e
commit b332410f0c

View File

@ -27,13 +27,17 @@ long strtol_deci(const char *nptr)
* Skip white space and pick up leading +/- sign if any. * Skip white space and pick up leading +/- sign if any.
*/ */
do { do {
c = *s++; c = *s;
s++;
} while (ISSPACE(c)); } while (ISSPACE(c));
if (c == '-') { if (c == '-') {
neg = 1; neg = 1;
c = *s++; c = *s;
} else if (c == '+') s++;
c = *s++; } else if (c == '+') {
c = *s;
s++;
}
/* /*
* Compute the cutoff value between legal numbers and illegal * Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the * numbers. That is the largest legal value, divided by the
@ -54,7 +58,9 @@ long strtol_deci(const char *nptr)
cutoff = (neg != 0) ? -(uint64_t)LONG_MIN : LONG_MAX; cutoff = (neg != 0) ? -(uint64_t)LONG_MIN : LONG_MAX;
cutlim = cutoff % (uint64_t)base; cutlim = cutoff % (uint64_t)base;
cutoff /= (uint64_t)base; cutoff /= (uint64_t)base;
for (acc = 0, any = 0;; c = *s++) { acc = 0;
any = 0;
do {
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
c -= '0'; c -= '0';
else else
@ -68,7 +74,11 @@ long strtol_deci(const char *nptr)
acc *= base; acc *= base;
acc += c; acc += c;
} }
}
c = *s;
s++;
} while (true);
if (any < 0) if (any < 0)
acc = (neg != 0) ? LONG_MIN : LONG_MAX; acc = (neg != 0) ? LONG_MIN : LONG_MAX;
else if (neg != 0) else if (neg != 0)
@ -101,7 +111,9 @@ uint64_t strtoul_hex(const char *nptr)
cutoff = (uint64_t)ULONG_MAX / (uint64_t)base; cutoff = (uint64_t)ULONG_MAX / (uint64_t)base;
cutlim = (uint64_t)ULONG_MAX % (uint64_t)base; cutlim = (uint64_t)ULONG_MAX % (uint64_t)base;
for (acc = 0, any = 0;; c = *s++) { acc = 0;
any = 0;
do {
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9')
c -= '0'; c -= '0';
else if (c >= 'A' && c <= 'F') else if (c >= 'A' && c <= 'F')
@ -119,7 +131,10 @@ uint64_t strtoul_hex(const char *nptr)
acc *= base; acc *= base;
acc += c; acc += c;
} }
}
c = *s;
s++;
} while (true);
if (any <= 0) if (any <= 0)
acc = ULONG_MAX; acc = ULONG_MAX;