diff options
author | Kazu Hirata <kazu@codesourcery.com> | 2002-11-25 20:56:17 +0000 |
---|---|---|
committer | Kazu Hirata <kazu@codesourcery.com> | 2002-11-25 20:56:17 +0000 |
commit | f24585c6bb565026fe4e98f4b48219487c5877a8 (patch) | |
tree | 4c2ddc0f2538f18a9c8adabadc597fbb2190c476 /newlib | |
parent | 60d4d42f4f97784b71b3777f7c3c36f1ebeb8738 (diff) | |
download | newlib-f24585c6bb565026fe4e98f4b48219487c5877a8.zip newlib-f24585c6bb565026fe4e98f4b48219487c5877a8.tar.gz newlib-f24585c6bb565026fe4e98f4b48219487c5877a8.tar.bz2 |
* libc/string/memset.c (memset): Make it safe even if
sizeof (int) = 2.
Diffstat (limited to 'newlib')
-rw-r--r-- | newlib/ChangeLog | 5 | ||||
-rw-r--r-- | newlib/libc/string/memset.c | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 9cc8bfe..10d5f90 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,8 @@ +2002-11-25 Kazu Hirata <kazu@cs.umass.edu> + + * libc/string/memset.c (memset): Make it safe even if + sizeof (int) = 2. + 2002-11-22 Joe Buehler <jbuehler@hekimian.com> * configure.in: Change check for libc/include in ${CC} to diff --git a/newlib/libc/string/memset.c b/newlib/libc/string/memset.c index a5890c8..eceff8e 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) |