Message ID | 9705ea09d3dac2e569c075cd9bd7f594796b12c1.1712215939.git.federico.serafini@bugseng.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | xen: address violations of MISRA C:2012 Rule 16.3 | expand |
On 04.04.2024 09:49, Federico Serafini wrote: > 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> Reviewed-by: Jan Beulich <jbeulich@suse.com>
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;
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(-)