]> Creatis software - gdcm.git/commitdiff
BUG: was leading zeroes in numeric components. This is illegal, according to PS 3...
authormalaterre <malaterre>
Sat, 22 Jan 2005 01:40:41 +0000 (01:40 +0000)
committermalaterre <malaterre>
Sat, 22 Jan 2005 01:40:41 +0000 (01:40 +0000)
src/gdcmUtil.cxx

index 90359b57797adbac23a48c2442c89a77c2832d6d..3ec5687345cb007d7827a7751323b84a3ef7e485 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/21 20:49:37 $
-  Version:   $Revision: 1.117 $
+  Date:      $Date: 2005/01/22 01:40:41 $
+  Version:   $Revision: 1.118 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -676,18 +676,24 @@ std::string Util::GetMACAddress()
    // 3 OS: Win32, SunOS and 'real' POSIX
    // http://groups-beta.google.com/group/comp.unix.solaris/msg/ad36929d783d63be
    // http://bdn.borland.com/article/0,1410,26040,00.html
-   union dual { uint64_t n; unsigned char addr[6];  };
+   unsigned char addr[6];
+   uint64_t n = 0;
  
-   // zero-initialize the whole thing first:
-   dual d = { 0 };
-   int stat = GetMacAddrSys(d.addr);
+   int stat = GetMacAddrSys(addr);
    if (stat == 0)
    {
-      // fill with zero to fit on 15 bytes.
+      // Horner evaluation
+      for(int i=0; i<6; i++)
+      {
+         n *= 256;
+         n += addr[i];
+      }
+
+      // we fit on 15 bytes maximum < 256^6.
 #if defined(_MSC_VER) || defined(__BORLANDC__)
-      return Format("%015I64u", d.n);
+      return Format("%I64u", n);
 #else
-      return Format("%015llu", d.n);
+      return Format("%llu", n);
 #endif
    }
    else