MISRA C:2012 Rule 16.3 states: "An unconditional `break' statement
shall terminate every switch-clause".
In order to meet the requirements to deviate the rule:
1) refactor the for loop to make the switch-clause ending with a
return statement (note that adding a break at the end of the
switch-clause would result in a violation of Rule 2.1
"A project shall not contain unreachable code");
2) add pseudo-keyword fallthrough.
No functional change.
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
---
Changes in v2:
- improved commit message.
---
xen/common/vsprintf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index c49631c0a4..612751c90f 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -377,7 +377,7 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr,
str = number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD);
if ( ++i == field_width )
- return str;
+ break;
if ( sep )
{
@@ -386,6 +386,8 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr,
++str;
}
}
+
+ return str;
}
case 'p': /* PCI SBDF. */
@@ -619,6 +621,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
case 'X':
flags |= LARGE;
+ fallthrough;
case 'x':
base = 16;
break;
@@ -626,6 +629,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
case 'd':
case 'i':
flags |= SIGN;
+ fallthrough;
case 'u':
break;
--
2.34.1
shall terminate every switch-clause".
In order to meet the requirements to deviate the rule:
1) refactor the for loop to make the switch-clause ending with a
return statement (note that adding a break at the end of the
switch-clause would result in a violation of Rule 2.1
"A project shall not contain unreachable code");
2) add pseudo-keyword fallthrough.
No functional change.
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
---
Changes in v2:
- improved commit message.
---
xen/common/vsprintf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index c49631c0a4..612751c90f 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -377,7 +377,7 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr,
str = number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD);
if ( ++i == field_width )
- return str;
+ break;
if ( sep )
{
@@ -386,6 +386,8 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr,
++str;
}
}
+
+ return str;
}
case 'p': /* PCI SBDF. */
@@ -619,6 +621,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
case 'X':
flags |= LARGE;
+ fallthrough;
case 'x':
base = 16;
break;
@@ -626,6 +629,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
case 'd':
case 'i':
flags |= SIGN;
+ fallthrough;
case 'u':
break;
--
2.34.1