From 84b99dbbcc344644cb436323fec8d24d6c816369 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 1 Feb 2011 18:56:55 +0100 Subject: [PATCH] Changed: #1249 Endianness problems while access to disk or memory --- code/nel/include/nel/misc/bitmap.h | 14 ++++++++++---- code/ryzom/client/src/permanent_ban.cpp | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/code/nel/include/nel/misc/bitmap.h b/code/nel/include/nel/misc/bitmap.h index 99fa5527f..06d8d2670 100644 --- a/code/nel/include/nel/misc/bitmap.h +++ b/code/nel/include/nel/misc/bitmap.h @@ -35,13 +35,19 @@ class IStream; //------------------ DDS STUFFS -------------------- #ifndef NL_MAKEFOURCC - #define NL_MAKEFOURCC(ch0, ch1, ch2, ch3) \ - ((uint32)(uint8)(ch0) | ((uint32)(uint8)(ch1) << 8) | \ - ((uint32)(uint8)(ch2) << 16) | ((uint32)(uint8)(ch3) << 24 )) + #ifdef NL_LITTLE_ENDIAN + #define NL_MAKEFOURCC(ch0, ch1, ch2, ch3) \ + ((uint32)(uint8)(ch0) | ((uint32)(uint8)(ch1) << 8) | \ + ((uint32)(uint8)(ch2) << 16) | ((uint32)(uint8)(ch3) << 24 )) + #else + #define NL_MAKEFOURCC(ch0, ch1, ch2, ch3) \ + ((uint32)(uint8)(ch3) | ((uint32)(uint8)(ch2) << 8) | \ + ((uint32)(uint8)(ch1) << 16) | ((uint32)(uint8)(ch0) << 24 )) + #endif #endif const uint32 DDS_HEADER = NL_MAKEFOURCC('D', 'D', 'S', ' '); -const uint32 DXT_HEADER = NL_MAKEFOURCC('D','X', 'T', '\0'); +const uint32 DXT_HEADER = NL_MAKEFOURCC('D', 'X', 'T', '\0'); const uint32 PNG_HEADER = NL_MAKEFOURCC(0x89, 'P', 'N', 'G'); const uint32 JPG_HEADER = NL_MAKEFOURCC(0xff, 0xd8, 0xff, 0xe0); diff --git a/code/ryzom/client/src/permanent_ban.cpp b/code/ryzom/client/src/permanent_ban.cpp index 8cb4d0fac..032a5ffaa 100644 --- a/code/ryzom/client/src/permanent_ban.cpp +++ b/code/ryzom/client/src/permanent_ban.cpp @@ -157,6 +157,10 @@ static void markBNPFile(std::string &path) return; } +#ifdef NL_BIG_ENDIAN + NLMISC_BSWAP32(nOffsetFromBegining); +#endif + if (nlfseek64 (f, nOffsetFromBegining, SEEK_SET) != 0) { fclose (f); @@ -170,6 +174,11 @@ static void markBNPFile(std::string &path) fclose (f); return; } + +#ifdef NL_BIG_ENDIAN + NLMISC_BSWAP32(nNbFile); +#endif + for (uint32 i = 0; i < nNbFile; ++i) { char FileName[MAX_PATH]; @@ -223,12 +232,20 @@ static void markBNPFile(std::string &path) return; } +#ifdef NL_BIG_ENDIAN + NLMISC_BSWAP32(nFileSize2); +#endif + uint32 nFilePos; if (fread (&nFilePos, sizeof(uint32), 1, f) != 1) { fclose (f); return; } + +#ifdef NL_BIG_ENDIAN + NLMISC_BSWAP32(nFilePos); +#endif } fclose (f);