delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2011/06/30/15:15:05

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: V01U2FsdGVkX19L+ScIcm5L7XxQ4cm2flhfPRobCjzKVGVZx6HVPC
it5iWXlqRbxs6U
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
To: djgpp-workers AT delorie DOT com
Subject: Re: [patch] fix epunzip stric aliasing warnings
Date: Thu, 30 Jun 2011 21:09:30 +0200
User-Agent: KMail/1.9.10
References: <BANLkTinj8niun3H0Z6QTTsfQZ=8jD1rcSg AT mail DOT gmail DOT com>
In-Reply-To: <BANLkTinj8niun3H0Z6QTTsfQZ=8jD1rcSg@mail.gmail.com>
MIME-Version: 1.0
Message-Id: <201106302109.30225.juan.guerrero@gmx.de>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

Am Dienstag, 28. Juni 2011 schrieb Ozkan Sezer:
> Hi:
> 
> The attached patch fixes strict aliasing violation warnings in
> djtar/epunzip.c.  The warnings are only visible when using gcc<=3.3
> (old but one I do use) but worth fixing, IMO, considering the shape
> of the code.
> 
> Regards.
> 
> --
> O.S.
> 

I tested the patch submitted by Ozkan Sezer using gcc453b and gcc460b both 
djdev204 versions and it fixes the strict warning issues.  The proposed changes
look ok to me.  If no one objects in a reasonable period of time I will commit
the patch below.

Regards,
Juan M. Guerrero



	* src/utils/djtar/epunzip.c (epunzip_read): Fix strict aaliasing warning.
	From Ozkan Sezer <sezeroz AT gmail DOT com> 



Index: djgpp/src/utils/djtar/epunzip.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/utils/djtar/epunzip.c,v
retrieving revision 1.8
diff -U 3 -r1.8 epunzip.c
--- djgpp/src/utils/djtar/epunzip.c	9 Jan 2011 14:19:59 -0000	1.8
+++ djgpp/src/utils/djtar/epunzip.c	30 Jun 2011 19:08:00 -0000
@@ -54,30 +54,30 @@
    * for a one-segment ZIP, but fail on other headers. */
   while(1)
     {
-      int buffer = 0;
+      char buffer[4];
 
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
 
-      if(*(__dj_short_a *)&buffer != *(const short *)(const void *)"PK")
+      if(*(__dj_short_a *)buffer != ('K' << 8) + 'P')
 	break;
 
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
 
-      if(*(__dj_short_a *)&buffer == *(const short *)(const void *)"\x3\x4")
+      if(*(__dj_short_a *)buffer == ('\004' << 8) + '\003')
 	{
 	  /* local header */
 	  at_local_header = 1;
 	  break;
 	}
-      else if(*(__dj_short_a *)&buffer == *(const short *)(const void *)"\x30\x30")
+      else if(*(__dj_short_a *)buffer == ('0' << 8) + '0')
 	{
 	  /* spanning marker, but only one segment
 	   * => need to find local header. */
 	  continue;
 	}
-      else if(*(__dj_short_a *)&buffer == *(const short *)(const void *)"\x7\x8")
+      else if(*(__dj_short_a *)buffer == ('\010' << 8) + '\007')
 	{
 	  /* spanning marker, multiple segments. */
 	  fprintf(log_out, "%s: spanning is not supported\n", zipfilename);
@@ -89,7 +89,7 @@
 	  /* unknown header */
 	  fprintf(log_out,
 		  "%s: don't understand header type 0x%02x%02x\n",
-		  zipfilename, ((char *)&buffer)[0], ((char *)&buffer)[1]);
+		  zipfilename, buffer[0], buffer[1]);
 	  dont_understand = 1;
 	  break;
 	}
@@ -100,25 +100,26 @@
 
   if (at_local_header) while(1)
     {
-      int buffer, ext_header, timedate, crc, size, length, name_length,
+      int ext_header, timedate, crc, size, length, name_length,
 	extra_length, should_be_written, count, real_file = 0;
+      char buffer[4];
       char filename[2048];
 
       if (!at_local_header)
 	{
-	  ((char *)&buffer)[0] = (char)get_byte();
-	  ((char *)&buffer)[1] = (char)get_byte();
+	  buffer[0] = (char)get_byte();
+	  buffer[1] = (char)get_byte();
 
-	  if(*(__dj_short_a *)&buffer != *(const short *)(const void *)"PK")
+	  if(*(__dj_short_a *)buffer != ('K' << 8) + 'P')
 	    {
 	      fprintf(log_out, "%s: invalid zip file structure\n", zipfilename);
 	      break;
 	    }
 
-	  ((char *)&buffer)[0] = (char)get_byte();
-	  ((char *)&buffer)[1] = (char)get_byte();
+	  buffer[0] = (char)get_byte();
+	  buffer[1] = (char)get_byte();
 
-	  if(*(__dj_short_a *)&buffer != *(const short *)(const void *)"\x3\x4")
+	  if(*(__dj_short_a *)buffer != ('\004' << 8) + '\003')
 	    {
 	      /* not a local header - all done */
 	      break;
@@ -133,57 +134,57 @@
       get_byte();
       get_byte();
 
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
 
-      if(*(__dj_short_a *)&buffer & CRYFLG)
+      if(*(__dj_short_a *)buffer & CRYFLG)
 	{
 	  fprintf(log_out, "%s has encrypted file(s) - use unzip\n", zipfilename);
 	  break;
 	}
-      ext_header = *(__dj_short_a *)&buffer & EXTFLG ? 1 : 0;
+      ext_header = *(__dj_short_a *)buffer & EXTFLG ? 1 : 0;
 
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
 
-      method = *(__dj_short_a *)&buffer;
+      method = *(__dj_short_a *)buffer;
       if(method != 8 && method != 0)
 	{
 	  fprintf(log_out, "%s has file(s) compressed with unsupported method - use unzip\n", zipfilename);
 	  break;
 	}
 
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
-      ((char *)&buffer)[2] = (char)get_byte();
-      ((char *)&buffer)[3] = (char)get_byte();
-      timedate = buffer;
-
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
-      ((char *)&buffer)[2] = (char)get_byte();
-      ((char *)&buffer)[3] = (char)get_byte();
-      crc = buffer;
-
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
-      ((char *)&buffer)[2] = (char)get_byte();
-      ((char *)&buffer)[3] = (char)get_byte();
-      size = buffer;
-
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
-      ((char *)&buffer)[2] = (char)get_byte();
-      ((char *)&buffer)[3] = (char)get_byte();
-      length = buffer;
-
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
-      name_length = *(__dj_short_a *)&buffer;
-
-      ((char *)&buffer)[0] = (char)get_byte();
-      ((char *)&buffer)[1] = (char)get_byte();
-      extra_length = *(__dj_short_a *)&buffer;
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
+      buffer[2] = (char)get_byte();
+      buffer[3] = (char)get_byte();
+      timedate = *(__dj_int_a *)buffer;
+
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
+      buffer[2] = (char)get_byte();
+      buffer[3] = (char)get_byte();
+      crc = *(__dj_int_a *)buffer;
+
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
+      buffer[2] = (char)get_byte();
+      buffer[3] = (char)get_byte();
+      size = *(__dj_int_a *)buffer;
+
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
+      buffer[2] = (char)get_byte();
+      buffer[3] = (char)get_byte();
+      length = *(__dj_int_a *)buffer;
+
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
+      name_length = *(__dj_short_a *)buffer;
+
+      buffer[0] = (char)get_byte();
+      buffer[1] = (char)get_byte();
+      extra_length = *(__dj_short_a *)buffer;
 
       for(count = 0; count < name_length; count++)
 	{
@@ -277,34 +278,34 @@
 
 	  if(ext_header)
 	    {
-	      ((char *)&buffer)[0] = (char)get_byte();
-	      ((char *)&buffer)[1] = (char)get_byte();
-	      ((char *)&buffer)[2] = (char)get_byte();
-	      ((char *)&buffer)[3] = (char)get_byte();
-	      if(buffer != *(int *)"PK\x7\x8")
+	      buffer[0] = (char)get_byte();
+	      buffer[1] = (char)get_byte();
+	      buffer[2] = (char)get_byte();
+	      buffer[3] = (char)get_byte();
+	      if(*(__dj_int_a *)buffer != ('\010' << 24) + ('\007' << 16) + ('K' << 8) + 'P')
 		{
 		  fprintf(log_out, "%s: invalid zip file structure\n",
 			  zipfilename);
 		  break;
 		}
 
-	      ((char *)&buffer)[0] = (char)get_byte();
-	      ((char *)&buffer)[1] = (char)get_byte();
-	      ((char *)&buffer)[2] = (char)get_byte();
-	      ((char *)&buffer)[3] = (char)get_byte();
-	      crc = buffer;
-
-	      ((char *)&buffer)[0] = (char)get_byte();
-	      ((char *)&buffer)[1] = (char)get_byte();
-	      ((char *)&buffer)[2] = (char)get_byte();
-	      ((char *)&buffer)[3] = (char)get_byte();
-	      size = buffer;
-
-	      ((char *)&buffer)[0] = (char)get_byte();
-	      ((char *)&buffer)[1] = (char)get_byte();
-	      ((char *)&buffer)[2] = (char)get_byte();
-	      ((char *)&buffer)[3] = (char)get_byte();
-	      length = buffer;
+	      buffer[0] = (char)get_byte();
+	      buffer[1] = (char)get_byte();
+	      buffer[2] = (char)get_byte();
+	      buffer[3] = (char)get_byte();
+	      crc = *(__dj_int_a *)buffer;
+
+	      buffer[0] = (char)get_byte();
+	      buffer[1] = (char)get_byte();
+	      buffer[2] = (char)get_byte();
+	      buffer[3] = (char)get_byte();
+	      size = *(__dj_int_a *)buffer;
+
+	      buffer[0] = (char)get_byte();
+	      buffer[1] = (char)get_byte();
+	      buffer[2] = (char)get_byte();
+	      buffer[3] = (char)get_byte();
+	      length = *(__dj_int_a *)buffer;
 	    }
 
 	}

- Raw text -


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