Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Arm Trusted Firmware
Commits
b852f2c3
Commit
b852f2c3
authored
Feb 24, 2021
by
Joanna Farley
Committed by
TrustedFirmware Code Review
Feb 24, 2021
Browse files
Merge "libc: memset: Fix MISRA issues" into integration
parents
0125b42e
005415a3
Changes
1
Show whitespace changes
Inline
Side-by-side
lib/libc/memset.c
View file @
b852f2c3
...
@@ -10,19 +10,20 @@
...
@@ -10,19 +10,20 @@
void
*
memset
(
void
*
dst
,
int
val
,
size_t
count
)
void
*
memset
(
void
*
dst
,
int
val
,
size_t
count
)
{
{
char
*
ptr
=
dst
;
uint8_t
*
ptr
=
dst
;
uint64_t
*
ptr64
;
uint64_t
*
ptr64
;
uint64_t
fill
=
(
unsigned
char
)
val
;
uint64_t
fill
=
(
unsigned
char
)
val
;
/* Simplify code below by making sure we write at least one byte. */
/* Simplify code below by making sure we write at least one byte. */
if
(
count
==
0
)
{
if
(
count
==
0
U
)
{
return
dst
;
return
dst
;
}
}
/* Handle the first part, until the pointer becomes 64-bit aligned. */
/* Handle the first part, until the pointer becomes 64-bit aligned. */
while
(((
uintptr_t
)
ptr
&
7
))
{
while
(((
uintptr_t
)
ptr
&
7U
)
!=
0U
)
{
*
ptr
++
=
val
;
*
ptr
=
(
uint8_t
)
val
;
if
(
--
count
==
0
)
{
ptr
++
;
if
(
--
count
==
0U
)
{
return
dst
;
return
dst
;
}
}
}
}
...
@@ -33,15 +34,17 @@ void *memset(void *dst, int val, size_t count)
...
@@ -33,15 +34,17 @@ void *memset(void *dst, int val, size_t count)
fill
|=
fill
<<
32
;
fill
|=
fill
<<
32
;
/* Use 64-bit writes for as long as possible. */
/* Use 64-bit writes for as long as possible. */
ptr64
=
(
void
*
)
ptr
;
ptr64
=
(
uint64_t
*
)
ptr
;
for
(;
count
>=
8
;
count
-=
8
)
{
for
(;
count
>=
8U
;
count
-=
8
)
{
*
ptr64
++
=
fill
;
*
ptr64
=
fill
;
ptr64
++
;
}
}
/* Handle the remaining part byte-per-byte. */
/* Handle the remaining part byte-per-byte. */
ptr
=
(
void
*
)
ptr64
;
ptr
=
(
uint8_t
*
)
ptr64
;
while
(
count
--
)
{
while
(
count
--
>
0U
)
{
*
ptr
++
=
val
;
*
ptr
=
(
uint8_t
)
val
;
ptr
++
;
}
}
return
dst
;
return
dst
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment