xen/string: Fix strcmp() and strncmp()
PATCH 1/1 xen/string: Fix strcmp() and strncmp()
The C spec requires that the comarison be done in terms of unsigned char.
The code style in this file is terrible, but does claim to be Xen BSD style, so fix up these functions while rewriting them.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/common/string.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-)
xen/common/string.c +18 -13
@@ -119,14 +119,16 @@ EXPORT_SYMBOL(strlcat);*/ int (strcmp)(const char *cs,const char *ct) { - registersigned char __res; +for ( ; ; ) + { +unsigned char c1 = *cs++, c2 = *ct++; -while (1 ) { -if ((__res = *cs - *ct++) !=0 || !*cs++) -break ; - } +if ( c1 != c2 ) +return c1 - c2; -return __res; +if ( c1 =='\0' ) +return 0 ; + } }#endif
@@ -139,15 +141,18 @@ int (strcmp)(const char *cs, const char *ct)*/ int (strncmp)(const char *cs,const char *ct,size_t count) { - registersigned char __res =0 ; +for ( ; count; count-- ) + { +unsigned char c1 = *cs++, c2 = *ct++; -while (count) { -if ((__res = *cs - *ct++) !=0 || !*cs++) -break ; - count--; - } +if ( c1 != c2 ) +return c1 - c2; + +if ( c1 =='\0' ) +break ; + } -return __res; +return 0 ; }#endif
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 04.01.19 at 18:00, <[email protected]> wrote:
The C spec requires that the comarison be done in terms of unsigned char.
The code style in this file is terrible, but does claim to be Xen BSD style, so fix up these functions while rewriting them.
Where have you found this claim? The comment at the bottom has
* c-file-style: "BSD"
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
i.e. clearly not Xen style.
xen/common/string.c int (strcmp)(const char *cs, const char *ct) · line 144
Quoted 6 lines
xen/common/string.c +1
-1@@ -139,15 +141,18 @@ int (strcmp)(const char *cs, const char *ct)*/ int (strncmp)(const char *cs,const char *ct,size_t count) { - registersigned char __res =0 ; +for ( ; count; count-- )
Odd loop heading when "while (count--)" would do, since "count" isn't used elsewhere.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel