From 56d9a530202979fed9544131aa2e53bf2da0c7de Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 7 May 2008 19:23:18 -0400 Subject: [PATCH] PR5648: Fix memcpy's endianess issue. --- runtime/ChangeLog | 5 +++++ runtime/vsprintf.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 8410b9183..0a66a28bd 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,8 @@ +2008-05-06 Masami Hiramatsu + + PR 5648 + * vsprintf.c (_stp_vsnprintf): Fix memcpy's endianess issue. + 2008-05-05 Frank Ch. Eigler PR 6481. diff --git a/runtime/vsprintf.c b/runtime/vsprintf.c index dcaa1bc37..4ffcf72e2 100644 --- a/runtime/vsprintf.c +++ b/runtime/vsprintf.c @@ -248,6 +248,11 @@ int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) ++str; } } +#ifdef __ia64__ + if ((str + precision - 1) <= end) + memcpy(str, &num, precision); //to prevent unaligned access + str += precision; +#else switch(precision) { case 1: if(str <= end) @@ -256,21 +261,22 @@ int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) break; case 2: if((str + 1) <= end) - memcpy(str, &num, 2); + *(int16_t *)str = (int16_t)num; str+=2; break; case 4: if((str + 3) <= end) - memcpy(str, &num, 4); + *(int32_t *)str = num; str+=4; break; default: // "%.8b" by default case 8: if((str + 7) <= end) - memcpy(str, &num, 8); + *(int64_t *)str = num; str+=8; break; } +#endif while (len < field_width--) { if (str <= end) *str = '\0'; -- 2.43.5