mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
lib: obey to Misra rule 11.8 where possible
Casting away const-ness (or volatile-ness) is never a good idea, but some library functions (e.g. strchr()) require doing so. Where not required, remove / replace respective casts. While there convert touched functions to Xen style. No functional change intended. Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
This commit is contained in:
1 parent
fce27a1fd0
commit
d4d8d3bfba
4 files changed
+39
-34
No files matched your search
+5
-4
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
void *(memcpy)(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *tmp = (char *) dest, *s = (char *) src;
|
||||
char *tmp = dest;
|
||||
const char *s = src;
|
||||
|
||||
while (n--)
|
||||
*tmp++ = *s++;
|
||||
while ( n-- )
|
||||
*tmp++ = *s++;
|
||||
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+17
-13
@@ -14,21 +14,25 @@
|
||||
*/
|
||||
void *(memmove)(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *tmp, *s;
|
||||
char *tmp;
|
||||
const char *s;
|
||||
|
||||
if (dest <= src) {
|
||||
tmp = (char *) dest;
|
||||
s = (char *) src;
|
||||
while (n--)
|
||||
*tmp++ = *s++;
|
||||
} else {
|
||||
tmp = (char *) dest + n;
|
||||
s = (char *) src + n;
|
||||
while (n--)
|
||||
*--tmp = *--s;
|
||||
}
|
||||
if ( dest <= src )
|
||||
{
|
||||
tmp = dest;
|
||||
s = src;
|
||||
while ( n-- )
|
||||
*tmp++ = *s++;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = dest + n;
|
||||
s = src + n;
|
||||
while ( n-- )
|
||||
*--tmp = *--s;
|
||||
}
|
||||
|
||||
return dest;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+7
-8
@@ -11,16 +11,15 @@
|
||||
*/
|
||||
int (strcmp)(const char *cs, const char *ct)
|
||||
{
|
||||
unsigned char *csu = (unsigned char *)cs;
|
||||
unsigned char *ctu = (unsigned char *)ct;
|
||||
int res;
|
||||
const unsigned char *csu = (const void *)cs;
|
||||
const unsigned char *ctu = (const void *)ct;
|
||||
int res;
|
||||
|
||||
while (1) {
|
||||
if ((res = *csu - *ctu++) != 0 || !*csu++)
|
||||
break;
|
||||
}
|
||||
for ( ; ; )
|
||||
if ( (res = *csu - *ctu++) != 0 || !*csu++ )
|
||||
break;
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+10
-9
@@ -12,17 +12,18 @@
|
||||
*/
|
||||
int (strncmp)(const char *cs, const char *ct, size_t count)
|
||||
{
|
||||
unsigned char *csu = (unsigned char *)cs;
|
||||
unsigned char *ctu = (unsigned char *)ct;
|
||||
int res = 0;
|
||||
const unsigned char *csu = (const void *)cs;
|
||||
const unsigned char *ctu = (const void *)ct;
|
||||
int res = 0;
|
||||
|
||||
while (count) {
|
||||
if ((res = *csu - *ctu++) != 0 || !*csu++)
|
||||
break;
|
||||
count--;
|
||||
}
|
||||
while ( count )
|
||||
{
|
||||
if ( (res = *csu - *ctu++) != 0 || !*csu++ )
|
||||
break;
|
||||
count--;
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||