This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ECOS] Re: Bug in crc32 routine?


On Fri, Oct 18, 2002 at 03:14:24AM +0100, Jonathan Larmour wrote:
> >+  if (1667500021 != cyg_ether_crc32(license_txt,sizeof(license_txt)-1)) {
> 
> Mumble, mumble, 32-bit reliance, mumble ;-). Really, that's what the type 
> defs in <cyg/infra/cyg_type.h> are for - rather than using unsigned longs. 
> (Although in due course we should use the C99 <inttypes.h> when GCC gets 
> round to implementing it).

Will this stop you mumbling?

     Andrew

Index: packages/services/crc/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/crc/current/ChangeLog,v
retrieving revision 1.3
diff -u -r1.3 ChangeLog
--- packages/services/crc/current/ChangeLog	18 Oct 2002 02:14:43 -0000	1.3
+++ packages/services/crc/current/ChangeLog	28 Oct 2002 17:05:31 -0000
@@ -1,3 +1,7 @@
+2002-10-28  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* */*: Fixed 32-bit reliance.
+
 2002-10-18  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* include/crc.h: Add extern definitions.
Index: packages/services/crc/current/doc/crc.sgml
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/crc/current/doc/crc.sgml,v
retrieving revision 1.4
diff -u -r1.4 crc.sgml
--- packages/services/crc/current/doc/crc.sgml	18 Oct 2002 02:06:49 -0000	1.4
+++ packages/services/crc/current/doc/crc.sgml	28 Oct 2002 17:05:31 -0000
@@ -24,7 +24,7 @@
 1008.2 Standard. This is the same as the Linux cksum program.
 </para>
 <programlisting>
-unsigned long cyg_posix_crc32(unsigned char &ast; s, int len);
+cyg_uint32 cyg_posix_crc32(unsigned char &ast; s, int len);
 </programlisting>
 <para>
 The CRC calculation is run over the data pointed to by
@@ -40,8 +40,8 @@
 X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0.
 </para>
 <programlisting>
-unsigned long cyg_crc32(unsigned char &ast; s, int len);
-unsigned long cyg_crc32_accumulate(unsigned long crc, unsigned char &ast; s, int len);
+cyg_uint32 cyg_crc32(unsigned char &ast; s, int len);
+cyg_uint32 cyg_crc32_accumulate(cyg_uint32 crc, unsigned char &ast; s, int len);
 </programlisting>
 <para>
 The CRC calculation is run over the data pointed to by
@@ -61,8 +61,8 @@
 These functions implement the 32 bit CRC used by the Ethernet FCS word.
 </para>
 <programlisting>
-unsigned long cyg_ether_crc32(unsigned char &ast; s, int len);
-unsigned long cyg_ether_crc32_accumulate(unsigned long crc, unsigned char &ast; s, int len);
+cyg_uint32 cyg_ether_crc32(unsigned char &ast; s, int len);
+cyg_uint32 cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char &ast; s, int len);
 </programlisting>
 <para>
 The CRC calculation is run over the data pointed to by
@@ -83,7 +83,7 @@
 x^16+x^12+x^5+1.
 </para>
 <programlisting>
-unsigned short cyg_crc16(unsigned char &ast; s, int len);
+cyg_uint16 cyg_crc16(unsigned char &ast; s, int len);
 </programlisting>
 <para>
 The CRC calculation is run over the data pointed to by
Index: packages/services/crc/current/include/crc.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/crc/current/include/crc.h,v
retrieving revision 1.3
diff -u -r1.3 crc.h
--- packages/services/crc/current/include/crc.h	18 Oct 2002 02:14:44 -0000	1.3
+++ packages/services/crc/current/include/crc.h	28 Oct 2002 17:05:31 -0000
@@ -55,6 +55,8 @@
 #ifndef _SERVICES_CRC_CRC_H_
 #define _SERVICES_CRC_CRC_H_
 
+#include <cyg/infra/cyg_type.h>
+
 #ifndef __externC
 # ifdef __cplusplus
 #  define __externC extern "C"
@@ -65,34 +67,34 @@
 
 // Compute a CRC, using the POSIX 1003 definition
 
-__externC unsigned long 
+__externC cyg_uint32 
 cyg_posix_crc32(unsigned char *s, int len);
 
 // Gary S. Brown's 32 bit CRC
 
-__externC unsigned long 
+__externC cyg_uint32 
 cyg_crc32(unsigned char *s, int len);
 
 // Gary S. Brown's 32 bit CRC, but accumulate the result from a
 // previous CRC calculation
 
-__externC unsigned long 
-cyg_crc32_accumulate(unsigned long crc, unsigned char *s, int len);
+__externC cyg_uint32 
+cyg_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);
 
 // Ethernet FCS Algorithm
 
-__externC unsigned long 
+__externC cyg_uint32 
 cyg_ether_crc32(unsigned char *s, int len);
 
 // Ethernet FCS algorithm, but accumulate the result from a previous
 // CRC calculation.
 
-__externC unsigned long 
-cyg_ether_crc32_accumulate(unsigned long crc, unsigned char *s, int len);
+__externC cyg_uint32 
+cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);
 
 // 16 bit CRC with polynomial x^16+x^12+x^5+1
 
-__externC unsigned short
+__externC cyg_uint16
 cyg_crc16(unsigned char *s, int len);
 
 #endif // _SERVICES_CRC_CRC_H_
Index: packages/services/crc/current/src/crc16.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/crc/current/src/crc16.c,v
retrieving revision 1.1
diff -u -r1.1 crc16.c
--- packages/services/crc/current/src/crc16.c	9 Aug 2002 10:27:04 -0000	1.1
+++ packages/services/crc/current/src/crc16.c	28 Oct 2002 17:05:31 -0000
@@ -56,7 +56,7 @@
 #include <cyg/crc/crc.h>
 
 // Table of CRC constants - implements x^16+x^12+x^5+1
-static const unsigned short crc16_tab[] = {
+static const cyg_uint16 crc16_tab[] = {
     0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 
     0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 
     0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 
@@ -91,11 +91,11 @@
     0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, 
 };
 
-unsigned short
+cyg_uint16
 cyg_crc16(unsigned char *buf, int len)
 {
     int i;
-    unsigned short cksum;
+    cyg_uint16 cksum;
 
     cksum = 0;
     for (i = 0;  i < len;  i++) {
Index: packages/services/crc/current/src/crc32.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/crc/current/src/crc32.c,v
retrieving revision 1.2
diff -u -r1.2 crc32.c
--- packages/services/crc/current/src/crc32.c	14 Oct 2002 15:31:13 -0000	1.2
+++ packages/services/crc/current/src/crc32.c	28 Oct 2002 17:05:31 -0000
@@ -65,7 +65,7 @@
   /*                                                                        */
   /* ====================================================================== */
 
-static const unsigned long crc32_tab[] = {
+static const cyg_uint32 crc32_tab[] = {
       0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
       0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
       0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
@@ -122,8 +122,8 @@
 
 /* This is the standard Gary S. Brown's 32 bit CRC algorithm, but
    accumulate the CRC into the result of a previous CRC. */
-unsigned long 
-cyg_crc32_accumulate(unsigned long crc32val, unsigned char *s, int len)
+cyg_uint32 
+cyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
 {
   int i;
 
@@ -134,7 +134,7 @@
 }
 
 /* This is the standard Gary S. Brown's 32 bit CRC algorithm */
-unsigned long 
+cyg_uint32
 cyg_crc32(unsigned char *s, int len)
 {
   return (cyg_crc32_accumulate(0,s,len));
@@ -143,8 +143,8 @@
 /* Return a 32-bit CRC of the contents of the buffer accumulating the
    result from a previous CRC calculation. This uses the Ethernet FCS
    algorithm.*/
-unsigned long 
-cyg_ether_crc32_accumulate(unsigned long crc32val, unsigned char *s, int len)
+cyg_uint32
+cyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
 {
   int i;
 
@@ -159,7 +159,7 @@
 
 /* Return a 32-bit CRC of the contents of the buffer, using the
    Ethernet FCS algorithm. */
-unsigned long 
+cyg_uint32
 cyg_ether_crc32(unsigned char *s, int len)
 {
   return cyg_ether_crc32_accumulate(0,s,len);
Index: packages/services/crc/current/src/posix_crc.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/crc/current/src/posix_crc.c,v
retrieving revision 1.1
diff -u -r1.1 posix_crc.c
--- packages/services/crc/current/src/posix_crc.c	9 Aug 2002 10:27:04 -0000	1.1
+++ packages/services/crc/current/src/posix_crc.c	28 Oct 2002 17:05:31 -0000
@@ -61,7 +61,7 @@
 // opposite order.  This computation matches the output of the
 // Linux 'cksum' program.
 
-static const unsigned long posix_crc32_tab[] = {
+static const cyg_uint32 posix_crc32_tab[] = {
   0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 
   0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD,
   0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, 
@@ -96,11 +96,11 @@
   0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
    };
 
-unsigned long 
+cyg_uint32 
 cyg_posix_crc32(unsigned char *s, int len)
 {
   int i;
-  unsigned long crc32val;
+  cyg_uint32 crc32val;
   unsigned long length;
   
   crc32val = 0;
Index: packages/services/crc/current/tests/crc_test.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/crc/current/tests/crc_test.c,v
retrieving revision 1.2
diff -u -r1.2 crc_test.c
--- packages/services/crc/current/tests/crc_test.c	14 Oct 2002 15:31:14 -0000	1.2
+++ packages/services/crc/current/tests/crc_test.c	28 Oct 2002 17:05:31 -0000
@@ -79,13 +79,13 @@
   
   CYG_TEST_INFO("Calculating CRCs");
  
-  if (1500790746l != cyg_posix_crc32(license_txt,sizeof(license_txt)-1)) {
+  if (1500790746UL != cyg_posix_crc32(license_txt,sizeof(license_txt)-1)) {
     CYG_TEST_FAIL("Wrong POSIX CRC32 calculation");
   } else {
     CYG_TEST_PASS("POSIX CRC32 calculation");
   }
   
-  if (1667500021 != cyg_ether_crc32(license_txt,sizeof(license_txt)-1)) {
+  if (1667500021UL != cyg_ether_crc32(license_txt,sizeof(license_txt)-1)) {
     CYG_TEST_FAIL("Wrong Ethernet crc32 calculation");
   } else {
     CYG_TEST_PASS("Ethernet crc32 calculation");
@@ -97,14 +97,14 @@
     crc1= cyg_ether_crc32_accumulate(0, license_txt,sizeof(license_txt)-1);
     crc2 = cyg_ether_crc32_accumulate(crc1, license_txt,sizeof(license_txt)-1);
     
-    if ((1667500021 != crc1) || (3478736840u != crc2)) {
+    if ((1667500021UL != crc1) || (3478736840UL != crc2)) {
       CYG_TEST_FAIL("Wrong Etheret crc32 accumulate");
     } else {
       CYG_TEST_PASS("Ethernet crc32_accumulate");
     }
   }
 
-  if (1247800780 != cyg_crc32(license_txt,sizeof(license_txt)-1)) {
+  if (1247800780UL != cyg_crc32(license_txt,sizeof(license_txt)-1)) {
     CYG_TEST_FAIL("Wrong Gary S. Browns' crc32 calculation");
   } else {
     CYG_TEST_PASS("Gary S. Browns' crc32 calculation");
@@ -113,13 +113,13 @@
   crc1 = cyg_crc32_accumulate(0,license_txt,sizeof(license_txt)-1);
   crc2 = cyg_crc32_accumulate(crc1,license_txt,sizeof(license_txt)-1);
     
-  if ((1247800780 != crc1) || (926002294 != crc2)) {
+  if ((1247800780UL != crc1) || (926002294UL != crc2)) {
     CYG_TEST_FAIL("Wrong Gary S. Browns' crc32 accumulate calculation");
   } else {
     CYG_TEST_PASS("Gary S. Browns' crc32 accumulate calculation");
   }
     
-  if (32256 != cyg_crc16(license_txt,sizeof(license_txt)-1)) {
+  if (32256UL != cyg_crc16(license_txt,sizeof(license_txt)-1)) {
     CYG_TEST_FAIL_FINISH("Wrong 16bit CRC calculation");
   } else {
     CYG_TEST_PASS_FINISH("16bit CRC calculation");


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]