From bdbcc9f17fe73967e766505c1a978429bf66431a Mon Sep 17 00:00:00 2001 From: malaterre Date: Sat, 22 Jan 2005 01:40:41 +0000 Subject: [PATCH] BUG: was leading zeroes in numeric components. This is illegal, according to PS 3.8 Annex F and PS 3.5 Section 6.1 and ISO 8824. Also remove the union this is a bad idea when working on little and big endian machine, the result was not constitant across endianess --- src/gdcmUtil.cxx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 90359b57..3ec56873 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -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 -- 2.48.1