delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2008/05/11/13:08:53

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
X-Authenticated: #27081556
X-Provags-ID: V01U2FsdGVkX19IxMMWNMNIhB20I8gT9n9QDJx+84YuJ27FYvXpnI
nW//k5tAGUsO6k
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
To: djgpp-workers AT delorie DOT com
Subject: type punning fix for doprnt.c
Date: Sun, 11 May 2008 19:01:36 +0200
User-Agent: KMail/1.9.5
MIME-Version: 1.0
Message-Id: <200805111901.37922.juan.guerrero@gmx.de>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

OFYI: to pacify gcc 4.3.0 due to dereferencing type-punned pointers I have
applied this patch.

Regards,
Juan M. Guerrero



Index: src/libc/ansi/stdio/doprnt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doprnt.c,v
retrieving revision 1.27
diff -p -U3 -r1.27 doprnt.c
--- src/libc/ansi/stdio/doprnt.c	1 May 2008 00:45:51 -0000	1.27
+++ src/libc/ansi/stdio/doprnt.c	11 May 2008 16:57:35 -0000
@@ -95,7 +95,7 @@ static __inline__ char tochar(int n)
 #define	ZEROPAD		0x0100		/* zero (as opposed to blank) pad */
 #define	HEXPREFIX	0x0200		/* add 0x or 0X prefix */
 #define	GROUPING	0x0400		/* non monetary thousands grouping */
-#define	UPPERCASE	0x0800		/* INF/NAN for [EFG] */
+#define	UPPERCASE	0x0800		/* INF/NAN for [AEFG] */
 
 static int cvtl(long double number, int prec, int flags, char *signp,
 	        unsigned char fmtch, char *startp, char *endp);
@@ -679,12 +679,15 @@ cvtl(long double number, int prec, int f
 #define HEX_DIGIT_SIZE                  4
 #define IEEE754_LONG_DOUBLE_BIAS        0x3FFFU
 
-
-    long_double_t ip = *(long_double_t *)(void *)&number;
+    _longdouble_union_t ieee_value;
     char *fraction_part;
-    int left_shifts, precision_given, positive_exponent, exponent = ip.exponent;
-    unsigned long long int mantissa = (unsigned long long int) ip.mantissah << 32 | ip.mantissal;
+    int left_shifts, precision_given, positive_exponent, exponent;
+    unsigned long long int mantissa;
+
 
+    ieee_value.ld = number;
+    exponent = ieee_value.ldt.exponent;
+    mantissa = (unsigned long long int) ieee_value.ldt.mantissah << 32 | ieee_value.ldt.mantissal;
     p = endp;
     t = startp;
     precision_given = (prec != -1) ? TRUE : FALSE;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019