mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-09 03:58:34 +00:00
hv: string: fix MISRA-C violations related to break
This patch fixes the MISRA-C violations in lib/string.c * make the while loop have only one `break` Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
parent
b319e654c1
commit
2c6c383e54
@ -228,32 +228,38 @@ char *strncpy_s(char *d_arg, size_t dmax, const char *s_arg, size_t slen_arg)
|
|||||||
dest_avail = dmax;
|
dest_avail = dmax;
|
||||||
|
|
||||||
while (dest_avail > 0U) {
|
while (dest_avail > 0U) {
|
||||||
|
bool complete = false;
|
||||||
|
|
||||||
if (overlap_guard == 0U) {
|
if (overlap_guard == 0U) {
|
||||||
pr_err("%s: overlap happened.", __func__);
|
pr_err("%s: overlap happened.", __func__);
|
||||||
d--;
|
d--;
|
||||||
*d = '\0';
|
*d = '\0';
|
||||||
/* break out to return */
|
|
||||||
pret = NULL;
|
pret = NULL;
|
||||||
break;
|
/* copy complete */
|
||||||
|
complete = true;
|
||||||
|
} else {
|
||||||
|
if (slen == 0U) {
|
||||||
|
*d = '\0';
|
||||||
|
/* copy complete */
|
||||||
|
complete = true;
|
||||||
|
} else {
|
||||||
|
*d = *s;
|
||||||
|
if (*d == '\0') {
|
||||||
|
/* copy complete */
|
||||||
|
complete = true;
|
||||||
|
} else {
|
||||||
|
d++;
|
||||||
|
s++;
|
||||||
|
slen--;
|
||||||
|
dest_avail--;
|
||||||
|
overlap_guard--;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slen == 0U) {
|
if (complete) {
|
||||||
*d = '\0';
|
|
||||||
/* break out to return */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*d = *s;
|
|
||||||
if (*d == '\0') {
|
|
||||||
/* break out to return */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
d++;
|
|
||||||
s++;
|
|
||||||
slen--;
|
|
||||||
dest_avail--;
|
|
||||||
overlap_guard--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dest_avail == 0U) {
|
if (dest_avail == 0U) {
|
||||||
|
Loading…
Reference in New Issue
Block a user