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`
Acked-by: Anthony Xu
@@ -228,33 +228,39 @@ char *strncpy_s(char *d_arg, size_t dmax, const char *s_arg, size_t slen_arg)
dest_avail = dmax;
while (dest_avail > 0U) {
+ bool complete = false;
+
if (overlap_guard == 0U) {
pr_err("%s: overlap happened.", __func__);
d--;
*d = '\0';
- /* break out to return */
pret = NULL;
- break;
- }
-
+ /* copy complete */
+ complete = true;
+ } else {
if (slen == 0U) {
*d = '\0';
- /* break out to return */
- break;
- }
-
+ /* copy complete */
+ complete = true;
+ } else {
*d = *s;
if (*d == '\0') {
- /* break out to return */
- break;
- }
-
+ /* copy complete */
+ complete = true;
+ } else {
d++;
s++;
slen--;
dest_avail--;
overlap_guard--;
}
+ }
+ }
+
+ if (complete) {
+ break;
+ }
+ }
if (dest_avail == 0U) {
pr_err("%s: dest buffer has no enough space.", __func__);
