• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision592574ae535c35de500f6c3e8d8400d0bb0d985a (tree)
Zeit2022-04-13 21:17:48
AutorTom Bannink <tombannink@gmai...>
CommiterWaldemar Brodkorb

Log Message

Fix bug in ARM memset implementation

The ARM implementation of memset has a bug when the fill-value is negative or outside the
[0, 255] range. To reproduce:

char array[256];
memset(array, -5, 256);

This is supposed to fill the array with int8 values -5, -5, -5, ... . On ARM, this does
not work because the implementation assumes the high bytes of the fill-value argument are
already zero. However in this test case they are filled with 1-bits. The aarch64 and x86_64
implementations do not have this problem: they first convert the fill-value to an unsigned
byte following the specification of memset.

With GCC one can use memset(ptr, (-5 & 0xFF), size) as a workaround, but for clang
users that does not work: clang optimizes the & 0xFF away because it assumes that
memset will do it.

Signed-off-by: Tom Bannink <tombannink@gmail.com>
Acked-by: Peter Korsgaard <peter@korsgaard.com>

Ändern Zusammenfassung

Diff

--- a/libc/string/arm/memset.S
+++ b/libc/string/arm/memset.S
@@ -32,6 +32,7 @@ memset:
3232 cmp r2, #8 @ at least 8 bytes to do?
3333 bcc 2f
3434
35+ and r1, r1, #0xFF
3536 lsl r3, r1, #8
3637 orr r1, r3
3738 lsl r3, r1, #16
@@ -68,6 +69,7 @@ memset:
6869 mov a4, a1
6970 cmp a3, $8 @ at least 8 bytes to do?
7071 blo 2f
72+ and a2, a2, #0xFF
7173 orr a2, a2, a2, lsl $8
7274 orr a2, a2, a2, lsl $16
7375 1: