mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-17 01:54:22 +00:00
libc: memset: Fix MISRA issues
MISRA complained about "0"s not being followed by an "U" (please note my protest about this!) and about values not being explicitly compared to 0 (fair enough). Also use explicit pointer types. Fix those issues to make the CI happy. Change-Id: I4d11e49c14f16223a71c78b0fc3e68ba9a1382d3 Signed-off-by: Andre Przywara <andre.przywara@arm.com>
This commit is contained in:
parent
0125b42e95
commit
005415a39a
1 changed files with 14 additions and 11 deletions
|
@ -10,19 +10,20 @@
|
|||
|
||||
void *memset(void *dst, int val, size_t count)
|
||||
{
|
||||
char *ptr = dst;
|
||||
uint8_t *ptr = dst;
|
||||
uint64_t *ptr64;
|
||||
uint64_t fill = (unsigned char)val;
|
||||
|
||||
/* Simplify code below by making sure we write at least one byte. */
|
||||
if (count == 0) {
|
||||
if (count == 0U) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* Handle the first part, until the pointer becomes 64-bit aligned. */
|
||||
while (((uintptr_t)ptr & 7)) {
|
||||
*ptr++ = val;
|
||||
if (--count == 0) {
|
||||
while (((uintptr_t)ptr & 7U) != 0U) {
|
||||
*ptr = (uint8_t)val;
|
||||
ptr++;
|
||||
if (--count == 0U) {
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
@ -33,15 +34,17 @@ void *memset(void *dst, int val, size_t count)
|
|||
fill |= fill << 32;
|
||||
|
||||
/* Use 64-bit writes for as long as possible. */
|
||||
ptr64 = (void *)ptr;
|
||||
for (; count >= 8; count -= 8) {
|
||||
*ptr64++ = fill;
|
||||
ptr64 = (uint64_t *)ptr;
|
||||
for (; count >= 8U; count -= 8) {
|
||||
*ptr64 = fill;
|
||||
ptr64++;
|
||||
}
|
||||
|
||||
/* Handle the remaining part byte-per-byte. */
|
||||
ptr = (void *)ptr64;
|
||||
while (count--) {
|
||||
*ptr++ = val;
|
||||
ptr = (uint8_t *)ptr64;
|
||||
while (count-- > 0U) {
|
||||
*ptr = (uint8_t)val;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return dst;
|
||||
|
|
Loading…
Add table
Reference in a new issue