summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/CMakeCCompilerId.c.in4
-rw-r--r--Modules/CMakeCXXCompilerId.cpp.in4
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake5
-rw-r--r--Modules/CTestUseLaunchers.cmake2
-rw-r--r--Modules/CompilerId/VS-7.vcproj.in5
-rw-r--r--Modules/FindQt4.cmake4
-rw-r--r--Modules/FindSDL.cmake2
-rw-r--r--Modules/UseQt4.cmake12
-rw-r--r--Source/CMakeVersion.cmake2
-rw-r--r--Source/cmExportBuildFileGenerator.cxx14
-rw-r--r--Source/cmExportFileGenerator.cxx31
-rw-r--r--Source/cmExportFileGenerator.h2
-rw-r--r--Source/cmExportInstallFileGenerator.cxx14
-rw-r--r--Source/cmNinjaTargetGenerator.cxx16
-rw-r--r--Source/cmVisualStudioWCEPlatformParser.cxx48
-rw-r--r--Source/cmVisualStudioWCEPlatformParser.h13
-rw-r--r--Source/cmake.cxx36
-rw-r--r--Source/cmake.h2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_endian.h36
19 files changed, 219 insertions, 33 deletions
diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in
index 3d1380c..2d76c7a 100644
--- a/Modules/CMakeCCompilerId.c.in
+++ b/Modules/CMakeCCompilerId.c.in
@@ -228,7 +228,3 @@ int main(int argc, char* argv[])
return require;
}
#endif
-
-#ifdef ADD_MAINCRTSTARTUP
-void mainCRTStartup() {}
-#endif
diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in
index 142a5c5..5e70a41 100644
--- a/Modules/CMakeCXXCompilerId.cpp.in
+++ b/Modules/CMakeCXXCompilerId.cpp.in
@@ -210,7 +210,3 @@ int main(int argc, char* argv[])
(void)argv;
return require;
}
-
-#ifdef ADD_MAINCRTSTARTUP
-extern "C" void mainCRTStartup() {}
-#endif
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index 43469ea..609f35b 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -141,7 +141,10 @@ Id flags: ${testflags}
set(id_toolset "")
endif()
if(CMAKE_VS_WINCE_VERSION)
- set(id_definitions "ADD_MAINCRTSTARTUP")
+ set(id_entrypoint "mainACRTStartup")
+ set(id_subsystem 9)
+ else()
+ set(id_subsystem 1)
endif()
if("${CMAKE_MAKE_PROGRAM}" MATCHES "[Mm][Ss][Bb][Uu][Ii][Ll][Dd]")
set(build /p:Configuration=Debug /p:Platform=@id_arch@ /p:VisualStudioVersion=${vs_version}.0)
diff --git a/Modules/CTestUseLaunchers.cmake b/Modules/CTestUseLaunchers.cmake
index 6731d37..24f5f2e 100644
--- a/Modules/CTestUseLaunchers.cmake
+++ b/Modules/CTestUseLaunchers.cmake
@@ -35,7 +35,7 @@ if(NOT DEFINED CTEST_USE_LAUNCHERS AND DEFINED ENV{CTEST_USE_LAUNCHERS_DEFAULT})
CACHE INTERNAL "CTEST_USE_LAUNCHERS initial value from ENV")
endif()
-if(NOT "${CMAKE_GENERATOR}" MATCHES "Make")
+if(NOT "${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
set(CTEST_USE_LAUNCHERS 0)
endif()
diff --git a/Modules/CompilerId/VS-7.vcproj.in b/Modules/CompilerId/VS-7.vcproj.in
index b1449e4..fa48cad 100644
--- a/Modules/CompilerId/VS-7.vcproj.in
+++ b/Modules/CompilerId/VS-7.vcproj.in
@@ -24,7 +24,6 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- PreprocessorDefinitions="@id_definitions@"
MinimalRebuild="false"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@@ -35,8 +34,10 @@
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
+ IgnoreDefaultLibraryNames="libc"
GenerateDebugInformation="false"
- SubSystem="1"
+ SubSystem="@id_subsystem@"
+ EntryPointSymbol="@id_entrypoint@"
/>
<Tool
Name="VCPostBuildEventTool"
diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake
index b42247a..00e86e8 100644
--- a/Modules/FindQt4.cmake
+++ b/Modules/FindQt4.cmake
@@ -65,6 +65,10 @@
# is much more flexible, but requires that FindQt4.cmake is executed before
# such an exported dependency file is processed.
#
+# QT_INCLUDE_DIRS_NO_SYSTEM
+# If this variable is set to TRUE, the Qt include directories
+# in the QT_USE_FILE will NOT have the SYSTEM keyword set.
+#
# There are also some files that need processing by some Qt tools such as moc
# and uic. Listed below are macros that may be used to process those files.
#
diff --git a/Modules/FindSDL.cmake b/Modules/FindSDL.cmake
index f2e9f25..fec142e 100644
--- a/Modules/FindSDL.cmake
+++ b/Modules/FindSDL.cmake
@@ -122,7 +122,7 @@ if(SDL_LIBRARY_TEMP)
if(SDLMAIN_LIBRARY AND NOT SDL_BUILDING_LIBRARY)
list(FIND SDL_LIBRARY_TEMP "${SDLMAIN_LIBRARY}" _SDL_MAIN_INDEX)
if(_SDL_MAIN_INDEX EQUAL -1)
- list(APPEND SDL_LIBRARY_TEMP "${SDLMAIN_LIBRARY}")
+ set(SDL_LIBRARY_TEMP "${SDLMAIN_LIBRARY}" ${SDL_LIBRARY_TEMP})
endif()
unset(_SDL_MAIN_INDEX)
endif()
diff --git a/Modules/UseQt4.cmake b/Modules/UseQt4.cmake
index e8166f4..f05a3d5 100644
--- a/Modules/UseQt4.cmake
+++ b/Modules/UseQt4.cmake
@@ -25,7 +25,11 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_DEBUG)
endif()
-include_directories(${QT_INCLUDE_DIR})
+if(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(${QT_INCLUDE_DIR})
+else(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(SYSTEM ${QT_INCLUDE_DIR})
+endif(QT_INCLUDE_DIRS_NO_SYSTEM)
set(QT_LIBRARIES "")
set(QT_LIBRARIES_PLUGINS "")
@@ -89,7 +93,11 @@ foreach(module QT3SUPPORT QTOPENGL QTASSISTANT QTDESIGNER QTMOTIF QTNSPLUGIN
if(QT_USE_${module})
string(REPLACE "QT" "" qt_module_def "${module}")
add_definitions(-DQT_${qt_module_def}_LIB)
- include_directories(${QT_${module}_INCLUDE_DIR})
+ if(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(${QT_${module}_INCLUDE_DIR})
+ else(QT_INCLUDE_DIRS_NO_SYSTEM)
+ include_directories(SYSTEM ${QT_${module}_INCLUDE_DIR})
+ endif(QT_INCLUDE_DIRS_NO_SYSTEM)
endif()
set(QT_LIBRARIES ${QT_LIBRARIES} ${QT_${module}_LIBRARY})
set(QT_LIBRARIES_PLUGINS ${QT_LIBRARIES_PLUGINS} ${QT_${module}_PLUGINS})
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 942c0d0..a97bf61 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -2,5 +2,5 @@
set(CMake_VERSION_MAJOR 2)
set(CMake_VERSION_MINOR 8)
set(CMake_VERSION_PATCH 10)
-set(CMake_VERSION_TWEAK 20121203)
+set(CMake_VERSION_TWEAK 20121205)
#set(CMake_VERSION_RC 1)
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index fb3f39f..cd6a7ab 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -22,6 +22,20 @@ cmExportBuildFileGenerator::cmExportBuildFileGenerator()
//----------------------------------------------------------------------------
bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
{
+ {
+ std::string expectedTargets;
+ std::string sep;
+ for(std::vector<cmTarget*>::const_iterator
+ tei = this->Exports->begin();
+ tei != this->Exports->end(); ++tei)
+ {
+ expectedTargets += sep + this->Namespace + (*tei)->GetName();
+ sep = " ";
+ }
+
+ this->GenerateExpectedTargetsCode(os, expectedTargets);
+ }
+
// Create all the imported targets.
for(std::vector<cmTarget*>::const_iterator
tei = this->Exports->begin();
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 8dffae4..3f738cc 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -287,6 +287,37 @@ void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
}
//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
+ const std::string &expectedTargets)
+{
+ os << "SET(_targetsDefined)\n"
+ "SET(_targetsNotDefined)\n"
+ "SET(_expectedTargets)\n"
+ "FOREACH(_expectedTarget " << expectedTargets << ")\n"
+ " LIST(APPEND _expectedTargets ${_expectedTarget})\n"
+ " IF(NOT TARGET ${_expectedTarget})\n"
+ " LIST(APPEND _targetsNotDefined ${_expectedTarget})\n"
+ " ENDIF(NOT TARGET ${_expectedTarget})\n"
+ " IF(TARGET ${_expectedTarget})\n"
+ " LIST(APPEND _targetsDefined ${_expectedTarget})\n"
+ " ENDIF(TARGET ${_expectedTarget})\n"
+ "ENDFOREACH(_expectedTarget)\n"
+ "IF(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
+ " SET(CMAKE_IMPORT_FILE_VERSION)\n"
+ " CMAKE_POLICY(POP)\n"
+ " RETURN()\n"
+ "ENDIF(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
+ "IF(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
+ " MESSAGE(FATAL_ERROR \"Some (but not all) targets in this export "
+ "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
+ "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
+ "ENDIF(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
+ "UNSET(_targetsDefined)\n"
+ "UNSET(_targetsNotDefined)\n"
+ "UNSET(_expectedTargets)\n"
+ "\n\n";
+}
+//----------------------------------------------------------------------------
void
cmExportFileGenerator
::GenerateImportTargetCode(std::ostream& os, cmTarget* target)
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
index 70bc65d..4a75c52 100644
--- a/Source/cmExportFileGenerator.h
+++ b/Source/cmExportFileGenerator.h
@@ -63,6 +63,8 @@ protected:
void GenerateMissingTargetsCheckCode(std::ostream& os,
const std::vector<std::string>& missingTargets);
+ void GenerateExpectedTargetsCode(std::ostream& os,
+ const std::string &expectedTargets);
// Collect properties with detailed information about targets beyond
// their location on disk.
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index 7841731..6ba7d9f 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -39,6 +39,20 @@ std::string cmExportInstallFileGenerator::GetConfigImportFileGlob()
//----------------------------------------------------------------------------
bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
{
+ {
+ std::string expectedTargets;
+ std::string sep;
+ for(std::vector<cmTargetExport*>::const_iterator
+ tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
+ tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei)
+ {
+ expectedTargets += sep + this->Namespace + (*tei)->Target->GetName();
+ sep = " ";
+ }
+
+ this->GenerateExpectedTargetsCode(os, expectedTargets);
+ }
+
// Create all the imported targets.
for(std::vector<cmTargetExport*>::const_iterator
tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 5b1dfc8..15842e4 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -423,17 +423,19 @@ cmNinjaTargetGenerator
std::vector<std::string> compileCmds;
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
+ if(useClDeps)
+ {
+ std::string cmdPrefix = clDepsBinary + lang + " $in \"$DEP_FILE\" $out " +
+ clShowPrefix + clBinary;
+ compileCmds.front().insert(0, cmdPrefix);
+ }
+
for (std::vector<std::string>::iterator i = compileCmds.begin();
i != compileCmds.end(); ++i)
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
- std::string cmdLine;
- if(useClDeps)
- {
- cmdLine = clDepsBinary + lang + " $in \"$DEP_FILE\" $out " +
- clShowPrefix + clBinary;
- }
- cmdLine += this->GetLocalGenerator()->BuildCommandLine(compileCmds);
+ std::string cmdLine =
+ this->GetLocalGenerator()->BuildCommandLine(compileCmds);
// Write the rule for compiling file of the given language.
diff --git a/Source/cmVisualStudioWCEPlatformParser.cxx b/Source/cmVisualStudioWCEPlatformParser.cxx
index 0afcf67..b302246 100644
--- a/Source/cmVisualStudioWCEPlatformParser.cxx
+++ b/Source/cmVisualStudioWCEPlatformParser.cxx
@@ -15,18 +15,23 @@
int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version)
{
- std::string vskey = cmGlobalVisualStudioGenerator::GetRegistryBase(version);
- vskey += "\\Setup\\VS;ProductDir";
+ const std::string registryBase =
+ cmGlobalVisualStudioGenerator::GetRegistryBase(version);
+ const std::string vckey = registryBase + "\\Setup\\VC;ProductDir";
+ const std::string vskey = registryBase + "\\Setup\\VS;ProductDir";
- std::string vsInstallPath;
- if(!cmSystemTools::ReadRegistryValue(vskey.c_str(), vsInstallPath))
+ if(!cmSystemTools::ReadRegistryValue(vckey.c_str(), this->VcInstallDir) ||
+ !cmSystemTools::ReadRegistryValue(vskey.c_str(), this->VsInstallDir))
{
return 0;
}
- cmSystemTools::ConvertToUnixSlashes(vsInstallPath);
+ cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
+ cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
+ this->VcInstallDir.append("/");
+ this->VsInstallDir.append("/");
const std::string configFilename =
- vsInstallPath + "/VC/vcpackages/WCE.VCPlatform.config";
+ this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
return this->ParseFile(configFilename.c_str());
}
@@ -93,6 +98,24 @@ void cmVisualStudioWCEPlatformParser::StartElement(const char* name,
this->Macros[macroName] = macroValue;
}
}
+ else if(strcmp(name, "Directories") == 0)
+ {
+ for(const char** attr = attributes; *attr; attr += 2)
+ {
+ if(strcmp(attr[0], "Include") == 0)
+ {
+ this->Include = attr[1];
+ }
+ else if(strcmp(attr[0], "Library") == 0)
+ {
+ this->Library = attr[1];
+ }
+ else if(strcmp(attr[0], "Path") == 0)
+ {
+ this->Path = attr[1];
+ }
+ }
+ }
}
void cmVisualStudioWCEPlatformParser::EndElement(const char* name)
@@ -137,3 +160,16 @@ void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
{
this->CharacterData.append(data, length);
}
+
+std::string cmVisualStudioWCEPlatformParser::FixPaths(
+ const std::string& paths) const
+{
+ std::string ret = paths;
+ cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
+ cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
+ cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
+ cmSystemTools::ReplaceString(ret, "\\", "/");
+ cmSystemTools::ReplaceString(ret, "//", "/");
+ cmSystemTools::ReplaceString(ret, "/", "\\");
+ return ret;
+}
diff --git a/Source/cmVisualStudioWCEPlatformParser.h b/Source/cmVisualStudioWCEPlatformParser.h
index 28061fd..466e1dd 100644
--- a/Source/cmVisualStudioWCEPlatformParser.h
+++ b/Source/cmVisualStudioWCEPlatformParser.h
@@ -31,6 +31,12 @@ public:
bool Found() const {return this->FoundRequiredName;}
const char* GetArchitectureFamily() const;
std::string GetOSVersion() const;
+ std::string GetIncludeDirectories() const {
+ return this->FixPaths(this->Include); }
+ std::string GetLibraryDirectories() const {
+ return this->FixPaths(this->Library); }
+ std::string GetPathDirectories() const {
+ return this->FixPaths(this->Path); }
const std::vector<std::string>& GetAvailablePlatforms() const {
return this->AvailablePlatforms; }
@@ -40,8 +46,13 @@ protected:
void CharacterDataHandler(const char* data, int length);
private:
+ std::string FixPaths(const std::string& paths) const;
+
std::string CharacterData;
+ std::string Include;
+ std::string Library;
+ std::string Path;
std::string PlatformName;
std::string OSMajorVersion;
std::string OSMinorVersion;
@@ -50,6 +61,8 @@ private:
const char* RequiredName;
bool FoundRequiredName;
+ std::string VcInstallDir;
+ std::string VsInstallDir;
};
#endif
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 1424a11..fba4860 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -82,6 +82,7 @@
#if defined(CMAKE_HAVE_VS_GENERATORS)
#include "cmCallVisualStudioMacro.h"
+#include "cmVisualStudioWCEPlatformParser.h"
#endif
#if !defined(CMAKE_BOOT_MINGW)
@@ -1143,6 +1144,10 @@ void CMakeCommandUsage(const char* program)
<< "Available on Windows only:\n"
<< " comspec - on windows 9x use this for RunCommand\n"
<< " delete_regv key - delete registry value\n"
+ << " env_vs8_wince sdkname - displays a batch file which sets the "
+ "environment for the provided Windows CE SDK installed in VS2005\n"
+ << " env_vs9_wince sdkname - displays a batch file which sets the "
+ "environment for the provided Windows CE SDK installed in VS2008\n"
<< " write_regv key value - write registry value\n"
#else
<< "Available on UNIX only:\n"
@@ -1808,6 +1813,14 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
}
return cmWin32ProcessExecution::Windows9xHack(command.c_str());
}
+ else if (args[1] == "env_vs8_wince" && args.size() == 3)
+ {
+ return cmake::WindowsCEEnvironment("8.0", args[2]);
+ }
+ else if (args[1] == "env_vs9_wince" && args.size() == 3)
+ {
+ return cmake::WindowsCEEnvironment("9.0", args[2]);
+ }
#endif
}
@@ -4001,6 +4014,29 @@ static bool cmakeCheckStampList(const char* stampList)
return true;
}
+//----------------------------------------------------------------------------
+int cmake::WindowsCEEnvironment(const char* version, const std::string& name)
+{
+#if defined(CMAKE_HAVE_VS_GENERATORS)
+ cmVisualStudioWCEPlatformParser parser(name.c_str());
+ parser.ParseVersion(version);
+ if (parser.Found())
+ {
+ std::cout << "@echo off" << std::endl;
+ std::cout << "echo Environment Selection: " << name << std::endl;
+ std::cout << "set PATH=" << parser.GetPathDirectories() << std::endl;
+ std::cout << "set INCLUDE=" << parser.GetIncludeDirectories() <<std::endl;
+ std::cout << "set LIB=" << parser.GetLibraryDirectories() <<std::endl;
+ return 0;
+ }
+#else
+ (void)version;
+#endif
+
+ std::cerr << "Could not find " << name;
+ return -1;
+}
+
// For visual studio 2005 and newer manifest files need to be embeded into
// exe and dll's. This code does that in such a way that incremental linking
// still works.
diff --git a/Source/cmake.h b/Source/cmake.h
index 79e05ca..e5aa076 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -445,6 +445,8 @@ protected:
std::string const& link);
static int ExecuteEchoColor(std::vector<std::string>& args);
static int ExecuteLinkScript(std::vector<std::string>& args);
+ static int WindowsCEEnvironment(const char* version,
+ const std::string& name);
static int VisualStudioLink(std::vector<std::string>& args, int type);
static int VisualStudioLinkIncremental(std::vector<std::string>& args,
int type,
diff --git a/Utilities/cmlibarchive/libarchive/archive_endian.h b/Utilities/cmlibarchive/libarchive/archive_endian.h
index bbf58fd..3c039f7 100644
--- a/Utilities/cmlibarchive/libarchive/archive_endian.h
+++ b/Utilities/cmlibarchive/libarchive/archive_endian.h
@@ -64,7 +64,13 @@ archive_be16dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
- return ((p[0] << 8) | p[1]);
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p0 << 8) | p1);
}
static inline uint32_t
@@ -72,7 +78,15 @@ archive_be32dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
- return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p3 = p[3];
+ unsigned int p2 = p[2];
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p0 << 24) | (p1 << 16) | (p2 << 8) | p3);
}
static inline uint64_t
@@ -88,7 +102,13 @@ archive_le16dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
- return ((p[1] << 8) | p[0]);
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p1 << 8) | p0);
}
static inline uint32_t
@@ -96,7 +116,15 @@ archive_le32dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
- return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+ /* Store into unsigned temporaries before left shifting, to avoid
+ promotion to signed int and then left shifting into the sign bit,
+ which is undefined behaviour. */
+ unsigned int p3 = p[3];
+ unsigned int p2 = p[2];
+ unsigned int p1 = p[1];
+ unsigned int p0 = p[0];
+
+ return ((p3 << 24) | (p2 << 16) | (p1 << 8) | p0);
}
static inline uint64_t