diff options
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/string/memset.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/newlib/libc/string/memset.c b/newlib/libc/string/memset.c index a5890c884..eceff8e9c 100644 --- a/newlib/libc/string/memset.c +++ b/newlib/libc/string/memset.c @@ -64,21 +64,23 @@ _DEFUN (memset, (m, c, n), { /* If we get this far, we know that n is large and m is word-aligned. */ + /* To avoid sign extention, copy C to an unsigned variable. */ + unsigned int d = c & 0xff; + aligned_addr = (unsigned long*)m; - /* Store C into each char sized location in BUFFER so that + /* Store D into each char sized location in BUFFER so that we can set large blocks quickly. */ - c &= 0xff; if (LBLOCKSIZE == 4) { - buffer = (c << 8) | c; + buffer = (d << 8) | d; buffer |= (buffer << 16); } else { buffer = 0; for (i = 0; i < LBLOCKSIZE; i++) - buffer = (buffer << 8) | c; + buffer = (buffer << 8) | d; } while (n >= LBLOCKSIZE*4) |