mirror of https://github.com/rusefi/openblt.git
Refs #320. Refactored the XCP Seed and Key shared library. Its build system is now based on CMake and it is cross-platform.
git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@379 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
parent
40f5406c80
commit
88855a5f7a
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,15 @@
|
|||
:: Batch file to generate a reference manual from the comments in the source code, with
|
||||
:: Doxygen. The following tools should be installed and added to the path:
|
||||
:: - DoxyGen (doxygen.exe)
|
||||
:: - Graphviz (dot.exe)
|
||||
:: - MikTex (pdflatex.exe)
|
||||
:: - HTML Help Workshop compiler (hhc.exe)
|
||||
if exist ..\RM_SeedNKey.pdf del ..\RM_SeedNKey.pdf
|
||||
if exist ..\RM_SeedNKey.chm del ..\RM_SeedNKey.chm
|
||||
doxygen.exe DoxyfileSeedNKey
|
||||
call .\output\SeedNKey\latex\make.bat
|
||||
call copy .\output\SeedNKey\latex\refman.pdf ..\RM_SeedNKey.pdf
|
||||
:: Remove the comment on the next line to automatically open the generated PDF file
|
||||
:: call start "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" ..\RM_SeedNKey.pdf
|
||||
:: Remove the comment on the next line to automatically open the generated CHM file
|
||||
:: start .\..\RM_SeedNKey.chm
|
Binary file not shown.
|
@ -365,7 +365,7 @@ begin
|
|||
// create ini file object
|
||||
settingsIni := TIniFile.Create(iniFile);
|
||||
|
||||
FSeedKeyDll := settingsIni.ReadString('xcp', 'seedkey', ExtractFilePath(ParamStr(0))+'FeaserKey.dll');
|
||||
FSeedKeyDll := settingsIni.ReadString('xcp', 'seedkey', ExtractFilePath(ParamStr(0))+'libseednkey.dll');
|
||||
|
||||
// if no path specified, then assume dll is located in the executable's path
|
||||
if ExtractFilePath(FSeedKeyDll) = '' then
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
/************************************************************************************//**
|
||||
* \file SeedNKey.cpp
|
||||
* \brief XCP Seed/Key algorithms
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2014 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/****************************************************************************************
|
||||
* Type definitions
|
||||
****************************************************************************************/
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Defines
|
||||
****************************************************************************************/
|
||||
/* XCP dll function type info */
|
||||
#define XCP_DLL_EXPORT __declspec(dllexport) __cdecl
|
||||
|
||||
/* XCP supported resources */
|
||||
#define kXcpResPGM 0x10 /* ProGraMing */
|
||||
#define kXcpResSTIM 0x08 /* data STIMulation */
|
||||
#define kXcpResDAQ 0x04 /* Data AcQuisition */
|
||||
#define kXcpResCALPAG 0x01 /* CALibration and PAGing */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
** NAME: XCP_ComputeKeyFromSeed
|
||||
** PARAMETER: resource : resource for which the unlock key is requested
|
||||
** seedLen : length of the seed
|
||||
** seedPtr : pointer to the seed data
|
||||
** keyLenPtr: pointer where to store the key length
|
||||
** keyPtr : pointer where to store the key data
|
||||
** RETURN VALUE: 0: success, 1: error
|
||||
** DESCRIPTION: Computes the key for the requested resource.
|
||||
**
|
||||
****************************************************************************************/
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Computes the key for the requested resource.
|
||||
** \param resource resource for which the unlock key is requested
|
||||
** \param seedLen length of the seed
|
||||
** \param seedPtr pointer to the seed data
|
||||
** \param keyLenPtr pointer where to store the key length
|
||||
** \param keyPtr pointer where to store the key data
|
||||
** \return 0 on success, otherwise 1.
|
||||
**
|
||||
****************************************************************************************/
|
||||
DWORD XCP_DLL_EXPORT XCP_ComputeKeyFromSeed( BYTE resource, BYTE seedLen, BYTE *seedPtr,
|
||||
BYTE *keyLenPtr, BYTE *keyPtr)
|
||||
{
|
||||
BYTE i;
|
||||
|
||||
/* Feaser XCP driver example key algorithm for PGM simply
|
||||
* decrements the value of each seed by 1
|
||||
*/
|
||||
if ( resource == kXcpResPGM )
|
||||
{
|
||||
/* compute the key */
|
||||
for ( i=0; i<seedLen; i++)
|
||||
{
|
||||
keyPtr[i] = seedPtr[i] - 1;
|
||||
}
|
||||
|
||||
/* set the key length */
|
||||
*keyLenPtr = seedLen;
|
||||
|
||||
/* done */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* still here, so the resource was unsupported */
|
||||
return 1;
|
||||
} /*** end of XCP_ComputeKeyFromSeed ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Computes the key for the requested resource.
|
||||
** \param resourcePtr pointer where to store the supported resources for the key
|
||||
** computation.
|
||||
** \return 0 on success, otherwise 1.
|
||||
**
|
||||
****************************************************************************************/
|
||||
DWORD XCP_DLL_EXPORT XCP_GetAvailablePrivileges( BYTE *resourcePtr)
|
||||
{
|
||||
/* this dll supports key computation algorithm for the PGM resource */
|
||||
*resourcePtr = (kXcpResPGM);
|
||||
|
||||
return 0;
|
||||
} /*** end of XCP_GetAvailablePrivileges ***/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************** end of SeedNKey.cpp *******************************/
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Express 2013 for Windows Desktop
|
||||
VisualStudioVersion = 12.0.31101.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SeedNKey", "SeedNKey.vcxproj", "{8292CD77-57FC-42DB-BE82-58ACD4A63BFD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8292CD77-57FC-42DB-BE82-58ACD4A63BFD}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{8292CD77-57FC-42DB-BE82-58ACD4A63BFD}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{8292CD77-57FC-42DB-BE82-58ACD4A63BFD}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{8292CD77-57FC-42DB-BE82-58ACD4A63BFD}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Binary file not shown.
|
@ -1,87 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="SeedNKey.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{8292CD77-57FC-42DB-BE82-58ACD4A63BFD}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>SeedNKey</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>.\..\..\..\</OutDir>
|
||||
<TargetName>FeaserKey</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;SEEDNKEY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;SEEDNKEY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,133 @@
|
|||
#****************************************************************************************
|
||||
# \file CMakeLists.txt
|
||||
# \brief CMake descriptor file for the XCP Seed and Key shared library.
|
||||
# \internal
|
||||
#----------------------------------------------------------------------------------------
|
||||
# C O P Y R I G H T
|
||||
#----------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 by Feaser http://www.feaser.com All rights reserved
|
||||
#
|
||||
#----------------------------------------------------------------------------------------
|
||||
# L I C E N S E
|
||||
#----------------------------------------------------------------------------------------
|
||||
# This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
# PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
# should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
#
|
||||
# \endinternal
|
||||
#****************************************************************************************
|
||||
# Specify the version being used aswell as the language
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
|
||||
#****************************************************************************************
|
||||
# Project configuration
|
||||
#****************************************************************************************
|
||||
# Specify the project name
|
||||
project(seednkey)
|
||||
|
||||
# Build debug version by default
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
|
||||
|
||||
#****************************************************************************************
|
||||
# Options
|
||||
#****************************************************************************************
|
||||
# Add option with default value to disable the generation of the PC-lint target. It can
|
||||
# be overridden on the command line when CMake is called using the following parameter:
|
||||
# -DLINT_ENABLED=ON
|
||||
option(LINT_ENABLED "Configurable to enable/disable the PC-lint target" OFF)
|
||||
|
||||
|
||||
#****************************************************************************************
|
||||
# Directories
|
||||
#****************************************************************************************
|
||||
# Set the output directory
|
||||
set (PROJECT_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../../..)
|
||||
|
||||
# Set the output directory for the generic no-config case (e.g. with mingw)
|
||||
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIRECTORY} )
|
||||
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIRECTORY} )
|
||||
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIRECTORY} )
|
||||
# Set the output directory for multi-config builds (e.g. msvc)
|
||||
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
|
||||
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
|
||||
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_OUTPUT_DIRECTORY} )
|
||||
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_OUTPUT_DIRECTORY} )
|
||||
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_OUTPUT_DIRECTORY} )
|
||||
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
|
||||
|
||||
|
||||
#****************************************************************************************
|
||||
# Compiler flags
|
||||
#****************************************************************************************
|
||||
# Set platform specific compiler macro PLATFORM_XXX
|
||||
if(WIN32)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WIN32 -D_CRT_SECURE_NO_WARNINGS")
|
||||
elseif(UNIX)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_LINUX -std=gnu99")
|
||||
endif(WIN32)
|
||||
|
||||
|
||||
#***************************************************************************************
|
||||
# Includes
|
||||
#****************************************************************************************
|
||||
# Set include directories
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
|
||||
|
||||
#***************************************************************************************
|
||||
# Files
|
||||
#****************************************************************************************
|
||||
# Get header files from the root directory
|
||||
file(GLOB INCS_ROOT "*.h")
|
||||
set(INCS ${INCS_ROOT})
|
||||
|
||||
# Add sources
|
||||
set(
|
||||
LIB_SRCS
|
||||
seednkey.c
|
||||
${INCS}
|
||||
)
|
||||
|
||||
|
||||
#***************************************************************************************
|
||||
# Targets
|
||||
#****************************************************************************************
|
||||
# Set main target. Use "make seednkey_shared" to individually build the shared library.
|
||||
add_library(seednkey_shared SHARED ${LIB_SRCS})
|
||||
if(CMAKE_C_COMPILER_ID MATCHES MSVC)
|
||||
# Microsoft Visual Studio does not add "lib" to the name of the DLL, whereas GCC
|
||||
# (including MinGW) does. Correct this here.
|
||||
SET_TARGET_PROPERTIES(seednkey_shared PROPERTIES OUTPUT_NAME libseednkey CLEAN_DIRECT_OUTPUT 1)
|
||||
else()
|
||||
SET_TARGET_PROPERTIES(seednkey_shared PROPERTIES OUTPUT_NAME seednkey CLEAN_DIRECT_OUTPUT 1)
|
||||
endif()
|
||||
|
||||
# Only generate the PC-lint taget if the option is enabled. Use "make seednkey_LINT" to
|
||||
# lint the project sources
|
||||
if(LINT_ENABLED)
|
||||
# Include PC-lint configuration file for the correct compiler. Currently GNU GCC and
|
||||
# Microsoft Visual Studio are supported.
|
||||
if(CMAKE_C_COMPILER_ID MATCHES GNU)
|
||||
include(${PROJECT_SOURCE_DIR}/lint/gnu/pc_lint.cmake)
|
||||
elseif(CMAKE_C_COMPILER_ID MATCHES MSVC)
|
||||
include(${PROJECT_SOURCE_DIR}/lint/msvc/pc_lint.cmake)
|
||||
endif()
|
||||
|
||||
# Generate the PC-lint target.
|
||||
if(COMMAND add_pc_lint)
|
||||
add_pc_lint(seednkey ${LIB_SRCS})
|
||||
endif(COMMAND add_pc_lint)
|
||||
endif(LINT_ENABLED)
|
||||
|
||||
|
||||
#*********************************** end of CMakeLists.txt ******************************
|
|
@ -0,0 +1,129 @@
|
|||
// ---------------------------------------------------------------------
|
||||
// This file is provided by Gimpel Software (www.gimpel.com) for use with
|
||||
// its products PC-lint and FlexeLint.
|
||||
//
|
||||
// Redistribution and use of this file, with or without modification, is
|
||||
// permitted provided that any such redistribution retains this notice.
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#ifndef CO_GCC_H_
|
||||
#define CO_GCC_H_
|
||||
/*lint -save -w1 */
|
||||
|
||||
#ifdef _lint /* Make sure no compiler comes this way */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Standard library headers typically define the assert macro so that it
|
||||
expands to a complicated conditional expression that uses special
|
||||
funtions that Lint does not know about by default. For linting
|
||||
purposes, we can simplify things a bit by forcing assert() to expand to
|
||||
a call to a special function that has the appropriate 'assert'
|
||||
semantics.
|
||||
*/
|
||||
//lint -function( __assert, __lint_assert )
|
||||
void __lint_assert( int );
|
||||
//lint ++d"assert(e)=__lint_assert(!!(e))"
|
||||
//(++d makes this definition permanently immutable for the Lint run.)
|
||||
//Now that we've made our own 'assert', we need to keep people from being
|
||||
//punished when the marco in 'assert.h' appears not to be used:
|
||||
//lint -efile(766,*assert.h)
|
||||
|
||||
typedef char *__builtin_va_list;
|
||||
|
||||
/*lint -e{171} */
|
||||
__builtin_va_list __lint_init_va(...);
|
||||
|
||||
void __builtin_va_end( __builtin_va_list );
|
||||
/*lint
|
||||
++d"__builtin_va_start(ap,parmN)=((ap)=__lint_init_va(parmN))"
|
||||
++d"__builtin_va_arg(a,b)=(*( ((b) *) ( (((a) += sizeof(b)) - sizeof(b) )))"
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
The headers included below must be generated; For C++, generate
|
||||
with:
|
||||
|
||||
g++ [usual build options] -E -dM t.cpp >lint_cppmac.h
|
||||
|
||||
For C, generate with:
|
||||
|
||||
gcc [usual build options] -E -dM t.c >lint_cmac.h
|
||||
|
||||
...where "t.cpp" and "t.c" are empty source files.
|
||||
|
||||
It's important to use the same compiler options used when compiling
|
||||
project code because they can affect the existence and precise
|
||||
definitions of certain predefined macros. See gcc-readme.txt for
|
||||
details and a tutorial.
|
||||
*/
|
||||
#if defined(__cplusplus)
|
||||
# include "lint_cppmac.h" // DO NOT COMMENT THIS OUT. DO NOT SUPPRESS ERROR 322. (If you see an error here, your Lint configuration is broken; check -i options and ensure that you have generated lint_cppmac.h as documented in gcc-readme.txt. Otherwise Gimpel Software cannot support your configuration.)
|
||||
#else
|
||||
# include "lint_cmac.h" // DO NOT COMMENT THIS OUT. DO NOT SUPPRESS ERROR 322. (If you see an error here, your Lint configuration is broken; check -i options and ensure that you have generated lint_cmac.h as documented in gcc-readme.txt. Otherwise Gimpel Software cannot support your configuration.)
|
||||
#endif
|
||||
|
||||
/* If the macro set given by the generated macro files must be adjusted in
|
||||
order for Lint to cope, then you can make those adjustments here.
|
||||
*/
|
||||
|
||||
#define LINT_CO_GCC_H_GCC_VERSION ( __GNUC__ * 10000 + \
|
||||
__GNUC_MINOR__ * 100 + \
|
||||
__GNUC_PATCHLEVEL__ )
|
||||
|
||||
/* The following is a workaround for versions of GCC with bug 25717, in
|
||||
which the preprocessor does not dump a #define directive for __STDC__
|
||||
when -dM is given:
|
||||
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25717
|
||||
|
||||
We know the unconditional definition of __STDC__ was introduced no
|
||||
later than version 3.0; the preprocessor bug was fixed no later than
|
||||
version 4.1.0.
|
||||
*/
|
||||
#if ( LINT_CO_GCC_H_GCC_VERSION >= 30000 && \
|
||||
LINT_CO_GCC_H_GCC_VERSION < 40100 )
|
||||
# define __STDC__ 1
|
||||
#endif
|
||||
|
||||
#if !__cplusplus && !__STRICT_ANSI__ && __STDC_VERSION__ < 199901L
|
||||
/* apparently, the code is compiled with -std=gnu89 (as opposed to -std=c89),
|
||||
so: */
|
||||
/*lint -rw_asgn(inline,__inline) */
|
||||
#endif
|
||||
|
||||
#if LINT_CO_GCC_H_GCC_VERSION >= 40300
|
||||
# define __COUNTER__ __lint__COUNTER__
|
||||
//lint +rw( *type_traits ) // Enable type traits support
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#if _lint >= 909 // For 9.00i and later:
|
||||
//// __attribute__ is GCC's __attribute__:
|
||||
//
|
||||
//lint -rw_asgn(__attribute__,__gcc_attribute__)
|
||||
//lint -rw_asgn(__attribute, __gcc_attribute__)
|
||||
//
|
||||
//// Prevent "__attribute__" from being defined as a macro:
|
||||
//
|
||||
//lint --u"__attribute__"
|
||||
//lint --u"__attribute"
|
||||
//
|
||||
//// Because an attribute-specifier is a form of
|
||||
//// declaration-modifier, and because it can appear at the
|
||||
//// beginning of a decl-specifier-seq, we must enable "Early
|
||||
//// Modifiers":
|
||||
//
|
||||
//lint +fem
|
||||
#else // for 9.00h and earlier:
|
||||
//lint -d__attribute__()=
|
||||
//lint -d__attribute()=
|
||||
#endif
|
||||
|
||||
#endif /* _lint */
|
||||
/*lint -restore */
|
||||
#endif /* CO_GCC_H_ */
|
|
@ -0,0 +1,212 @@
|
|||
/* Date Stamp */ -d"_lint_co_gcc_lnt=co-gcc.lnt modified 12-Jun-2014"
|
||||
/* To document usage use: -message( "Using " _lint_co_gcc_lnt ) */
|
||||
// ---------------------------------------------------------------------
|
||||
// This file is provided by Gimpel Software (www.gimpel.com) for use with
|
||||
// its products PC-lint and FlexeLint.
|
||||
//
|
||||
// Redistribution and use of this file, with or without modification, is
|
||||
// permitted provided that any such redistribution retains this notice.
|
||||
// ---------------------------------------------------------------------
|
||||
/* co-gcc.lnt: This is the seed file for configuring Lint for use with
|
||||
GCC versions 2.95.3 and later.
|
||||
|
||||
Like all compiler options files this file is intended to be used
|
||||
as follows:
|
||||
|
||||
lint co-gcc.lnt source-files-to-be-linted
|
||||
|
||||
Some of the information that co-gcc.lnt requires needs to be furnished
|
||||
with the help of the gcc system itself. The easiest way to generate
|
||||
this information is to use the makefile co-gcc.mak (supplied with the
|
||||
Lint distribution) in an invocation of GNU Make; for details, see the
|
||||
commentary at the top of co-gcc.mak.
|
||||
*/
|
||||
|
||||
-cgnu // Notifies FlexeLint that gcc is being used.
|
||||
|
||||
// ===========================
|
||||
// Preprocessor Configuration:
|
||||
+fdi // GCC starts its #include search in the directory of the including
|
||||
// file.
|
||||
|
||||
++fln // Allow:
|
||||
// # digit-sequence " [s-char-sequence] " new-line
|
||||
// as a synonym for:
|
||||
// # line digit-sequence " [s-char-sequence] " new-line
|
||||
// GCC additionally allows flag values to follow the
|
||||
// s-char-sequence, but currently Lint ignores them.
|
||||
|
||||
-header(co-gcc.h) // Includes headers generated by GCC (bringing in
|
||||
// predefined macros).
|
||||
+libh(co-gcc.h) // Marks that header as library code.
|
||||
|
||||
gcc-include-path.lnt // This .lnt file should contain --i options
|
||||
// and should be generated by invoking gcc with its '-v' option.
|
||||
// (GCC's implicit #include search path is presented in the output.)
|
||||
// This happens automatically when 'make -f co-gcc.mak' is invoked.
|
||||
|
||||
// Assertion directives (a feature of GCC's preprocessor) have been
|
||||
// considered obsolete in GCC's documentation since version 3.0, so we do
|
||||
// not use them here. If support for #assert is needed in the form of a
|
||||
// lint option, one may use '-a#' like so:
|
||||
// -a#machine(i386) // #assert's machine(i386) (SVR4 facility).
|
||||
|
||||
// File extensions:
|
||||
// From the GCC man page:
|
||||
//
|
||||
// file.cc
|
||||
// file.cp
|
||||
// file.cxx
|
||||
// file.cpp
|
||||
// file.CPP
|
||||
// file.c++
|
||||
// file.C
|
||||
// C++ source code that must be preprocessed. Note that in .cxx, the
|
||||
// last two letters must both be literally x. Likewise, .C refers to
|
||||
// a literal capital C.
|
||||
//
|
||||
// We emulate this with:
|
||||
|
||||
+cpp(.cc)
|
||||
+cpp(.cp)
|
||||
+cpp(.cxx)
|
||||
+cpp(.cpp)
|
||||
+cpp(.c++)
|
||||
// Note the exceptions:
|
||||
// +cpp(.CPP)
|
||||
// +cpp(.C)
|
||||
// These are commented out for the default config because they seem to
|
||||
// cause trouble more often than not. For starters, it is problematic
|
||||
// with filesystems that are case-insensitive (which has become common
|
||||
// even on some POSIX systems).
|
||||
|
||||
// =============
|
||||
// Size Options:
|
||||
// +fwc // wchar_t might be builtin; if so, uncomment this option. (NOTE:
|
||||
// // this option needs to be set before a size option is given for
|
||||
// // wchar_t; see the documentation for -sw# in the Lint manual.)
|
||||
|
||||
size-options.lnt // This .lnt file should be generated (preferrably
|
||||
// by a program created by invoking GCC with the compile options that
|
||||
// are used in the compilation of the project to be linted). This
|
||||
// happens automatically when 'make -f co-gcc.mak' is invoked.
|
||||
|
||||
|
||||
// ===========================================
|
||||
// +rw and -d options to cope with GNU syntax:
|
||||
+ppw(ident) // Tolerate #ident
|
||||
+ppw(warning)
|
||||
|
||||
// GCC provides alternative spellings of certain keywords:
|
||||
+rw(__inline)
|
||||
-rw_asgn(__inline__,__inline)
|
||||
-rw_asgn(__header_always_inline,__inline)
|
||||
-rw_asgn(__header_inline,__inline)
|
||||
|
||||
-rw_asgn(__signed__,signed)
|
||||
-rw_asgn(__signed,signed)
|
||||
-rw_asgn( __volatile__, volatile )
|
||||
-rw_asgn( __volatile, volatile )
|
||||
+rw(restrict)
|
||||
-rw_asgn(__restrict,restrict)
|
||||
-rw_asgn(__restrict__,restrict)
|
||||
++d"__const=const" // gconv.h uses __const rather than const
|
||||
++d"const=const" // ensure const expands to const.
|
||||
|
||||
-rw_asgn( asm, _up_to_brackets )
|
||||
-rw_asgn( __asm, _up_to_brackets )
|
||||
-rw_asgn( __asm__, _up_to_brackets )
|
||||
// This re-definition of the various spellings of the asm keyword enables
|
||||
// Lint to pass gracefully over expression-statements like:
|
||||
// __asm __volatile ("fsqrt" : "=t" (__result) : "0" (__x));
|
||||
// But it may be necessary to suppress certain error messages that are
|
||||
// triggered by tokens that are part of an assembly declaration or
|
||||
// statement. For example:
|
||||
|
||||
-d"__asm__(p...)=/*lint -e{19}*/ __asm__(p)"
|
||||
|
||||
// ...causes Lint to be quiet about the semicolon that follows an
|
||||
// __asm__() declaration. Note, the -e{N} form of suppression takes
|
||||
// effect only for the forward-declaration, definition or
|
||||
// [possibly-compound] statement that immediately follows. Because a
|
||||
// semicolon is seen as a declaration-terminator, Error 19 will be
|
||||
// re-enabled immediately after the semicolon in '__asm__(...);'.
|
||||
// (The elipsis after the macro parameter p allows zero or more commas to
|
||||
// appear in the operand.)
|
||||
//
|
||||
// If you encounter other diagnostics that appear to need suppression in
|
||||
// or near assembly regions, please let us know!
|
||||
//
|
||||
-esym(123,__asm__)
|
||||
|
||||
-rw_asgn(__alignof__,__alignof)
|
||||
|
||||
// "__extension__" is GCC's way of allowing the use of non-standard
|
||||
// constructs in a strict Standard-conforming mode. We don't currently
|
||||
// have explicit support for it, but we can use local suppressions. For
|
||||
// example, we can use -e(160) so that we will not see any Errors about
|
||||
// GNU statement-expressions wrapped in __extension__().
|
||||
++d"__extension__=/*lint -e(160) */"
|
||||
|
||||
++d"__null=0"
|
||||
+rw(_to_semi) // needed for the two macros above.
|
||||
+rw(__typeof__) // activate __typeof__ keyword
|
||||
-d"__typeof=__typeof__" // an alternative to using __typeof__
|
||||
|
||||
-rw(__except) // This MS reserved word is used as an identifier
|
||||
+rw( __complex__, __real__, __imag__ ) // reserved words that can be ignored.
|
||||
++d"__builtin_strchr=(char*)" // permits the inline definition ...
|
||||
++d"__builtin_strpbrk=(char*)" // of these functions to be linted ...
|
||||
++d"__builtin_strrchr=(char*)" // without drawing a complaint
|
||||
++d"__builtin_strstr=(char*)" // about the use of a non-standard name
|
||||
++d"__PRETTY_FUNCTION__=___function___" // lint defines ___function___ internally
|
||||
++d"__FUNCTION__=___function___" // lint defines ___function___ internally
|
||||
++d"__func__=___function___" // Some C++ modes suport the implicit __func__
|
||||
// identifier.
|
||||
-ident($)
|
||||
|
||||
// =========================================================
|
||||
// Other options supporting GNU C/C++ syntax:
|
||||
+fld // enables the processing of _L_abel _D_esignators E.g.:
|
||||
// union { double d; int i; } u = { d: 3.141 };
|
||||
|
||||
// =========================================================
|
||||
// Generally useful suppressions:
|
||||
-wlib(1) // sets the warning level within library headers to 1
|
||||
// (no warnings, just syntax errors). Comment out if you
|
||||
// are actually linting library headers.
|
||||
-elib(123) // 123 is really a warning, but it's in the "Error" range.
|
||||
-elib(93) // allow newlines within quoted string arguments to macros
|
||||
-elib(46) // allow bit fields to have integral types other than
|
||||
// '_Bool' and 'int'.
|
||||
-elibsym(793) // suppress warning about limit of 31 significant characters
|
||||
-elibsym(628) // Suppress 628 for __builtin symbols.
|
||||
|
||||
-esym(528,__huge_val,__nan,__qnan,__qnanf,__snan,__snanf)
|
||||
// We don't care if we don't reference some GNU functions
|
||||
-esym(528,__gnu_malloc,__gnu_calloc)
|
||||
|
||||
// The following functions exhibit variable return modes.
|
||||
// That is, they may equally-usefully be called for a value
|
||||
// as called just for their effects. Accordingly we inhibit
|
||||
// Warning 534 for these functions.
|
||||
// Feel free to add to or subtract from this list.
|
||||
|
||||
-esym(534,close,creat,fclose,fprintf,fputc)
|
||||
-esym(534,fputs,fscanf,fseek,fwrite,lseek,memcpy,memmove,memset)
|
||||
-esym(534,printf,puts,scanf,sprintf,sscanf,strcat,strcpy)
|
||||
-esym(534,strncat,strncpy,unlink,write)
|
||||
|
||||
// For non-ANSI compilers we suppress messages 515 and 516
|
||||
// for functions known to have variable argument lists.
|
||||
// For ANSI compilers, header files should take care of this.
|
||||
|
||||
-esym(515,fprintf,printf,sprintf,fscanf,scanf,sscanf)
|
||||
-esym(516,fprintf,printf,sprintf,fscanf,scanf,sscanf)
|
||||
-esym(1702,*operator<<,*operator>>)
|
||||
-esym(534,*operator<<,*operator>>)
|
||||
-esym(1055,*__builtin*)
|
||||
-esym(718,*__builtin*) // The compiler does not need these ...
|
||||
-esym(746,*__builtin*) // declared and it knows their prototypes.
|
||||
-esym(793, pthread_mutexattr_getprioceiling, pthread_mutexattr_setprioceiling)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
--i/usr/lib/gcc/x86_64-linux-gnu/6/include
|
||||
--i/usr/local/include
|
||||
--i/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed
|
||||
--i/usr/include/x86_64-linux-gnu
|
||||
--i/usr/include
|
||||
|
|
@ -0,0 +1,319 @@
|
|||
|
||||
Using FlexeLint with GCC
|
||||
|
||||
These notes describe how to use the option file co-gcc.lnt which serves
|
||||
as a replacement for the older co-gnu.lnt and co-gnu3.lnt options files.
|
||||
|
||||
--- Quick Start ---
|
||||
|
||||
If you just want a quick-and-dirty Lint configuration (one that enables
|
||||
you to use Standard Library headers and system headers) then use the
|
||||
makefile 'co-gcc.mak' (supplied with the Lint distribution) in an
|
||||
invocation of GNU Make like so:
|
||||
|
||||
make -f co-gcc.mak
|
||||
|
||||
... which should generate the following files (provided that 'gcc', 'g++'
|
||||
and 'awk' are each found in your $PATH):
|
||||
|
||||
lint_cmac.h
|
||||
lint_cppmac.h
|
||||
gcc-include-path.lnt
|
||||
size-options.lnt
|
||||
|
||||
(co-gcc.lnt depends on these files, so they must be generated before you
|
||||
do anything else.)
|
||||
|
||||
That's it! You should now be able to run:
|
||||
|
||||
flint co-gcc.lnt [source files]
|
||||
|
||||
Note that Lint must be able to find co-gcc.lnt and the files referenced
|
||||
therein. If you want to keep them in a separate directory (e.g.,
|
||||
/usr/local/etc/flint) from the one where you will invoke Lint (e.g.,
|
||||
~/some-project/src), you'll need to specify the former with a '-i' option
|
||||
so that Lint will know where to look. In that case, the invocation would
|
||||
look like:
|
||||
|
||||
flint -i /usr/local/etc/flint co-gcc.lnt [source files]
|
||||
|
||||
If your project is compiled without any explicit command-line switches
|
||||
other than '-c' then this invocation alone might be all that you need to
|
||||
get started linting your project. Otherwise it probably won't suffice.
|
||||
For a Lint configuration that better matches the way you compile your
|
||||
code, you should at least read the 'usage' note at the top of co-gcc.mak.
|
||||
|
||||
For a motivation for the contents of co-gcc.mak, and to better understand
|
||||
the configuration issues in general, please read on.
|
||||
|
||||
--- Introduction ---
|
||||
|
||||
The configuration of Lint for use with GCC-compiled sources is complicated
|
||||
by two major issues:
|
||||
|
||||
First, GCC defines a large number of preprocessor macros internally (i.e.,
|
||||
it defines a lot of macros for which there are no '#define' directives in
|
||||
any source file that Lint can read.). Unless this issue is resolved for
|
||||
each project, Lint will not see the same sequence of C/C++ tokens as GCC
|
||||
when it tries to analyze your program, and as a result it will not see the
|
||||
same set of declarations; consequently you'll see lots of spurious
|
||||
messages because the analysis will reflect that of a program that is
|
||||
truly ill-formed (unlike the program seen by GCC).
|
||||
|
||||
Second, GCC is aware of several built-in functions. Most of them can be
|
||||
presented to Lint as ordinary forward-declarations of functions so as to
|
||||
avoid undesired diagnostics claiming that these functions were not
|
||||
declared before the first point of use. Note, these declarations do not
|
||||
necessarily need to be presented to GCC.
|
||||
|
||||
--- Solving the Preprocessor Problem ---
|
||||
|
||||
Before we get started, we'll need an empty C source file. Call it
|
||||
'empty.c' and save it to disk. Next, use your favorite command
|
||||
interpreter environment (such as sh in Unix-like environments or cmd.exe
|
||||
on Windows) and go to the directory containing 'empty.c'. Verify that you
|
||||
can run GCC by doing the following:
|
||||
|
||||
gcc -v
|
||||
|
||||
If your environment is properly set up you should see a version string.
|
||||
(You'll also want to verify that this is the same GCC executable used to
|
||||
compile your sources; check the PATH environment variable or try running
|
||||
'which gcc'.)
|
||||
|
||||
Assuming that worked, you can now try the following (and note that case,
|
||||
as with C/C++ identifiers, is important.):
|
||||
|
||||
gcc -E -dM empty.c
|
||||
|
||||
On one system, we then see definitions like:
|
||||
|
||||
#define __DBL_MIN_EXP__ (-1021)
|
||||
#define __FLT_MIN__ 1.17549435e-38F
|
||||
#define __DEC64_DEN__ 0.000000000000001E-383DD
|
||||
|
||||
... followed by about a hundred more '#define' directives. What just
|
||||
happened? We passed two options to gcc; the first one, '-E', means,
|
||||
"don't run the compiler; just run the preprocessor". The option '-dM'
|
||||
(not to be confused with '-DM', which is completely different) means,
|
||||
"don't generate preprocessor output; instead, only dump all macro
|
||||
definitions, including those defined internally".
|
||||
|
||||
With this output, we are now halfway to the point of having a preprocessor
|
||||
configuration for Lint. First, let's redirect those macros to a file:
|
||||
|
||||
gcc -E -dM empty.c >lint_cmac.h
|
||||
|
||||
Next, let's test our configuration: make a simple C source file
|
||||
containing the "Hello, world" program in a file called 't.c' (in the same
|
||||
directory as 'empty.c')
|
||||
|
||||
#include <stdio.h>
|
||||
int main () {
|
||||
printf( "hello, world!\n" );
|
||||
}
|
||||
|
||||
To lint this program, first copy the lnt file (co-gcc.lnt) and the
|
||||
associated header (co-gcc.h) into the same directory. Next, create two
|
||||
new empty files:
|
||||
|
||||
size-options.lnt
|
||||
gcc-include-path.lnt
|
||||
|
||||
... and save them to disk. Then make a file called 'std.lnt' which will
|
||||
(at first) contain only:
|
||||
|
||||
co-gcc.lnt
|
||||
|
||||
This tells Lint, "process the arguments in co-gcc.lnt". Two of those
|
||||
arguments are:
|
||||
|
||||
-header(co-gcc.h) // #include's headers generated by GCC.
|
||||
+libh(co-gcc.h) // Marks co-gcc.h as library code.
|
||||
|
||||
'-header(co-gcc.h)' means "behave as if each primary source file began
|
||||
with '#include "co-gcc.h"'. (Note that co-gcc.h includes "lint_cmac.h"
|
||||
when Lint runs in C language mode.)
|
||||
|
||||
Finally, try running:
|
||||
|
||||
/path/to/flint std.lnt t.c
|
||||
|
||||
... or, on Windows:
|
||||
|
||||
[drive-letter]:\path\to\lint-nt std.lnt t.c
|
||||
|
||||
Next we'll see output similar to the following:
|
||||
|
||||
FlexeLint for C/C++ (Unix/386) Vers. 9.00c, Copyright Gimpel Software
|
||||
1985-2009
|
||||
|
||||
--- Module: t.c (C)
|
||||
_
|
||||
#include <stdio.h>
|
||||
t.c 3 Error 322: Unable to open include file 'stdio.h'
|
||||
|
||||
What went wrong? The problem is that we haven't yet addressed the other
|
||||
half of the preprocessor configuration, namely: the ordered sequence of
|
||||
directories to search for system headers. Fortunately GCC already knows
|
||||
this list and gives us a way to discover it. Just run:
|
||||
|
||||
gcc -c -v empty.c
|
||||
|
||||
On one system (specifically, Mac OS X on Intel), that yields a lot of
|
||||
verbose output including these lines:
|
||||
|
||||
#include "..." search starts here:
|
||||
#include <...> search starts here:
|
||||
/usr/local/include
|
||||
/usr/lib/gcc/i686-apple-darwin8/4.0.1/include
|
||||
/usr/include
|
||||
/System/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
End of search list.
|
||||
|
||||
(Naturally, that list will look a bit different in different
|
||||
environments.) To make Lint search for system headers in the same way, we
|
||||
need to take that output from GCC and use it to make a set of options of
|
||||
the form --i[directory]. E.g. on the same system, that means that in
|
||||
gcc-include-path.lnt, I should place the following --i options:
|
||||
|
||||
--i/usr/local/include
|
||||
--i/usr/lib/gcc/i686-apple-darwin8/4.0.1/include
|
||||
--i/usr/include
|
||||
--i/System/Library/Frameworks
|
||||
--i/Library/Frameworks
|
||||
|
||||
(Note, arguments to Lint are processed in order, so the --i options must
|
||||
appear before t.c or they will not take effect in time.)
|
||||
|
||||
In this case, none of the directory names contains a space, but if one of
|
||||
them did we would have to surround its name with quotes as in:
|
||||
|
||||
--i"/usr/local/include"
|
||||
|
||||
Now let's try linting "hello, world" again:
|
||||
|
||||
/path/to/flint std.lnt t.c
|
||||
|
||||
This time we should see no error messages. Are we done yet? Not quite.
|
||||
First, let's test our configuration against all of the C Standard Library
|
||||
headers. Modify t.c to:
|
||||
|
||||
#include <assert.h>
|
||||
#include <iso646.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <errno.h>
|
||||
#include <locale.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int main () {
|
||||
printf( "hello, world!\n" );
|
||||
}
|
||||
|
||||
|
||||
... and try linting again:
|
||||
|
||||
/path/to/flint std.lnt t.c
|
||||
|
||||
This time you should see a number of messages; in particular, you should
|
||||
see Info 766 issued for most of these headers since they were not used.
|
||||
you may also see some legitimate warnings, and you may see an Error or two
|
||||
about 'wchar_t'. (Note, if it seems as though your port of GCC recognizes
|
||||
wchar_t as a keyword instead of an identifier then uncomment the use of
|
||||
'+fwc' in your copy of co-gcc.lnt).
|
||||
|
||||
[NOTE: we should point out that the option -wlib(1) is in co-gcc.lnt for a
|
||||
reason. Please note that we *strongly* recommend against the use of
|
||||
options like -wlib(0) or -elib(*). If you see syntax error messages about
|
||||
library header code, odds are that something is wrong with the Lint
|
||||
configuration; so you'll do yourself no favors by silencing Lint when it
|
||||
sees constructs that Lint's parser doesn't know how to handle. If you need
|
||||
help with correcting your configuration, please check the Lint manual or
|
||||
contact us.]
|
||||
|
||||
We should really be done now, right? Well, not quite. A remaining issue
|
||||
is that the set of predefined macros (dumped into "lint_cmac.h" earlier)
|
||||
depends not only on things like the target system and the version of GCC;
|
||||
it also depends on the options that you pass to GCC when you compile your
|
||||
program. E.g., if we invoke:
|
||||
|
||||
gcc -O3 -E -dM empty.c >lint_cmac.h
|
||||
|
||||
... then (with the version of GCC we tested) lint_cmac.h will no longer
|
||||
contain a definition for the macro '__NO_INLINE__' and contains a new
|
||||
definition for '__OPTIMIZE__'. So when you generate macros, you should be
|
||||
careful to pass in the full set of options used when you compile.
|
||||
Ideally, you should establish a target in your build system that
|
||||
re-generates the predefined macro header whenever your build configuration
|
||||
changes; that way you'll seldom need to think about it again and Lint's
|
||||
preprocessor configuration will always match the compiler's.
|
||||
|
||||
Assuming you've generated the right set of predefined macros for your
|
||||
build settings, you should now try Linting a single primary source file in
|
||||
your project. Since we're just starting out, let's run with -w1 (i.e.,
|
||||
with the warning level set to one) so that we can deal with any syntax
|
||||
errors that pop up:
|
||||
|
||||
flint std.lnt -u -w1 some-project-file.c
|
||||
|
||||
Again, remember that syntax errors at this stage are likely due to a
|
||||
misconfiguration; please check the Lint manual for likely remedies or
|
||||
contact us if the solution is not obvious.
|
||||
|
||||
Once you've taken care of all syntax errors, try doing the same with all
|
||||
project files. We recommend placing the name of each project file in a
|
||||
.lnt file (often called project.lnt); e.g.:
|
||||
|
||||
file1.c
|
||||
file2.c
|
||||
[...etc.]
|
||||
|
||||
... and invoke Lint like so:
|
||||
|
||||
flint std.lnt -w1 project.lnt
|
||||
|
||||
When all syntax errors are resolved, you can begin turning on Warning
|
||||
messages (i.e., those listed in section 17.4 of the Lint manual). You can
|
||||
turn them on individually after '-w1' or you can instead use '-w2' and
|
||||
then suppress the Warnings that are less severe. (For details on message
|
||||
suppression, see section 5.2 of the Lint manual.)
|
||||
|
||||
At this point, you should be well-equipped to Lint any C program compiled
|
||||
with GCC. However, C++ users have a couple more points to consider.
|
||||
|
||||
The command used to invoke GCC also affects the set of predefined macros.
|
||||
Observe the difference in '#define' output when you invoke:
|
||||
|
||||
g++ -O3 -E -dM empty.c >lint_cppmac.h
|
||||
diff lint_cmac.h lint_cppmac.h
|
||||
|
||||
Also, note that the list of directories to search for Standard Library
|
||||
headers has some new additions when you use 'g++ -v -c empty.c' instead of
|
||||
'gcc -v -c empty.c'. Your sequence of --i options should be set
|
||||
accordingly.
|
||||
|
||||
That's about it for the preprocessor.
|
||||
|
||||
--- Size options ---
|
||||
|
||||
Finally, you'll need to establish sizes of primitive types. E.g. for a
|
||||
64-bit platform this includes setting '-sp8' (indicating that pointers are
|
||||
8 bytes wide). It often also involves setting '-sl8' (indicating that
|
||||
'long' is eight bytes wide). As suggested earlier, the makefile
|
||||
co-gcc.mak can generate these options for you.
|
||||
|
||||
If you find this tutorial to be lacking in some way, please contact us
|
||||
(support@gimpel.com) with your suggestions for improvement.
|
|
@ -0,0 +1,254 @@
|
|||
#define __DBL_MIN_EXP__ (-1021)
|
||||
#define __UINT_LEAST16_MAX__ 0xffff
|
||||
#define __ATOMIC_ACQUIRE 2
|
||||
#define __FLT_MIN__ 1.17549435082228750797e-38F
|
||||
#define __GCC_IEC_559_COMPLEX 2
|
||||
#define __UINT_LEAST8_TYPE__ unsigned char
|
||||
#define __SIZEOF_FLOAT80__ 16
|
||||
#define __INTMAX_C(c) c ## L
|
||||
#define __CHAR_BIT__ 8
|
||||
#define __UINT8_MAX__ 0xff
|
||||
#define __WINT_MAX__ 0xffffffffU
|
||||
#define __ORDER_LITTLE_ENDIAN__ 1234
|
||||
#define __SIZE_MAX__ 0xffffffffffffffffUL
|
||||
#define __WCHAR_MAX__ 0x7fffffff
|
||||
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
|
||||
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
|
||||
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
|
||||
#define __DBL_DENORM_MIN__ ((double)4.94065645841246544177e-324L)
|
||||
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
|
||||
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
|
||||
#define __GCC_IEC_559 2
|
||||
#define __FLT_EVAL_METHOD__ 0
|
||||
#define __unix__ 1
|
||||
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
|
||||
#define __x86_64 1
|
||||
#define __UINT_FAST64_MAX__ 0xffffffffffffffffUL
|
||||
#define __SIG_ATOMIC_TYPE__ int
|
||||
#define __DBL_MIN_10_EXP__ (-307)
|
||||
#define __FINITE_MATH_ONLY__ 0
|
||||
#define __GNUC_PATCHLEVEL__ 0
|
||||
#define __UINT_FAST8_MAX__ 0xff
|
||||
#define __has_include(STR) __has_include__(STR)
|
||||
#define __DEC64_MAX_EXP__ 385
|
||||
#define __INT8_C(c) c
|
||||
#define __UINT_LEAST64_MAX__ 0xffffffffffffffffUL
|
||||
#define __SHRT_MAX__ 0x7fff
|
||||
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
|
||||
#define __UINT_LEAST8_MAX__ 0xff
|
||||
#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
|
||||
#define __UINTMAX_TYPE__ long unsigned int
|
||||
#define __linux 1
|
||||
#define __DEC32_EPSILON__ 1E-6DF
|
||||
#define __unix 1
|
||||
#define __UINT32_MAX__ 0xffffffffU
|
||||
#define __LDBL_MAX_EXP__ 16384
|
||||
#define __WINT_MIN__ 0U
|
||||
#define __linux__ 1
|
||||
#define __SCHAR_MAX__ 0x7f
|
||||
#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)
|
||||
#define __INT64_C(c) c ## L
|
||||
#define __DBL_DIG__ 15
|
||||
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
|
||||
#define __SIZEOF_INT__ 4
|
||||
#define __SIZEOF_POINTER__ 8
|
||||
#define __USER_LABEL_PREFIX__
|
||||
#define __STDC_HOSTED__ 1
|
||||
#define __LDBL_HAS_INFINITY__ 1
|
||||
#define __FLT_EPSILON__ 1.19209289550781250000e-7F
|
||||
#define __LDBL_MIN__ 3.36210314311209350626e-4932L
|
||||
#define __STDC_UTF_16__ 1
|
||||
#define __DEC32_MAX__ 9.999999E96DF
|
||||
#define __INT32_MAX__ 0x7fffffff
|
||||
#define __SIZEOF_LONG__ 8
|
||||
#define __STDC_IEC_559__ 1
|
||||
#define __STDC_ISO_10646__ 201605L
|
||||
#define __UINT16_C(c) c
|
||||
#define __DECIMAL_DIG__ 21
|
||||
#define __gnu_linux__ 1
|
||||
#define __has_include_next(STR) __has_include_next__(STR)
|
||||
#define __LDBL_HAS_QUIET_NAN__ 1
|
||||
#define __GNUC__ 6
|
||||
#define __pie__ 2
|
||||
#define __MMX__ 1
|
||||
#define __FLT_HAS_DENORM__ 1
|
||||
#define __SIZEOF_LONG_DOUBLE__ 16
|
||||
#define __BIGGEST_ALIGNMENT__ 16
|
||||
#define __DBL_MAX__ ((double)1.79769313486231570815e+308L)
|
||||
#define __INT_FAST32_MAX__ 0x7fffffffffffffffL
|
||||
#define __DBL_HAS_INFINITY__ 1
|
||||
#define __DEC32_MIN_EXP__ (-94)
|
||||
#define __INT_FAST16_TYPE__ long int
|
||||
#define __LDBL_HAS_DENORM__ 1
|
||||
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
|
||||
#define __INT_LEAST32_MAX__ 0x7fffffff
|
||||
#define __DEC32_MIN__ 1E-95DF
|
||||
#define __DBL_MAX_EXP__ 1024
|
||||
#define __DEC128_EPSILON__ 1E-33DL
|
||||
#define __SSE2_MATH__ 1
|
||||
#define __ATOMIC_HLE_RELEASE 131072
|
||||
#define __PTRDIFF_MAX__ 0x7fffffffffffffffL
|
||||
#define __amd64 1
|
||||
#define __STDC_NO_THREADS__ 1
|
||||
#define __ATOMIC_HLE_ACQUIRE 65536
|
||||
#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
|
||||
#define __SIZEOF_SIZE_T__ 8
|
||||
#define __SIZEOF_WINT_T__ 4
|
||||
#define __GCC_HAVE_DWARF2_CFI_ASM 1
|
||||
#define __GXX_ABI_VERSION 1010
|
||||
#define __FLT_MIN_EXP__ (-125)
|
||||
#define __INT_FAST64_TYPE__ long int
|
||||
#define __DBL_MIN__ ((double)2.22507385850720138309e-308L)
|
||||
#define __PIE__ 2
|
||||
#define __LP64__ 1
|
||||
#define __DECIMAL_BID_FORMAT__ 1
|
||||
#define __DEC128_MIN__ 1E-6143DL
|
||||
#define __REGISTER_PREFIX__
|
||||
#define __UINT16_MAX__ 0xffff
|
||||
#define __DBL_HAS_DENORM__ 1
|
||||
#define __UINT8_TYPE__ unsigned char
|
||||
#define __NO_INLINE__ 1
|
||||
#define __FLT_MANT_DIG__ 24
|
||||
#define __VERSION__ "6.3.0 20170516"
|
||||
#define __UINT64_C(c) c ## UL
|
||||
#define _STDC_PREDEF_H 1
|
||||
#define __GCC_ATOMIC_INT_LOCK_FREE 2
|
||||
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
|
||||
#define __STDC_IEC_559_COMPLEX__ 1
|
||||
#define __INT32_C(c) c
|
||||
#define __DEC64_EPSILON__ 1E-15DD
|
||||
#define __ORDER_PDP_ENDIAN__ 3412
|
||||
#define __DEC128_MIN_EXP__ (-6142)
|
||||
#define __INT_FAST32_TYPE__ long int
|
||||
#define __UINT_LEAST16_TYPE__ short unsigned int
|
||||
#define unix 1
|
||||
#define __INT16_MAX__ 0x7fff
|
||||
#define __SIZE_TYPE__ long unsigned int
|
||||
#define __UINT64_MAX__ 0xffffffffffffffffUL
|
||||
#define __INT8_TYPE__ signed char
|
||||
#define __ELF__ 1
|
||||
#define __GCC_ASM_FLAG_OUTPUTS__ 1
|
||||
#define __FLT_RADIX__ 2
|
||||
#define __INT_LEAST16_TYPE__ short int
|
||||
#define __LDBL_EPSILON__ 1.08420217248550443401e-19L
|
||||
#define __UINTMAX_C(c) c ## UL
|
||||
#define __SSE_MATH__ 1
|
||||
#define __k8 1
|
||||
#define __SIG_ATOMIC_MAX__ 0x7fffffff
|
||||
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
|
||||
#define __SIZEOF_PTRDIFF_T__ 8
|
||||
#define __x86_64__ 1
|
||||
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
|
||||
#define __INT_FAST16_MAX__ 0x7fffffffffffffffL
|
||||
#define __UINT_FAST32_MAX__ 0xffffffffffffffffUL
|
||||
#define __UINT_LEAST64_TYPE__ long unsigned int
|
||||
#define __FLT_HAS_QUIET_NAN__ 1
|
||||
#define __FLT_MAX_10_EXP__ 38
|
||||
#define __LONG_MAX__ 0x7fffffffffffffffL
|
||||
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
|
||||
#define __FLT_HAS_INFINITY__ 1
|
||||
#define __UINT_FAST16_TYPE__ long unsigned int
|
||||
#define __DEC64_MAX__ 9.999999999999999E384DD
|
||||
#define __CHAR16_TYPE__ short unsigned int
|
||||
#define __PRAGMA_REDEFINE_EXTNAME 1
|
||||
#define __SEG_FS 1
|
||||
#define __INT_LEAST16_MAX__ 0x7fff
|
||||
#define __DEC64_MANT_DIG__ 16
|
||||
#define __INT64_MAX__ 0x7fffffffffffffffL
|
||||
#define __UINT_LEAST32_MAX__ 0xffffffffU
|
||||
#define __SEG_GS 1
|
||||
#define __GCC_ATOMIC_LONG_LOCK_FREE 2
|
||||
#define __INT_LEAST64_TYPE__ long int
|
||||
#define __INT16_TYPE__ short int
|
||||
#define __INT_LEAST8_TYPE__ signed char
|
||||
#define __STDC_VERSION__ 201112L
|
||||
#define __DEC32_MAX_EXP__ 97
|
||||
#define __INT_FAST8_MAX__ 0x7f
|
||||
#define __INTPTR_MAX__ 0x7fffffffffffffffL
|
||||
#define linux 1
|
||||
#define __SSE2__ 1
|
||||
#define __LDBL_MANT_DIG__ 64
|
||||
#define __DBL_HAS_QUIET_NAN__ 1
|
||||
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
|
||||
#define __code_model_small__ 1
|
||||
#define __k8__ 1
|
||||
#define __INTPTR_TYPE__ long int
|
||||
#define __UINT16_TYPE__ short unsigned int
|
||||
#define __WCHAR_TYPE__ int
|
||||
#define __SIZEOF_FLOAT__ 4
|
||||
#define __pic__ 2
|
||||
#define __UINTPTR_MAX__ 0xffffffffffffffffUL
|
||||
#define __DEC64_MIN_EXP__ (-382)
|
||||
#define __INT_FAST64_MAX__ 0x7fffffffffffffffL
|
||||
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
|
||||
#define __FLT_DIG__ 6
|
||||
#define __UINT_FAST64_TYPE__ long unsigned int
|
||||
#define __INT_MAX__ 0x7fffffff
|
||||
#define __amd64__ 1
|
||||
#define __INT64_TYPE__ long int
|
||||
#define __FLT_MAX_EXP__ 128
|
||||
#define __ORDER_BIG_ENDIAN__ 4321
|
||||
#define __DBL_MANT_DIG__ 53
|
||||
#define __SIZEOF_FLOAT128__ 16
|
||||
#define __INT_LEAST64_MAX__ 0x7fffffffffffffffL
|
||||
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
|
||||
#define __DEC64_MIN__ 1E-383DD
|
||||
#define __WINT_TYPE__ unsigned int
|
||||
#define __UINT_LEAST32_TYPE__ unsigned int
|
||||
#define __SIZEOF_SHORT__ 2
|
||||
#define __SSE__ 1
|
||||
#define __LDBL_MIN_EXP__ (-16381)
|
||||
#define __INT_LEAST8_MAX__ 0x7f
|
||||
#define __SIZEOF_INT128__ 16
|
||||
#define __LDBL_MAX_10_EXP__ 4932
|
||||
#define __ATOMIC_RELAXED 0
|
||||
#define __DBL_EPSILON__ ((double)2.22044604925031308085e-16L)
|
||||
#define _LP64 1
|
||||
#define __UINT8_C(c) c
|
||||
#define __INT_LEAST32_TYPE__ int
|
||||
#define __SIZEOF_WCHAR_T__ 4
|
||||
#define __UINT64_TYPE__ long unsigned int
|
||||
#define __INT_FAST8_TYPE__ signed char
|
||||
#define __GNUC_STDC_INLINE__ 1
|
||||
#define __DBL_DECIMAL_DIG__ 17
|
||||
#define __STDC_UTF_32__ 1
|
||||
#define __FXSR__ 1
|
||||
#define __DEC_EVAL_METHOD__ 2
|
||||
#define __UINT32_C(c) c ## U
|
||||
#define __INTMAX_MAX__ 0x7fffffffffffffffL
|
||||
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
|
||||
#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F
|
||||
#define __INT8_MAX__ 0x7f
|
||||
#define __PIC__ 2
|
||||
#define __UINT_FAST32_TYPE__ long unsigned int
|
||||
#define __CHAR32_TYPE__ unsigned int
|
||||
#define __FLT_MAX__ 3.40282346638528859812e+38F
|
||||
#define __INT32_TYPE__ int
|
||||
#define __SIZEOF_DOUBLE__ 8
|
||||
#define __FLT_MIN_10_EXP__ (-37)
|
||||
#define __INTMAX_TYPE__ long int
|
||||
#define __DEC128_MAX_EXP__ 6145
|
||||
#define __ATOMIC_CONSUME 1
|
||||
#define __GNUC_MINOR__ 3
|
||||
#define __UINTMAX_MAX__ 0xffffffffffffffffUL
|
||||
#define __DEC32_MANT_DIG__ 7
|
||||
#define __DBL_MAX_10_EXP__ 308
|
||||
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
|
||||
#define __INT16_C(c) c
|
||||
#define __STDC__ 1
|
||||
#define __PTRDIFF_TYPE__ long int
|
||||
#define __ATOMIC_SEQ_CST 5
|
||||
#define __UINT32_TYPE__ unsigned int
|
||||
#define __UINTPTR_TYPE__ long unsigned int
|
||||
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
|
||||
#define __DEC128_MANT_DIG__ 34
|
||||
#define __LDBL_MIN_10_EXP__ (-4931)
|
||||
#define __SIZEOF_LONG_LONG__ 8
|
||||
#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
|
||||
#define __LDBL_DIG__ 18
|
||||
#define __FLT_DECIMAL_DIG__ 9
|
||||
#define __UINT_FAST16_MAX__ 0xffffffffffffffffUL
|
||||
#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
|
||||
#define __UINT_FAST8_TYPE__ unsigned char
|
||||
#define __ATOMIC_ACQ_REL 4
|
||||
#define __ATOMIC_RELEASE 3
|
|
@ -0,0 +1,85 @@
|
|||
# This file contains functions and configurations for generating PC-Lint build
|
||||
# targets for your CMake projects.
|
||||
|
||||
set(PC_LINT_EXECUTABLE "lint-nt.exe" CACHE STRING "full path to the pc-lint executable. NOT the generated lin.bat")
|
||||
set(PC_LINT_CONFIG_DIR "${PROJECT_SOURCE_DIR}/lint/gnu" CACHE STRING "full path to the directory containing pc-lint configuration files")
|
||||
set(PC_LINT_USER_FLAGS "-b" CACHE STRING "additional pc-lint command line options -- some flags of pc-lint cannot be set in option files (most notably -b)")
|
||||
|
||||
# a phony target which causes all available *_LINT targets to be executed
|
||||
add_custom_target(ALL_LINT)
|
||||
|
||||
# add_pc_lint(target source1 [source2 ...])
|
||||
#
|
||||
# Takes a list of source files and generates a build target which can be used
|
||||
# for linting all files
|
||||
#
|
||||
# The generated lint commands assume that a top-level config file named
|
||||
# 'std.lnt' resides in the configuration directory 'PC_LINT_CONFIG_DIR'. This
|
||||
# config file must include all other config files. This is standard lint
|
||||
# behaviour.
|
||||
#
|
||||
# Parameters:
|
||||
# - target: the name of the target to which the sources belong. You will get a
|
||||
# new build target named ${target}_LINT
|
||||
# - source1 ... : a list of source files to be linted. Just pass the same list
|
||||
# as you passed for add_executable or add_library. Everything except
|
||||
# C and CPP files (*.c, *.cpp, *.cxx) will be filtered out.
|
||||
#
|
||||
# Example:
|
||||
# If you have a CMakeLists.txt which generates an executable like this:
|
||||
#
|
||||
# set(MAIN_SOURCES main.c foo.c bar.c)
|
||||
# add_executable(main ${MAIN_SOURCES})
|
||||
#
|
||||
# include this file
|
||||
#
|
||||
# include(/path/to/pc_lint.cmake)
|
||||
#
|
||||
# and add a line to generate the main_LINT target
|
||||
#
|
||||
# if(COMMAND add_pc_lint)
|
||||
# add_pc_lint(main ${MAIN_SOURCES})
|
||||
# endif(COMMAND add_pc_lint)
|
||||
#
|
||||
function(add_pc_lint target)
|
||||
get_directory_property(lint_include_directories INCLUDE_DIRECTORIES)
|
||||
get_directory_property(lint_defines COMPILE_DEFINITIONS)
|
||||
|
||||
# let's get those elephants across the alps
|
||||
# prepend each include directory with "-i"; also quotes the directory
|
||||
set(lint_include_directories_transformed)
|
||||
foreach(include_dir ${lint_include_directories})
|
||||
list(APPEND lint_include_directories_transformed -i"${include_dir}")
|
||||
endforeach(include_dir)
|
||||
|
||||
# prepend each definition with "-d"
|
||||
set(lint_defines_transformed)
|
||||
foreach(definition ${lint_defines})
|
||||
list(APPEND lint_defines_transformed -d${definition})
|
||||
endforeach(definition)
|
||||
|
||||
# list of all commands, one for each given source file
|
||||
set(pc_lint_commands)
|
||||
|
||||
foreach(sourcefile ${ARGN})
|
||||
# only include c and cpp files
|
||||
if( sourcefile MATCHES \\.c$|\\.cxx$|\\.cpp$ )
|
||||
# make filename absolute
|
||||
get_filename_component(sourcefile_abs ${sourcefile} ABSOLUTE)
|
||||
# create command line for linting one source file and add it to the list of commands
|
||||
list(APPEND pc_lint_commands
|
||||
COMMAND ${PC_LINT_EXECUTABLE}
|
||||
-i"${PC_LINT_CONFIG_DIR}" std.lnt
|
||||
"-u" ${PC_LINT_USER_FLAGS}
|
||||
${lint_include_directories_transformed}
|
||||
${lint_defines_transformed}
|
||||
${sourcefile_abs})
|
||||
endif()
|
||||
endforeach(sourcefile)
|
||||
|
||||
# add a custom target consisting of all the commands generated above
|
||||
add_custom_target(${target}_LINT ${pc_lint_commands} VERBATIM)
|
||||
# make the ALL_LINT target depend on each and every *_LINT target
|
||||
add_dependencies(ALL_LINT ${target}_LINT)
|
||||
|
||||
endfunction(add_pc_lint)
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
co-gcc.lnt
|
|
@ -0,0 +1,42 @@
|
|||
// ---------------------------------------------------------------------
|
||||
// This file is provided by Gimpel Software (www.gimpel.com) for use with
|
||||
// its products PC-lint and FlexeLint.
|
||||
//
|
||||
// Redistribution and use of this file, with or without modification, is
|
||||
// permitted provided that any such redistribution retains this notice.
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#ifndef LINT_SUPPORT_CO_MSC100_H_
|
||||
#define LINT_SUPPORT_CO_MSC100_H_
|
||||
|
||||
// co-msc100.h --
|
||||
// This header is automatically included in every module if you use
|
||||
// co-msc100.lnt. (There is a -header(co-msc100.h) option therein
|
||||
// for this purpose.)
|
||||
|
||||
// Microsoft's C++11 implementation does not yet include built-in support
|
||||
// for the new character types, so we need to disable the relevant
|
||||
// keywords here. (This must be done before the inclusion of any other
|
||||
// header file because Microsoft's library headers contain declarations of
|
||||
// typedef names with the same spelling.)
|
||||
//lint -rw(char16_t,char32_t)
|
||||
|
||||
// Next we must compensate for the fact that class typeinfo is available
|
||||
// for use in the MSC compilers without an explicit definition. According
|
||||
// to the standard this class definition is not (available by default).
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#else // C mode
|
||||
|
||||
// co-msc100.lnt defines some macros that the Microsoft compiler defines
|
||||
// in C++ modes but not in C mode; we must un-define them here:
|
||||
#undef _CPPRTTI
|
||||
#undef _NATIVE_WCHAR_T_DEFINED
|
||||
#undef _WCHAR_T_DEFINED
|
||||
#undef _NATIVE_NULLPTR_SUPPORTED
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* LINT_SUPPORT_CO_MSC100_H_ */
|
|
@ -0,0 +1,461 @@
|
|||
/* Date Stamp */ -d"_lint_co_msc100_lnt=co-msc100.lnt modified 19-Sep-2013"
|
||||
/* To document usage use: -message( "Using " _lint_co_msc100_lnt ) */
|
||||
// ---------------------------------------------------------------------
|
||||
// This file is provided by Gimpel Software (www.gimpel.com) for use with
|
||||
// its products PC-lint and FlexeLint.
|
||||
//
|
||||
// Redistribution and use of this file, with or without modification, is
|
||||
// permitted provided that any such redistribution retains this notice.
|
||||
// ---------------------------------------------------------------------
|
||||
// co-msc100.lnt
|
||||
// Compiler Options for Visual Studio for C/C++ Version 10.00
|
||||
// (Visual Studio 2010)
|
||||
// This file contains options to allow PC-lint to process source
|
||||
// files for your compiler. It is used as follows:
|
||||
//
|
||||
// lint co-msc100.lnt source-file(s)
|
||||
//
|
||||
// (See macros-msc.c and/or macros-msc.cpp for details.)
|
||||
|
||||
// Section 1: options independent of the use of the automatic macro
|
||||
// generator (macros-msc.cpp)
|
||||
//
|
||||
-cmsc
|
||||
-A(C++2011)
|
||||
+compiler(search_actively_including_stack)
|
||||
-si4 // integers are 4 bytes
|
||||
-sp4 // pointers are 4 bytes too.
|
||||
|
||||
// We now support __declspec directly so that the following
|
||||
// option is now commented out. If trouble ensues you can
|
||||
// once again disable __declspec through this option.
|
||||
// -d__declspec()= // ignore this construct
|
||||
-d_declspec=__declspec // the single '_' version is occasionally used
|
||||
|
||||
// while processing compiler (library) header files ...
|
||||
-wlib(1) // sets the warning level within library headers to 1
|
||||
// (no warnings, just syntax errors). Comment out if you
|
||||
// are actually linting library headers. This
|
||||
// option makes obsolete options of the form -elib(axxx) where
|
||||
// xxx >= 400 which may be retained for historical reasons.
|
||||
-elib(1111) // Some VC++ headers contain explicit specializations at class
|
||||
// scope.
|
||||
-elib(19) // useless declarations (lone semicolons)
|
||||
-elib(123) // function-like macro name used as non macro
|
||||
-elib(652) // suppress message about #define of earlier declared symbols
|
||||
-elib(762) // suppress message about multiple identical declarations and
|
||||
-elib(760) // suppress message about multiple identical macro defs
|
||||
-elib(514) // allow #if <boolean> | <boolean>
|
||||
-elib(553) // undefined preprocessor variables assumed 0
|
||||
-elib(1081) // suspicious object argument to an object parameter
|
||||
-elib(726) // extraneous comma in enum definition
|
||||
-elib(157) // suppress message about no data may follow an incomplete array
|
||||
-elib(91) // suppress message about line exceeds 598 characters
|
||||
|
||||
// SREGS, WORDREGS, BYTEREGS are defined in both bios.h and dos.h
|
||||
// and accordingly you MAY get type differences based on 'origin'.
|
||||
// If so, use the following options:
|
||||
// -etd(origin)
|
||||
// -elib(770)
|
||||
|
||||
-format=%(%f(%l)\s:\s%)%t\s%n:\s%m
|
||||
// error format similar to MSC
|
||||
// Note that %c can also be used to specify column
|
||||
-e46 // allows bit-fields to be other than int or unsigned
|
||||
+fan // allow anonymous unions
|
||||
+fdi // Use directory of the including file
|
||||
+fbo // enable the bool type
|
||||
+fwm // wprintf format codes are not standard
|
||||
-fdh // do not append a .h to header names
|
||||
-esym(123,min,max) // allows users to use min, max as variables
|
||||
+rw(__inline) // activate the __inline keyword
|
||||
-rw_asgn(__nullptr,nullptr)
|
||||
-e19 // Suppress errors about lone semicolons
|
||||
+ppw(import) // activate #import
|
||||
-d_inline=__inline // _inline is the same as __inline
|
||||
-sld8 // sizeof(long double) is 8.
|
||||
-function(exit,_exit) // _exit() is like exit()
|
||||
-function(exit,_assert) // _assert() is like exit()
|
||||
-emacro(506,assert) // don't warn about constant value Boolean
|
||||
-emacro(734,putc) // don't complain about items being too large.
|
||||
-emacro(415,_FP_SEG) // access of out-of-bounds pointer
|
||||
-emacro(740,FP_SEG,FP_OFF) // unusual casts
|
||||
-emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662
|
||||
// 796 and 797 (out-of-bounds errors).
|
||||
-emacro((???),va_start) // the same applies to va_start
|
||||
-emacro(413,offsetof) // use of NULL pointer creates a stir
|
||||
-emacro(545,offsetof) // addressing an array member is OK
|
||||
-emacro(845,RGB) // a common use of RGB uses a operator that produces a 0
|
||||
-e793 // inhibit 'ANSI limit reached' --
|
||||
// limits are impractically low with MSVC headers
|
||||
-esym(628,eof) // failure to provide argument information for eof()
|
||||
-esym(773,L_tmpnam) // defined with an unparenthesized '+'
|
||||
-esym(438,_acp) // USES_CONVERSION assigns to _acp.
|
||||
-emacro(571,__isascii) // don't warn about the unusual cast
|
||||
-emacro(522,UNREFERENCED_PARAMETER) // don't complain about a lack of
|
||||
// side-effects
|
||||
-emacro(648,CDN_*) // ignore unsigned overflow
|
||||
-emacro(648,OIVN_*) // ignore unsigned overflow
|
||||
-emacro(648,TTN_*) // ignore unsigned overflow
|
||||
-emacro(648,TVN_*) // ignore unsigned overflow
|
||||
-emacro(648,TBN_*) // ignore unsigned overflow
|
||||
|
||||
// The following functions exhibit variable return modes.
|
||||
// That is, they may equally-usefully be called for a value
|
||||
// as called just for their effects. Accordingly we inhibit
|
||||
// Warning 534 for these functions.
|
||||
// Feel free to add to or subtract from this list.
|
||||
|
||||
-esym(534,close,creat,fclose,fflush,_flsbuf,fprintf,fputc)
|
||||
-esym(534,fputs,fscanf,fseek,fwrite,lseek,memcpy,memmove,memset)
|
||||
-esym(534,printf,puts,scanf,sprintf,sscanf,strcat,strcpy)
|
||||
-esym(534,strncat,strncpy,unlink,write)
|
||||
|
||||
// These are the wide char variants of printf-scanf family
|
||||
|
||||
-wprintf( 1, wprintf )
|
||||
-wprintf( 3, fwprintf, swprintf )
|
||||
-wscanf( 1, wscanf )
|
||||
-wscanf( 2, fwscanf, swscanf )
|
||||
|
||||
// These are substitutions for sprintf
|
||||
|
||||
-printf( 3, StringCbPrintfA )
|
||||
-printf( 3, StringCchPrintfA )
|
||||
-wprintf( 3, StringCbPrintfW )
|
||||
-wprintf( 3, StringCchPrintfW )
|
||||
|
||||
// The following options are used to adjust our function mimicry to
|
||||
// the actual library as provided by MS.
|
||||
|
||||
-function( wcstombs(1) ) // remove the check for a NULL first arg to wcstombs()
|
||||
|
||||
// The following options are required by most compilers to
|
||||
// noiselessly process iostream.h
|
||||
|
||||
-elib(1717) // empty prototypes
|
||||
-elib(522) // function return value ignored
|
||||
-elib(1053) // prototypes cannot be distinguished
|
||||
-elib(1721) // unusual operator =() declaration
|
||||
-elib(1720) // assignment op has non-const parameter
|
||||
-elib(655) // bitwise operator combining compatible enum's
|
||||
-elib(641) // converting enum's to int
|
||||
-elib(537) // repeated include file (ios.h)
|
||||
-elib(1511) // member (rdbuf) hides nonvirtual member
|
||||
-elib(1712) // default constructor not defined for class
|
||||
-elib(1736) // redundant access specifier
|
||||
-esym(1702,operator<<,operator>>) // both a member and an ordinary function
|
||||
|
||||
// These functions return things that are frequently ignored.
|
||||
|
||||
-esym(534,*operator<<,*operator>>)
|
||||
|
||||
// The following additional options seem to be needed.
|
||||
|
||||
-elib(506) // constant value Boolean
|
||||
-elib(620) // el or one? (some constants end in 'l' not 'L')
|
||||
-elib(648) // overflow in computing constant (3<<16)
|
||||
-elib(659) // nothing fold_NATIVE_WCHAR_T_DEFINEDlows '}' on some line
|
||||
-elib(723) // suspicious use of '='
|
||||
-elib(747) // significant prototype coercion
|
||||
-elib(740) // unusual pointer casts
|
||||
-elib(1007) // virtual functions within extern "C" block
|
||||
-elib(1029) // default argument repeated -- can't dist. char, signed char
|
||||
-elib(1055) // call to rdbuf() questioned?
|
||||
-elib(1504) // apparently useless structs
|
||||
-elib(1708,1709) // minor C/C++ declaration conflict
|
||||
-elib(1707) // operator new declared w/o 'static'
|
||||
-elib(1722) // assignment op does not return reference
|
||||
-elib(149) // default argument found in C code.
|
||||
-elib(578) // declaration of time hides delaration of global time().
|
||||
-elib(761) // two equivalent typedef declarations
|
||||
-elib(1065) // same name declared as "C" and not "C"
|
||||
-elib(1066) // same name declared as "C" and not "C"
|
||||
-elib(1704) // constructor with private access declaration
|
||||
-elib(1735) // default parameter within virtual function
|
||||
-elib(773) // macros that look like unparenthesized expressions
|
||||
-elib(806) // 1-bit bitfields typed int
|
||||
-elib(1501) // 0-length data members
|
||||
-elib(1510) // base class has no destructor
|
||||
-elib(1516) // data member hides inherited member
|
||||
-elib(1509) // base class destructor is not virtual
|
||||
|
||||
// Special Notice: You may be receiving mysterious 1058 errors
|
||||
// when you use "iomanipulator"s. For example:
|
||||
// cout << setw(4) << 4;
|
||||
// results in Error 1058 (assigning a const to a ref) because the
|
||||
// manipulator setw returns a non-lvalue which is assigned to a reference.
|
||||
// This reflects an oversight in the Microsoft header file: iomanip.h
|
||||
// Therein you may change the declaration:
|
||||
// friend ostream& operator<<(iostream& s, IOMANIP(T) & sm) { ...
|
||||
// to:
|
||||
// friend ostream& operator<<(iostream& s, const IOMANIP(T) & sm) { ...
|
||||
// to reflect the fact that sm is not modified by this function.
|
||||
|
||||
+fll // enable long long
|
||||
|
||||
// In the following option we define __uuidof() and suppress
|
||||
// Errors 50 and 69 and 1924 in exprs. containing same
|
||||
-d"__uuidof()= /*lint --e(50,69,1924) */ (_GUID)0"
|
||||
|
||||
-esym(123,FD_SET) // defined as macro and as typedef
|
||||
-esym(1726,endl,ends) // taking the address of an overloaded function
|
||||
-esym(18,Data_t::Data_t) // definition not matching declaration
|
||||
|
||||
-elib(10) // expecting ')' -- comdef.h has a: #if defined( id
|
||||
-elib(43) // vacuous array within _MIDL_FORMAT_STRING
|
||||
-elib(602) // benign comment within comment
|
||||
-elib(657) // declaring "anonymous struct" in union _LARGE_INTEGER
|
||||
-elib(799) // long numerical constant for max. __int64
|
||||
-elib(1502) // nothrow has no data members
|
||||
-elib(1505) // no access specifier in base class specifier
|
||||
-elib(1515) // AFX_THREAD_STATE member has no default constructor
|
||||
-elib(1706) // Unusual declaration with a scope operator
|
||||
-elib(1725) // data member is a reference
|
||||
-elib(1548) // conflicting exception specifications
|
||||
-elib(1737) // hiding global operator new
|
||||
-elib(1739) // binary operator should be non-member function
|
||||
-elib(1748) // non-virtual base class included twice
|
||||
-elib(1759) // post-fix operator returns a reference
|
||||
|
||||
// Add elements of ole automation
|
||||
|
||||
lib-ole.lnt
|
||||
|
||||
// Options required for .net
|
||||
|
||||
-d_stdcall=__stdcall // make _stdcall equivalent to __stdcall
|
||||
-d__interface=class // treat an interface the same as a class
|
||||
-d__unaligned= // pass over the __unaligned keyword
|
||||
-d__w64= // ignore this identifier
|
||||
-esym(40,DLGPROC) // used before being defined
|
||||
-elib(146) // assuming binary constant
|
||||
-elib(1015) // GetDefaultThreads not found in class
|
||||
+ppw(using) // ignore #using for now.
|
||||
|
||||
-d__pragma(x)= // ignore the pragma extension
|
||||
+rw(__ptr64) // additional qualifier
|
||||
+rw_asgn(__thiscall,fortran) // additional qualifier
|
||||
|
||||
-"d__identifier(x)=___identifier x"
|
||||
// treat C++ keyword x as an identifier
|
||||
|
||||
-elibsym(1512) // base class destructor not virtual
|
||||
|
||||
-d__TIMESTAMP__="Mon Jan 01 00:00:00 2010"
|
||||
-d__COUNTER__=__lint__COUNTER__
|
||||
-d__FUNCDNAME__="MyFunc"
|
||||
-d__FUNCSIG__="MyFunc"
|
||||
-d__FUNCTION__=___function___
|
||||
|
||||
-dinitonly= // Compiler should catch miss-uses.
|
||||
// Lint can just skip over it.
|
||||
-"dliteral=static const" // Documentation says they are
|
||||
// equivalent for member data.
|
||||
|
||||
// __try_cast is like dynamic_cast (except the former throws where
|
||||
// the latter returns 0).
|
||||
|
||||
-d__try_cast=dynamic_cast
|
||||
|
||||
+rw(__restrict) // reserved word
|
||||
|
||||
// Partial support for the "old" (VC++ 2003) Managed Extensions
|
||||
// syntax:
|
||||
+rw( __gc, __value, __nogc, __pin, __ptr32, __ptr64 )
|
||||
|
||||
-$ // $ can be used in identifiers
|
||||
+rw( __allowed_on_parameter )
|
||||
+rw( __allowed_on_function )
|
||||
+rw( __allowed_on_typedecl )
|
||||
+rw( __allowed_on_return )
|
||||
+rw( __allowed_on_struct )
|
||||
+rw( __allowed_on_function_or_typedecl )
|
||||
+rw( __allowed_on_field )
|
||||
+rw( __allowed_on_parameter_or_return )
|
||||
+rw( __allowed_on_function )
|
||||
+rw( *type_traits ) //type traits support
|
||||
|
||||
+e1942 // This Elective Note alerts the user to the non-standard
|
||||
// way in which MS handles originally-dependent base classes.
|
||||
// E.g. template<class T> class A : T { ... x ... };
|
||||
// Should T be searched for "x" during instantiation?
|
||||
// the standard says "no", MS does.
|
||||
|
||||
|
||||
-header(co-msc100.h) // implicitly includes <typeinfo>. (Needed because
|
||||
// MSVC 9 implicitly declares class type_info.)
|
||||
|
||||
|
||||
// Section 2: options that should be commented out if you use the
|
||||
// automatic macro generator (macros-msc.cpp)
|
||||
|
||||
// Note, a macro option of the form:
|
||||
// -dA{1}
|
||||
// has the same effect as:
|
||||
// -dA=1
|
||||
// or:
|
||||
// -d"A=1"
|
||||
// The curly-brace version of the syntax is appropriate for
|
||||
// macro-scavenging (the method we used to generate the macro options
|
||||
// below). For details, see notes on the -scavenge() option in section
|
||||
// 5.8.3 in the Lint manual. See also the macro generator file,
|
||||
// macros-msc.cpp, which follows the form of -scavenge() output.
|
||||
|
||||
// We generated the options in this section with the following commands:
|
||||
// %VSInstallDir%\vc\bin\vcvars32.bat
|
||||
// cl /EP /C macros-msc.cpp
|
||||
// The options for other build configurations will probably differ (which
|
||||
// is why you should comment out the following if you use the macro
|
||||
// generator).
|
||||
|
||||
// Also note: some of the following are defined for C++ mode but not for C
|
||||
// mode; but there's no need to comment them out here because they are
|
||||
// conditionally #undef'd in co-msc100.h.
|
||||
|
||||
-d_CPPRTTI{1}
|
||||
//
|
||||
// Defined for code compiled with /GR (Enable Run-Time Type
|
||||
// Information).
|
||||
//
|
||||
|
||||
-d_INTEGRAL_MAX_BITS{64}
|
||||
//
|
||||
// Reports the maximum size (in bits) for an integral type.
|
||||
//
|
||||
|
||||
// NOTE:
|
||||
// When generating 64-bit code, the definition for _M_IX86 must be
|
||||
// commented out.
|
||||
-d_M_IX86{600}
|
||||
//
|
||||
// Defined for x86 processors. See the "Values for _M_IX86 table" (in
|
||||
// Microsoft's preprocessor documentation) for more information. This
|
||||
// is not defined for x64 processors.
|
||||
//
|
||||
|
||||
-d_M_IX86_FP{0}
|
||||
//
|
||||
// Expands to a value indicating which /arch compiler option was used:
|
||||
//
|
||||
// 0 if /arch was not used.
|
||||
//
|
||||
// 1 if /arch:SSE was used.
|
||||
//
|
||||
// 2 if /arch:SSE2 was used.
|
||||
//
|
||||
// See /arch (Minimum CPU Architecture) for more information.
|
||||
//
|
||||
|
||||
-d_MSC_BUILD{1}
|
||||
//
|
||||
// Evaluates to the revision number component of the compiler's
|
||||
// version number. The revision number is the fourth component of the
|
||||
// period-delimited version number. For example, if the version number
|
||||
// of the Visual C++ compiler is 15.00.20706.01, the _MSC_BUILD macro
|
||||
// evaluates to 1.
|
||||
//
|
||||
|
||||
-d_MSC_EXTENSIONS{1}
|
||||
//
|
||||
// This macro is defined when you compile with the /Ze compiler option
|
||||
// (the default). Its value, when defined, is 1.
|
||||
//
|
||||
|
||||
-d_MSC_FULL_VER{160030319}
|
||||
//
|
||||
// Evaluates to the major, minor, and build number components of the
|
||||
// compiler's version number. The major number is the first component
|
||||
// of the period-delimited version number, the minor number is the
|
||||
// second component, and the build number is the third component. For
|
||||
// example, if the version number of the Visual C++ compiler is
|
||||
// 15.00.20706.01, the _MSC_FULL_VER macro evaluates to 150020706.
|
||||
// Type cl /? at the command line to view the compiler's version
|
||||
// number.
|
||||
//
|
||||
|
||||
-d_MSC_VER{1600}
|
||||
//
|
||||
// Evaluates to the major and minor number components of the
|
||||
// compiler's version number. The major number is the first component
|
||||
// of the period-delimited version number and the minor number is the
|
||||
// second component.
|
||||
//
|
||||
// For example, if the version number of the Visual C++ compiler is
|
||||
// 15.00.20706.01, the _MSC_VER macro evaluates to 1500.
|
||||
//
|
||||
// In Visual Studio 2010, _MSC_VER is defined as 1600.
|
||||
//
|
||||
|
||||
-d_MT{1}
|
||||
//
|
||||
// Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd
|
||||
// (Multithreaded) is specified.
|
||||
//
|
||||
|
||||
-d_NATIVE_WCHAR_T_DEFINED{1}
|
||||
//
|
||||
// Defined when /Zc:wchar_t is used.
|
||||
//
|
||||
|
||||
-d_WCHAR_T_DEFINED{1}
|
||||
//
|
||||
// Defined when /Zc:wchar_t is used or if wchar_t is defined in a
|
||||
// system header file included in your project.
|
||||
//
|
||||
|
||||
-d_WIN32{1}
|
||||
//
|
||||
// Defined for applications for Win32 and Win64. Always defined.
|
||||
//
|
||||
|
||||
/**** Undocumented predefined macros follow ****/
|
||||
|
||||
-d_NATIVE_NULLPTR_SUPPORTED{1}
|
||||
|
||||
// Section 3: options that should remain commented out if you use the
|
||||
// automatic macro generator (macros-msc.cpp)
|
||||
|
||||
// When compiling with /J, use:
|
||||
//+fcu // Plain char is unsigned
|
||||
//-d_CHAR_UNSIGNED
|
||||
|
||||
// When compiling with /clr, /clr:pure or /clr:safe, use:
|
||||
//-d__cplusplus_cli=200406 // for all 3
|
||||
//-d_M_CEE_PURE // for /clr:pure
|
||||
//-d_M_CEE_SAFE // for /clr:safe
|
||||
//-d_MANAGED // for /clr
|
||||
|
||||
// When using any /clr form, use:
|
||||
//-d_M_CEE
|
||||
|
||||
|
||||
// When compiling with /GX or /EH, use:
|
||||
//-d_CPPUNWIND // Enable Exception Handling
|
||||
|
||||
// When compiling for Win64, use:
|
||||
//-d_WIN64
|
||||
|
||||
// When compiling with /Wp64, use:
|
||||
//-d_Wp64 // 64-bit portability
|
||||
|
||||
// Be sure to define your platform if any of the following apply:
|
||||
//-d_M_ALPHA // For DEC ALPHA platforms
|
||||
//-d_M_IA64 // For Itanium 64-bit processors
|
||||
//-d_M_X64 // For x64 processors
|
||||
|
||||
// When compiling with the /RTC option, use:
|
||||
//-d__MSVC_RUNTIME_CHECKS // Using such checks
|
||||
|
||||
// When compiling with /openmp, use:
|
||||
//-d_OPENMP=200203 // OpenMP specification date
|
||||
|
||||
// When compiling with /Zl, use:
|
||||
//-d_VC_NODEFAULTLIB // Omit default library name in *.obj file
|
||||
|
||||
/* DLL's or Multithreads? Enable the following:
|
||||
|
||||
-d_AFXDLL // making a DLL
|
||||
-d_DLL // ditto
|
||||
|
||||
*/
|
|
@ -0,0 +1,221 @@
|
|||
/* Date Stamp */ -d"_lint_env_vc10_lnt=env-vc10.lnt modified 22-Feb-2012"
|
||||
/* To document usage use: -message( "Using " _lint_env_vc10_lnt ) */
|
||||
// ---------------------------------------------------------------------
|
||||
// This file is provided by Gimpel Software (www.gimpel.com) for use with
|
||||
// its products PC-lint and FlexeLint.
|
||||
//
|
||||
// Redistribution and use of this file, with or without modification, is
|
||||
// permitted provided that any such redistribution retains this notice.
|
||||
// ---------------------------------------------------------------------
|
||||
/*
|
||||
env-vc10.lnt: environment parameters for Microsoft's Visual C++ 10.0
|
||||
|
||||
If you are using Microsoft Visual Studio 2010 and you wish to invoke
|
||||
PC-lint from that environment then add one or more commands to the
|
||||
Tools menu as follows.
|
||||
|
||||
Simple Check
|
||||
------------
|
||||
|
||||
For example, to add a simple facility to lint the current file you
|
||||
may do the following:
|
||||
|
||||
1. From the Tools Menu choose "External Tools ..."
|
||||
2. Click the "Add" button.
|
||||
3. You will now be able to enter the fields of this Tool.
|
||||
Modify them so that they approximate the following:
|
||||
|
||||
Title: PC-lint (Simple Check)
|
||||
Command: c:\lint\lint-nt.exe
|
||||
Arguments:
|
||||
-i"c:\lint" std.lnt env-vc10.lnt "$(ItemFileName)$(ItemExt)"
|
||||
Initial Directory: $(ItemDir)
|
||||
|
||||
X_Use Output Window __Prompt for arguments __Close on exit
|
||||
|
||||
Please note that you will have to change the "Command:" path if
|
||||
the PC-lint Installation Directory is anything other than c:\lint
|
||||
and you will have to change the "Arguments:" line if the
|
||||
Configuration Directory is anything other than c:\lint
|
||||
|
||||
4. Select OK to return to the main environment.
|
||||
|
||||
This will result in the Tools menu containing the additional item
|
||||
"PC-lint (Simple Check)". Checking 'X' on 'Use Output Window' is
|
||||
important because in this way you can advance from error to error
|
||||
using the F8 key (Shift F8 to reverse).
|
||||
|
||||
Strings of the form $(...) are called macros and can be typed in
|
||||
directly as shown or can be selected from a menu by clicking
|
||||
a right arrow in the dialog box. $(ItemFileName) refers to the
|
||||
file name of the currently edited file without its path and without
|
||||
its extension. $(ItemExt) is its extension. $(ItemDir) represents
|
||||
the file's directory.
|
||||
|
||||
You will probably want to advance your new tool upward into the
|
||||
initial position of all tools while you are testing and modifying the
|
||||
command. You can do this by using the "Move Up" button that appears
|
||||
on the External Tools dialog.
|
||||
|
||||
The benefits of using "Initial Directory" are that file-names in lint
|
||||
error messages will not be so long, and, also, this directory can
|
||||
contain a std.lnt that overrides the global std.lnt in the
|
||||
Configuration Directory.
|
||||
|
||||
This Simple Check is fine to check stand-alone modules but to check
|
||||
projects or to unit check modules that are in projects we need to
|
||||
go a bit further ...
|
||||
|
||||
Project Creation
|
||||
----------------
|
||||
|
||||
To lint an entire project we will need the names of all the modules
|
||||
in the project. Visual Studio keeps these names (as well as some
|
||||
appropriate options such as define options (-d...) and include options
|
||||
(-i...) in a file named NAME.vcproj in the current project directory.
|
||||
NAME is the name of the project and is identified by the macro
|
||||
$(TargetName). PC-lint can read the .vcproj file and generate the
|
||||
appropriate .lnt file. We recommend creating a tool for this purpose.
|
||||
For this tool follow the steps 1-4 doing exactly the same thing as
|
||||
above except in step 3, the information entered should be:
|
||||
|
||||
Title: PC-lint (Project Creation)
|
||||
Command: c:\lint\lint-nt.exe
|
||||
Arguments: -v -os("$(TargetName).lnt") "$(ProjectFileName)"
|
||||
Init. Dir.: $(ProjectDir)
|
||||
|
||||
__Use Output Window __Prompt for arguments x_Close on exit
|
||||
|
||||
You will need to have an active project before this will work.
|
||||
If you don't already have one you can obtain an active project
|
||||
from the Solutions Explorer. You then click the newly added
|
||||
"PC-lint (Project Creation)" tool on the tools menu to create
|
||||
NAME.lnt.
|
||||
|
||||
The file created is an ASCII file and we recommend that you open it
|
||||
within the IDE and examine it for any obvious flaws. This is your
|
||||
chance to make any necessary modifications to the file as the process
|
||||
of conversion may be less than perfect.
|
||||
|
||||
Project Check
|
||||
-------------
|
||||
|
||||
Interestingly, by opening up the NAME.lnt file created above and
|
||||
running the Simple Check described earlier you have the equivalent
|
||||
of a full project check. However, we prefer to create a special
|
||||
Project Check tool.
|
||||
|
||||
Now that we have a project file we can create a new tool called
|
||||
"PC-lint (project check)". For this tool again follow steps 1-4 doing
|
||||
exactly the same thing as above except in step 3, the information
|
||||
entered should be:
|
||||
|
||||
Title: PC-lint (Project Check)
|
||||
Command: c:\lint\lint-nt.exe
|
||||
Arguments: -i"c:\lint" std.lnt env-vc10.lnt "$(TargetName).lnt"
|
||||
Init. Dir.: $(ProjectDir)
|
||||
|
||||
X_Use Output Window __Prompt for arguments __Close on exit
|
||||
|
||||
Unit Check
|
||||
----------
|
||||
|
||||
You can almost do a unit check on any single module by using the
|
||||
Simple Check scheme suggested above. The only problems are that you
|
||||
will need a -u option and you will not have the benefit of any -d or
|
||||
-i options that have been placed into NAME.lnt created in the Project
|
||||
Creation step. For this reason we suggest the following tool for
|
||||
doing a unit check of any module that is part of a project and for
|
||||
which a .lnt project file has been generated.
|
||||
|
||||
Title: PC-lint (Unit Check)
|
||||
Command: c:\lint\lint-nt.exe
|
||||
Arguments:
|
||||
-i"c:\lint" std.lnt env-vc10.lnt --u "$(TargetName).lnt" "$(ItemPath)"
|
||||
|
||||
Init. Dir.: $(ProjectDir)
|
||||
|
||||
X_Use Output Window __Prompt for arguments __Close on exit
|
||||
|
||||
Note that $(ItemPath) will provide a complete path name and in the
|
||||
absence of a project.lnt file it would cause full path names to
|
||||
appear in messages. But a side effect of using the project file
|
||||
with the --u option means that we adopt the shorter names used
|
||||
in the project file.
|
||||
|
||||
Suppressing Messages
|
||||
----------- --------
|
||||
|
||||
Suppressing messages is normally done by adding message suppression
|
||||
options to a file. For example, -e550 will suppress message 550.
|
||||
There are numerous other options to suppress messages.
|
||||
|
||||
As the documentation indicates, the file
|
||||
|
||||
c:\lint\options.lnt
|
||||
|
||||
(where c:\lint\ is the Configuration Directory) is the presumed
|
||||
container of your overall suppression policy. (Note: options.lnt is
|
||||
referenced by std.lnt). Add a message suppression here and you will
|
||||
affect all linting employing that configuration.
|
||||
|
||||
To suppress messages for a particular project (or for all projects
|
||||
within a given project directory) you may do the following:
|
||||
Create a file std.lnt that is contained in the project directory.
|
||||
Make it refer back to the std.lnt in the Configuration Directory.
|
||||
Then add additional message suppression options or indeed any options
|
||||
you want. For example it might contain:
|
||||
|
||||
c:\lint\std.lnt // reference to original std.lnt
|
||||
-e550 // project-specific option
|
||||
|
||||
In this way suppression is limited to a particular project.
|
||||
|
||||
|
||||
Tool Bar
|
||||
--------
|
||||
|
||||
You also have the option of creating a PC-lint toolbar within your
|
||||
Visual C++ IDE. First, create one or more tools as described above.
|
||||
You will need to know the number(s) of the tool(s) you want to place
|
||||
on the tool bar. This can only be done by the painful and laborious
|
||||
task of counting. Using the list provided by "Tools"/"External
|
||||
Tools", jot down the numbers (starting with 1 at the top) of all the
|
||||
tools to be added to the tool bar. We recommend placing all the
|
||||
PC-lint tools on a single tool bar. Then select Customize from the
|
||||
Tools menu. Select the Toolbars tab and click the New... button.
|
||||
Give the Toolbar a name (E.g., PC-lint) in the dialog box provided
|
||||
and click "OK". Confirm that the new toolbar is now floating on
|
||||
the desktop and that a check has been placed in the check box next
|
||||
to the new toolbar name. Then click on the Commands tab and
|
||||
select the "Toolbar:" radio button. Open the drop down list and
|
||||
select "PC-Lint" from the choices. Click the "Add Command..."
|
||||
button to reveal the "Add Command" window. In the "Categories:"
|
||||
box scroll down to and select the "Tools" item. In the
|
||||
"Commands:" box scroll down to and select the appropriate
|
||||
"External Command" numbered item that corresponds to the desired
|
||||
PC-Lint command, then click the OK button to add the selected item
|
||||
to the PC-Lint toolbar. Repeat the "Add Command..." process for
|
||||
each desired PC-Lint command the you wish to place on the PC-Lint
|
||||
toolbar.
|
||||
|
||||
If you want to add a button image to the toolbar, you can choose one
|
||||
via the Modify Selection button. Click Close and you now have your
|
||||
own PC-lint for C/C++ button. (Note: If you change the location of
|
||||
the PC-lint menu item on the Tools menu, you will change the subscript
|
||||
and you will need to change the button(s) on the toolbar.)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
-"format=%(%F(%l):%) error %n: (%t -- %m)" // Messages will contain
|
||||
// file information (%F), the line number (%l), the
|
||||
// message number (%n), message type (%t) and message text (%m).
|
||||
|
||||
-hF2 // Make sure we ALWAYS provide file information ('F') and use 2
|
||||
// lines (one for the source line in error and one for the
|
||||
// message).
|
||||
|
||||
-width(0) // don't break messages at any particular width
|
||||
-t4 // Presume that tabs are every 4 stops
|
||||
//+e900 // issue a message at termination.
|
|
@ -0,0 +1,17 @@
|
|||
/* Date Stamp */ -d"_lint_lib_ole_lnt=lib-ole.lnt modified 23-Mar-2004"
|
||||
/* To document usage use: -message( "Using " _lint_lib_ole_lnt ) */
|
||||
// ---------------------------------------------------------------------
|
||||
// This file is provided by Gimpel Software (www.gimpel.com) for use with
|
||||
// its products PC-lint and FlexeLint.
|
||||
//
|
||||
// Redistribution and use of this file, with or without modification, is
|
||||
// permitted provided that any such redistribution retains this notice.
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
// BSTR functions (part of OLE Automation)
|
||||
|
||||
-sem( SysAllocString, @p == malloc(1p) || @p == 0, 1p )
|
||||
-sem( SysAllocStringByteLen, @P == malloc(2n+1) || @p == 0 )
|
||||
-sem( SysAllocStringLen, @p == malloc(2n+1) || @p == 0 )
|
||||
-sem( SysStringLen, 1p ? @n == 1p - 1 : @n == 0 )
|
||||
-function( free, SysFreeString )
|
|
@ -0,0 +1,56 @@
|
|||
/* Date Stamp */ -d"_lint_lib_w32_lnt=lib-w32.lnt modified 2-Mar-1999"
|
||||
/* To document usage use: -message( "Using " _lint_lib_w32_lnt ) */
|
||||
// ---------------------------------------------------------------------
|
||||
// This file is provided by Gimpel Software (www.gimpel.com) for use with
|
||||
// its products PC-lint and FlexeLint.
|
||||
//
|
||||
// Redistribution and use of this file, with or without modification, is
|
||||
// permitted provided that any such redistribution retains this notice.
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
// lib-w32.lnt
|
||||
// PC-lint Library Options File for 32-bit mode windows.h
|
||||
|
||||
-d__FLAT__
|
||||
-d_WIN32
|
||||
-si4
|
||||
-sp4
|
||||
-esym(14,pLocalHeap) // variable defined in windows.h
|
||||
-e740 // remove 'suspicious cast' messages because these must be
|
||||
// routinely done within Windows.
|
||||
-elib(46) // windows.h uses a BYTE as base of bit field.
|
||||
-e793 // windows breaks ANSI limits
|
||||
|
||||
// the following functions have their return value typically ignored.
|
||||
// add or subtract from this list as desired.
|
||||
-esym(534,RegisterClass,ShowWindow,TranslateMessage,DispatchMessage)
|
||||
-esym(534,DrawText,GetTextMetrics,ReleaseDC,TextOut,SetTextAlign)
|
||||
-esym(534,SetScrollPos,SelectObject,SetBkMode,SendMessage,MessageBox)
|
||||
-esym(534,MessageBoxA,MessageBoxW,PostMessageA,PostMessageW)
|
||||
-esym(534,PatBlt,DeleteDC,SetCapture,SetCursor,StretchBlt)
|
||||
-esym(534,Rectangle,MoveTo,LineTo,ShowCursor,MoveWindow,SetWindowWord)
|
||||
-esym(534,SetPixel,FillRect,DeleteObject,KillTimer,GetProfileString)
|
||||
-esym(534,SetWindowLong,SetFocus,SetBkColor,SetTextColor,SetBrushOrg)
|
||||
-esym(534,UnrealizeObject,_lclose,Polygon,FrameRect,LoadString)
|
||||
-esym(534,GetInstanceData,GlobalUnlock,FreeResource,LoadString)
|
||||
-esym(534,DrawIcon,AppendMenu,GetObject,CheckMenuItem,SetClassWord)
|
||||
-esym(534,EnableMenuItem,SetMenu,DestroyMenu,TrackPopupMenu)
|
||||
-esym(534,AnsiUpper,Arc,BeginPaint,BitBlt,ChangeClipboardChain,Chord)
|
||||
-esym(534,CloseClipboard,CombineRgn,DdeClientTransaction,DdeDisconnect)
|
||||
-esym(534,DdeFreeStringHandle,DdeGetData,DdeNameService,DdePostAdvise)
|
||||
-esym(534,DdeQueryString,DdeUninitialize,DeleteMenu,DeleteMetaFile)
|
||||
-esym(534,DestroyWindow,DialogBox,DPtoLP,Ellipse,EmptyClipboard,EnableWindow)
|
||||
-esym(534,EnumChildWindows,EnumWindows,Escape,GetClassName,GetDlgItemText)
|
||||
-esym(534,GetFileTitle,GetMenuString,GetStrings,GetSystemMenu,GetTextFace)
|
||||
-esym(534,GetWindowText,GlobalDeleteAtom,GlobalFree,GlobalGetAtomName)
|
||||
-esym(534,LocalFree,LocalUnlock,LockResource,lstrcpy,OpenClipboard)
|
||||
-esym(534,Pie,PlayMetaFile,PopFindNextText,PostDataMessage,PostMessage)
|
||||
-esym(534,RestoreDC,SaveDC,SelectClipRgn,SendDlgItemMessage,SetClipboardData)
|
||||
-esym(534,SetDIBitsToDevice,SetMapMode,SetMapperFlags,SetROP2,SetStretchBltMode)
|
||||
-esym(534,SetTextJustification,SetTimer,SetViewportExt,SetViewportOrg)
|
||||
-esym(534,SetWindowExt,SetWindowOrg,StretchDIBits,WinExec)
|
||||
|
||||
// Ignored parameters
|
||||
-esym(715,lpszCmdParam,lpszCmdLine)
|
||||
|
||||
-emacro(648,PSN_*) // ignore unsigned overflow (0-200U)
|
|
@ -0,0 +1,85 @@
|
|||
# This file contains functions and configurations for generating PC-Lint build
|
||||
# targets for your CMake projects.
|
||||
|
||||
set(PC_LINT_EXECUTABLE "C:/Lint/lint-nt.exe" CACHE STRING "full path to the pc-lint executable. NOT the generated lin.bat")
|
||||
set(PC_LINT_CONFIG_DIR "${PROJECT_SOURCE_DIR}/lint/msvc" CACHE STRING "full path to the directory containing pc-lint configuration files")
|
||||
set(PC_LINT_USER_FLAGS "-b" CACHE STRING "additional pc-lint command line options -- some flags of pc-lint cannot be set in option files (most notably -b)")
|
||||
|
||||
# a phony target which causes all available *_LINT targets to be executed
|
||||
add_custom_target(ALL_LINT)
|
||||
|
||||
# add_pc_lint(target source1 [source2 ...])
|
||||
#
|
||||
# Takes a list of source files and generates a build target which can be used
|
||||
# for linting all files
|
||||
#
|
||||
# The generated lint commands assume that a top-level config file named
|
||||
# 'std.lnt' resides in the configuration directory 'PC_LINT_CONFIG_DIR'. This
|
||||
# config file must include all other config files. This is standard lint
|
||||
# behaviour.
|
||||
#
|
||||
# Parameters:
|
||||
# - target: the name of the target to which the sources belong. You will get a
|
||||
# new build target named ${target}_LINT
|
||||
# - source1 ... : a list of source files to be linted. Just pass the same list
|
||||
# as you passed for add_executable or add_library. Everything except
|
||||
# C and CPP files (*.c, *.cpp, *.cxx) will be filtered out.
|
||||
#
|
||||
# Example:
|
||||
# If you have a CMakeLists.txt which generates an executable like this:
|
||||
#
|
||||
# set(MAIN_SOURCES main.c foo.c bar.c)
|
||||
# add_executable(main ${MAIN_SOURCES})
|
||||
#
|
||||
# include this file
|
||||
#
|
||||
# include(/path/to/pc_lint.cmake)
|
||||
#
|
||||
# and add a line to generate the main_LINT target
|
||||
#
|
||||
# if(COMMAND add_pc_lint)
|
||||
# add_pc_lint(main ${MAIN_SOURCES})
|
||||
# endif(COMMAND add_pc_lint)
|
||||
#
|
||||
function(add_pc_lint target)
|
||||
get_directory_property(lint_include_directories INCLUDE_DIRECTORIES)
|
||||
get_directory_property(lint_defines COMPILE_DEFINITIONS)
|
||||
|
||||
# let's get those elephants across the alps
|
||||
# prepend each include directory with "-i"; also quotes the directory
|
||||
set(lint_include_directories_transformed)
|
||||
foreach(include_dir ${lint_include_directories})
|
||||
list(APPEND lint_include_directories_transformed -i"${include_dir}")
|
||||
endforeach(include_dir)
|
||||
|
||||
# prepend each definition with "-d"
|
||||
set(lint_defines_transformed)
|
||||
foreach(definition ${lint_defines})
|
||||
list(APPEND lint_defines_transformed -d${definition})
|
||||
endforeach(definition)
|
||||
|
||||
# list of all commands, one for each given source file
|
||||
set(pc_lint_commands)
|
||||
|
||||
foreach(sourcefile ${ARGN})
|
||||
# only include c and cpp files
|
||||
if( sourcefile MATCHES \\.c$|\\.cxx$|\\.cpp$ )
|
||||
# make filename absolute
|
||||
get_filename_component(sourcefile_abs ${sourcefile} ABSOLUTE)
|
||||
# create command line for linting one source file and add it to the list of commands
|
||||
list(APPEND pc_lint_commands
|
||||
COMMAND ${PC_LINT_EXECUTABLE}
|
||||
-i"${PC_LINT_CONFIG_DIR}" std.lnt
|
||||
"-u" ${PC_LINT_USER_FLAGS}
|
||||
${lint_include_directories_transformed}
|
||||
${lint_defines_transformed}
|
||||
${sourcefile_abs})
|
||||
endif()
|
||||
endforeach(sourcefile)
|
||||
|
||||
# add a custom target consisting of all the commands generated above
|
||||
add_custom_target(${target}_LINT ${pc_lint_commands} VERBATIM)
|
||||
# make the ALL_LINT target depend on each and every *_LINT target
|
||||
add_dependencies(ALL_LINT ${target}_LINT)
|
||||
|
||||
endfunction(add_pc_lint)
|
|
@ -0,0 +1,4 @@
|
|||
co-msc100.lnt
|
||||
env-vc10.lnt
|
||||
lib-w32.lnt
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
\mainpage XCP Seed and Key shared library (SeedNKey)
|
||||
\details
|
||||
\tableofcontents
|
||||
\section into Introduction
|
||||
The OpenBLT bootloader is an open source project, allowing everyone to access the
|
||||
sources. One downside of this is that if someone knows the OpenBLT bootloader is used
|
||||
in your product, it is relatively easy for them to figure out how to update the
|
||||
firmware in your product. Although this could be a feature of your product, in most
|
||||
cases it is not desirable.
|
||||
|
||||
For this reason the bootloader contains a seed/key security module. If this security
|
||||
module is enabled in the bootloader's configuration, updates can only be made by users
|
||||
that have the correct algorithm inside this Seed and Key shared library. If not, then
|
||||
new firmware update requests are rejected by the bootloader.
|
||||
|
||||
The SeedNKey project is preconfigured to build this Seed and Key shared library. Its
|
||||
default implemented seed and key algorithm works together with those implemented in
|
||||
the OpenBLT demo bootloaders. You are free and encouraged to update this algorithm to
|
||||
match your security needs.
|
||||
|
||||
On the bootloader target side (microcontroller), this security module is enabled by
|
||||
setting configurable BOOT_XCP_SEED_KEY_ENABLE to a value of 1 in the bootloader's
|
||||
configuration header file (blt_conf.h). The implementation of the seed and key algorithm
|
||||
can be made in the hook-functions XcpGetSeedHook() and XcpVerifyKeyHook().
|
||||
|
||||
On the host side (PC), you simply specify the Seed and Key shared library file that this
|
||||
preconfigured project built. In MicroBoot this shared library can be specified through
|
||||
the settings user interface. In BootCommander it is specified via a command line option.
|
||||
|
||||
Refer to the OpenBLT website for additional information regarding the XCP Seed and Key
|
||||
shared library, including step-by-step instructions on how to build it:
|
||||
https://www.feaser.com/openblt/doku.php?id=manual:security
|
||||
php?id=manual:libopenblt.
|
||||
|
||||
\verbatim
|
||||
----------------------------------------------------------------------------------------
|
||||
C O P Y R I G H T
|
||||
----------------------------------------------------------------------------------------
|
||||
Copyright (c) 2017 Feaser. All rights reserved.
|
||||
|
||||
----------------------------------------------------------------------------------------
|
||||
L I C E N S E
|
||||
----------------------------------------------------------------------------------------
|
||||
This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
----------------------------------------------------------------------------------------
|
||||
\endverbatim
|
||||
|
||||
*/
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/************************************************************************************//**
|
||||
* \file seednkey.c
|
||||
* \brief XCP Seed and Key shared library source file.
|
||||
* \ingroup SeedNKey
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2017 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
|
||||
/****************************************************************************************
|
||||
* Include files
|
||||
****************************************************************************************/
|
||||
#include <assert.h> /* for assertions */
|
||||
#include <stddef.h> /* for NULL declaration */
|
||||
#include "seednkey.h" /* XCP seed and key */
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Computes the key for the requested resource.
|
||||
** \param resource resource for which the unlock key is requested
|
||||
** \param seedLen length of the seed
|
||||
** \param seedPtr pointer to the seed data
|
||||
** \param keyLenPtr pointer where to store the key length
|
||||
** \param keyPtr pointer where to store the key data
|
||||
** \return XCP_RESULT_OK on success, otherwise XCP_RESULT_ERROR.
|
||||
**
|
||||
****************************************************************************************/
|
||||
LIBOPENBLT_EXPORT uint32_t XCP_ComputeKeyFromSeed(uint8_t resource, uint8_t seedLen,
|
||||
uint8_t const * seedPtr,
|
||||
uint8_t * keyLenPtr,
|
||||
uint8_t * keyPtr)
|
||||
{
|
||||
uint32_t result = XCP_RESULT_ERROR;
|
||||
uint8_t idx;
|
||||
|
||||
/* Check parameters. */
|
||||
assert(seedLen > 0);
|
||||
assert(seedPtr != NULL);
|
||||
assert(keyLenPtr != NULL);
|
||||
assert(keyPtr != NULL);
|
||||
|
||||
/* Only continue if the parameters are valid. */
|
||||
if ( (seedLen > 0) && (seedPtr != NULL) && (keyLenPtr != NULL) &&
|
||||
(keyPtr != NULL) ) /*lint !e774 */
|
||||
{
|
||||
/* This example implementation of the key algorithm for PGM simply decrements the value
|
||||
* of each seed byte by 1. This coincides with the default implementation of the hook-
|
||||
* function XcpVerifyKeyHook() in the OpenBLT demo bootloaders.
|
||||
*/
|
||||
if (resource == XCP_RESOURCE_PGM)
|
||||
{
|
||||
/* Compute the key. */
|
||||
for (idx = 0; idx < seedLen; idx++)
|
||||
{
|
||||
keyPtr[idx] = seedPtr[idx] - 1;
|
||||
}
|
||||
/* Set the key length. */
|
||||
*keyLenPtr = seedLen;
|
||||
/* Update the result value. */
|
||||
result = XCP_RESULT_OK;
|
||||
}
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of XCP_ComputeKeyFromSeed ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Computes the key for the requested resource.
|
||||
** \param resourcePtr pointer where to store the supported resources for the key
|
||||
** computation.
|
||||
** \return XCP_RESULT_OK on success, otherwise XCP_RESULT_ERROR.
|
||||
**
|
||||
****************************************************************************************/
|
||||
LIBOPENBLT_EXPORT uint32_t XCP_GetAvailablePrivileges(uint8_t * resourcePtr)
|
||||
{
|
||||
uint32_t result = XCP_RESULT_ERROR;
|
||||
|
||||
/* Check parameters. */
|
||||
assert(resourcePtr != NULL);
|
||||
|
||||
/* Only continue if the parameter is valid. */
|
||||
if (resourcePtr != NULL) /*lint !e774 */
|
||||
{
|
||||
/* This example implementation supports a key computation algorithm for the PGM
|
||||
* resource.
|
||||
*/
|
||||
*resourcePtr = XCP_RESOURCE_PGM;
|
||||
/* Update the result value. */
|
||||
result = XCP_RESULT_OK;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of XCP_GetAvailablePrivileges ***/
|
||||
|
||||
|
||||
/*********************************** end of seednkey.c *********************************/
|
||||
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/************************************************************************************//**
|
||||
* \file seednkey.h
|
||||
* \brief XCP Seed and Key shared library header file.
|
||||
* \ingroup SeedNKey
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2017 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
/************************************************************************************//**
|
||||
* \defgroup SeedNKey XCP Seed/Key
|
||||
* \brief XCP Seed and Key shared library.
|
||||
* \details
|
||||
* This shared library implements an example XCP Seed and Key protection algorithm. If the
|
||||
* OpenBLT bootloader on the microcontroller is configured to support this protection,
|
||||
* this shared library file must be configured in the firmware update tool on the host
|
||||
* (for example MicroBoot or BootCommander). The OpenBLT bootloader will reject new
|
||||
* firmware update requests, if an incorrect XCP Seed and Key protection algorithm is
|
||||
* specified.
|
||||
*
|
||||
* You are free and even encouraged to change the protection algorithm in this shared
|
||||
* library to however you see fit to protect your target from unwanted firmware updates.
|
||||
****************************************************************************************/
|
||||
#ifndef SEEDNKEY_H
|
||||
#define SEEDNKEY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****************************************************************************************
|
||||
* Include files
|
||||
****************************************************************************************/
|
||||
#include <stdint.h> /* for standard integer types */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Macro definitions
|
||||
****************************************************************************************/
|
||||
/* CMake automatically defines macro seednkey_shared_EXPORTS when building the shared
|
||||
* version of the library. When building under windows, this is used to set the export
|
||||
* macro, which is needed to confige the library functions.
|
||||
*/
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#if defined(seednkey_shared_EXPORTS)
|
||||
#define LIBOPENBLT_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define LIBOPENBLT_EXPORT
|
||||
#endif /* seednkey_shared_EXPORTS */
|
||||
#else /* defined(_WIN32) || defined(_WIN64) */
|
||||
#define LIBOPENBLT_EXPORT
|
||||
#endif
|
||||
|
||||
/* Result values. */
|
||||
/** \brief Result value in case of success. */
|
||||
#define XCP_RESULT_OK (0u)
|
||||
/** \brief Result value in case of error. */
|
||||
#define XCP_RESULT_ERROR (1u)
|
||||
|
||||
|
||||
/* XCP supported resources. */
|
||||
/** \brief XCP ProGraMing resource. */
|
||||
#define XCP_RESOURCE_PGM (0x10u)
|
||||
/** \brief XCP data STIMulation resource. */
|
||||
#define XCP_RESOURCE_STIM (0x08u)
|
||||
/** \brief XCP Data AcQuisition resource. */
|
||||
#define XCP_RESOURCE_DAQ (0x04u)
|
||||
/** \brief XCP CALibration and PAGing resource. */
|
||||
#define XCP_RESOURCE_CALPAG (0x01u)
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
LIBOPENBLT_EXPORT uint32_t XCP_ComputeKeyFromSeed(uint8_t resource, uint8_t seedLen,
|
||||
uint8_t const * seedPtr,
|
||||
uint8_t * keyLenPtr,
|
||||
uint8_t * keyPtr);
|
||||
LIBOPENBLT_EXPORT uint32_t XCP_GetAvailablePrivileges(uint8_t * resourcePtr);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SEEDNKEY_H */
|
||||
/********************************* end of seednkey.h ***********************************/
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
|
@ -6,7 +6,7 @@ extended=0
|
|||
txid=1639
|
||||
rxid=2017
|
||||
[xcp]
|
||||
seedkey=
|
||||
seedkey=libseednkey.dll
|
||||
t1=1000
|
||||
t3=2000
|
||||
t4=10000
|
||||
|
|
Binary file not shown.
|
@ -6,7 +6,7 @@ extended=0
|
|||
txid=1639
|
||||
rxid=2017
|
||||
[xcp]
|
||||
seedkey=FeaserKey.dll
|
||||
seedkey=libseednkey.dll
|
||||
t1=1000
|
||||
t3=2000
|
||||
t4=10000
|
||||
|
|
Binary file not shown.
|
@ -6,7 +6,7 @@ extended=0
|
|||
txid=1639
|
||||
rxid=2017
|
||||
[xcp]
|
||||
seedkey=FeaserKey.dll
|
||||
seedkey=libseednkey.dll
|
||||
t1=1000
|
||||
t3=2000
|
||||
t4=10000
|
||||
|
|
Binary file not shown.
|
@ -2,7 +2,7 @@
|
|||
hostname=169.254.19.63
|
||||
port=1000
|
||||
[xcp]
|
||||
seedkey=FeaserKey.dll
|
||||
seedkey=libseednkey.dll
|
||||
t1=1000
|
||||
t3=2000
|
||||
t4=10000
|
||||
|
|
Binary file not shown.
|
@ -1,8 +1,8 @@
|
|||
[sci]
|
||||
port=9
|
||||
port=5
|
||||
baudrate=8
|
||||
[xcp]
|
||||
seedkey=FeaserKey.dll
|
||||
seedkey=libseednkey.dll
|
||||
t1=1000
|
||||
t3=2000
|
||||
t4=10000
|
||||
|
|
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
[xcp]
|
||||
seedkey=FeaserKey.dll
|
||||
seedkey=libseednkey.dll
|
||||
t1=1000
|
||||
t3=2000
|
||||
t4=10000
|
||||
|
|
Loading…
Reference in New Issue