From f64111dd32521890a9585a80e93b44bb73e67dbf Mon Sep 17 00:00:00 2001 From: ensc Date: Thu, 14 Feb 2008 21:51:41 +0000 Subject: [PATCH] fixed big-endian problems in strcpy + strcmp --- dietlibc-0.31.20080212-strend.patch | 53 +++++++++++++++++++++++++++++ dietlibc.spec | 2 ++ 2 files changed, 55 insertions(+) create mode 100644 dietlibc-0.31.20080212-strend.patch diff --git a/dietlibc-0.31.20080212-strend.patch b/dietlibc-0.31.20080212-strend.patch new file mode 100644 index 0000000..2fad801 --- /dev/null +++ b/dietlibc-0.31.20080212-strend.patch @@ -0,0 +1,53 @@ +diff -upN dietlibc-0.31.20080212/lib/strcpy.c.~1~ dietlibc-0.31.20080212/lib/strcpy.c +--- dietlibc-0.31.20080212/lib/strcpy.c.~1~ 2008-02-14 21:51:56.000000000 +0100 ++++ dietlibc-0.31.20080212/lib/strcpy.c 2008-02-14 22:45:56.000000000 +0100 +@@ -26,8 +26,7 @@ strcpy (char *s1, const char *s2) + while (1) { + l = *(const unsigned long *) s2; + if (((l - MKW(0x1ul)) & ~l) & MKW(0x80ul)) { +- unsigned char c; +- while ((*s1++ = (l & 0xff))) l>>=8; ++ while ((*s1++ = GFC(l))) INCSTR(l); + return (res); + } + *(unsigned long *) s1 = l; +diff -upN dietlibc-0.31.20080212/lib/strcmp.c.~1~ dietlibc-0.31.20080212/lib/strcmp.c +--- dietlibc-0.31.20080212/lib/strcmp.c.~1~ 2008-02-14 21:51:56.000000000 +0100 ++++ dietlibc-0.31.20080212/lib/strcmp.c 2008-02-14 22:44:44.000000000 +0100 +@@ -35,12 +35,12 @@ strcmp (const char *s1, const char *s2) + ((((l2 - MKW(0x1ul)) & ~l2) & MKW(0x80ul))) || l1 != l2) { + unsigned char c1, c2; + while (1) { +- c1 = l1 & 0xff; +- c2 = l2 & 0xff; ++ c1 = GFC(l1); ++ c2 = GFC(l2); + if (!c1 || c1 != c2) + return (c1 - c2); +- l1 >>= 8; +- l2 >>= 8; ++ INCSTR(l1); ++ INCSTR(l2); + } + } + } +diff -upN dietlibc-0.31.20080212/dietstring.h.~1~ dietlibc-0.31.20080212/dietstring.h +--- dietlibc-0.31.20080212/dietstring.h.~1~ 2003-12-21 13:06:36.000000000 +0100 ++++ dietlibc-0.31.20080212/dietstring.h 2008-02-14 22:45:56.000000000 +0100 +@@ -11,6 +11,16 @@ + # define STRALIGN(x) (((unsigned long)x&3)?4-((unsigned long)x&3):0) + #endif + ++/* GFC(x) - returns first character */ ++/* INCSTR(x) - moves to next character */ ++#if __BYTE_ORDER == __LITTLE_ENDIAN ++# define GFC(x) ((x)&0xff) ++# define INCSTR(x) do { x >>= 8; } while (0) ++#else ++# define GFC(x) (((x)>>(sizeof(x)-8))&0xff) ++# define INCSTR(x) do { x <<= 8; } while (0) ++#endif ++ + #define UNALIGNED(x,y) (((unsigned long)x & (sizeof (unsigned long)-1)) ^ ((unsigned long)y & (sizeof (unsigned long)-1))) + + #endif /* _DIET_STRING_H_ */ diff --git a/dietlibc.spec b/dietlibc.spec index 01653d4..43ee7cd 100644 --- a/dietlibc.spec +++ b/dietlibc.spec @@ -53,6 +53,7 @@ Patch40: dietlibc-0.31-printftest.patch Patch41: dietlibc-0.31.20080212-teststdout.patch Patch42: dietlibc-0.31.20080212-strlen.patch Patch43: dietlibc-0.31.20080212-ulong.patch +Patch44: dietlibc-0.31.20080212-strend.patch BuildRoot: %_tmppath/%name-%version-%release-buildroot %{?with_dynamic:Requires: dietlibc-lib = %version-%release} %{!?with_dynamic:Obsoletes: dietlibc-lib < %version-%release} @@ -95,6 +96,7 @@ This package contains the dynamic libraries for dietlibc. %patch41 -p1 -b .teststdout %patch42 -p1 -b .strlen %patch43 -p1 -b .ulong +%patch44 -p1 -b .strend %if %{without ssp}