Skip to content

Commit

Permalink
clang-tidy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Jan 9, 2021
1 parent bd2fc7b commit f0ddf31
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 125 deletions.
50 changes: 25 additions & 25 deletions flsemu/common.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP.
*
* (C) 2007-2020 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2021 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand Down Expand Up @@ -70,7 +70,7 @@ static FlsEmu_ConfigType const * FlsEmu_Config = XCP_NULL; /**< Segment configu
*/
void FlsEmu_Init(FlsEmu_ConfigType const * config)
{
uint8_t idx;
uint8_t idx = 0;

FlsEmu_SystemMemory.AllocationGranularity = FlsEmu_GetAllocationGranularity();
FlsEmu_Config = config;
Expand All @@ -83,7 +83,7 @@ void FlsEmu_Init(FlsEmu_ConfigType const * config)

void FlsEmu_DeInit(void)
{
uint8_t idx;
uint8_t idx = 0;

for (idx = 0; idx < FlsEmu_GetConfig()->numSegments; ++idx) {
//printf("UNLOAD-SEG-NAME: %s\n", FlsEmu_Config->segments[idx]->name);
Expand All @@ -94,13 +94,13 @@ void FlsEmu_DeInit(void)

void FlsEmu_OpenCreate(uint8_t segmentIdx)
{
int length;
unsigned int length = 0;
char rom[1024];
FlsEmu_SegmentType * segment;
FlsEmu_OpenCreateResultType result;
uint32_t fillerSize;
void * offset;
uint16_t numPages;
FlsEmu_SegmentType * segment = XCP_NULL;
FlsEmu_OpenCreateResultType result = 0;
uint32_t fillerSize = 0UL;
void * offset = XCP_NULL;
uint16_t numPages = 0U;
uint16_t pageIdx = 0U;

FLSEMU_ASSERT_INITIALIZED();
Expand Down Expand Up @@ -133,7 +133,7 @@ void FlsEmu_OpenCreate(uint8_t segmentIdx)
void * FlsEmu_BasePointer(uint8_t segmentIdx)
{
/// TODO: getSegment()
FlsEmu_SegmentType const * segment;
FlsEmu_SegmentType const * segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();

if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand All @@ -146,7 +146,7 @@ void * FlsEmu_BasePointer(uint8_t segmentIdx)

uint32_t FlsEmu_NumPages(uint8_t segmentIdx)
{
FlsEmu_SegmentType const * segment;
FlsEmu_SegmentType const * segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();

if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand All @@ -160,9 +160,9 @@ uint32_t FlsEmu_NumPages(uint8_t segmentIdx)

void FlsEmu_EraseSector(uint8_t segmentIdx, uint32_t address)
{
uint32_t mask;
uint16_t * ptr;
FlsEmu_SegmentType const * segment;
uint32_t mask = 0UL;
uint16_t * ptr = XCP_NULL;
FlsEmu_SegmentType const * segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand All @@ -182,7 +182,7 @@ void FlsEmu_EraseSector(uint8_t segmentIdx, uint32_t address)
void FlsEmu_ErasePage(uint8_t segmentIdx, uint8_t page)
{
uint8_t * ptr = (uint8_t * )FlsEmu_BasePointer(segmentIdx);
FlsEmu_SegmentType * segment;
FlsEmu_SegmentType * segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand All @@ -197,10 +197,10 @@ void FlsEmu_ErasePage(uint8_t segmentIdx, uint8_t page)
void FlsEmu_EraseBlock(uint8_t segmentIdx, uint16_t block)
{
/* TODO: Nur den entsprechenden Block mappen!!! */
uint8_t * ptr;
uint32_t offset;
uint32_t blockSize;
FlsEmu_SegmentType * segment;
uint8_t * ptr = XCP_NULL;
uint32_t offset = 0UL;
uint32_t blockSize = 0UL;
FlsEmu_SegmentType * segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand All @@ -218,9 +218,9 @@ void FlsEmu_EraseBlock(uint8_t segmentIdx, uint16_t block)

Xcp_MemoryMappingResultType FlsEmu_MemoryMapper(Xcp_MtaType * dst, Xcp_MtaType const * src)
{
uint8_t idx;
uint8_t * ptr;
FlsEmu_SegmentType * segment;
uint8_t idx = 0;
uint8_t * ptr = XCP_NULL;
FlsEmu_SegmentType * segment = XCP_NULL;

/* printf("addr: %x ext: %d\n", src->address, src->ext); */

Expand Down Expand Up @@ -248,7 +248,7 @@ Xcp_MemoryMappingResultType FlsEmu_MemoryMapper(Xcp_MtaType * dst, Xcp_MtaType c
*/
uint32_t FlsEmu_AllocatedSize(uint8_t segmentIdx)
{
FlsEmu_SegmentType const * segment;
FlsEmu_SegmentType const * segment = XCP_NULL;
FLSEMU_ASSERT_INITIALIZED();

if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand All @@ -257,8 +257,8 @@ uint32_t FlsEmu_AllocatedSize(uint8_t segmentIdx)
segment = FlsEmu_GetConfig()->segments[segmentIdx];

return FlsEmu_SystemMemory.AllocationGranularity * (
(segment->pageSize / FlsEmu_SystemMemory.AllocationGranularity) +
((segment->pageSize % FlsEmu_SystemMemory.AllocationGranularity) != 0) ? 1 : 0
((segment->pageSize / FlsEmu_SystemMemory.AllocationGranularity) +
((segment->pageSize % FlsEmu_SystemMemory.AllocationGranularity) != 0)) ? 1 : 0
);
}

Expand Down
18 changes: 9 additions & 9 deletions flsemu/posix/flsemu.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2007-2020 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2021 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand Down Expand Up @@ -57,7 +57,7 @@ uint32_t FlsEmu_GetAllocationGranularity(void)

void FlsEmu_Close(uint8_t segmentIdx)
{
FlsEmu_SegmentType const * segment;
FlsEmu_SegmentType const * segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand All @@ -71,7 +71,7 @@ void FlsEmu_Close(uint8_t segmentIdx)

static bool FlsEmu_Flush(uint8_t segmentIdx)
{
FlsEmu_SegmentType const * segment;
FlsEmu_SegmentType const * segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();

Expand All @@ -96,7 +96,7 @@ static void FlsEmu_ClosePersitentArray(FlsEmu_PersistentArrayType const * persis

static void FlsEmu_MapAddress(void * mappingAddress, int offset, uint32_t size, int fd)
{
void * res;
void * res = XCP_NULL;

res = mmap(mappingAddress, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
if (res == MAP_FAILED) {
Expand All @@ -113,9 +113,9 @@ static void FlsEmu_UnmapAddress(void * addr, uint32_t size)

FlsEmu_OpenCreateResultType FlsEmu_OpenCreatePersitentArray(char const * fileName, uint32_t size, FlsEmu_PersistentArrayType * persistentArray)
{
int fd;
void * addr;
FlsEmu_OpenCreateResultType result;
int fd = 0;
void * addr = XCP_NULL;
FlsEmu_OpenCreateResultType result = 0;
bool newFile = XCP_FALSE;

fd = open(fileName, O_RDWR | O_DIRECT | O_DSYNC, 0666);
Expand Down Expand Up @@ -162,8 +162,8 @@ FlsEmu_OpenCreateResultType FlsEmu_OpenCreatePersitentArray(char const * fileNam

void FlsEmu_SelectPage(uint8_t segmentIdx, uint8_t page)
{
uint32_t offset;
FlsEmu_SegmentType * segment;
uint32_t offset = 0UL;
FlsEmu_SegmentType * segment = XCP_NULL;

FLSEMU_ASSERT_INITIALIZED();
if (!FLSEMU_VALIDATE_SEGMENT_IDX(segmentIdx)) {
Expand Down
4 changes: 2 additions & 2 deletions inc/xcp_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ extern "C"
#endif

#if !defined(XCP_MAX)
#define XCP_MAX(l, r) ((l) > (r) ? (l) : (r)) /**< Computes the maximum of \a l and \a r. */
#define XCP_MAX(l, r) (((l) > (r)) ? (l) : (r)) /**< Computes the maximum of \a l and \a r. */
#endif

#if !defined(XCP_MIN)
#define XCP_MIN(l, r) ((l) < (r) ? (l) : (r)) /**< Computes the minimum of \a l and \a r. */
#define XCP_MIN(l, r) (((l) < (r)) ? (l) : (r)) /**< Computes the minimum of \a l and \a r. */
#endif

#if !defined(XCP_TRUE)
Expand Down
19 changes: 9 additions & 10 deletions src/hw/linux/hw.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2007-2020 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2021 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand Down Expand Up @@ -30,7 +30,6 @@
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
//#include <semaphore.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -84,8 +83,6 @@ static void DeinitTUI(void);

void endwin(void); /* We don't want to include ncurses.h */

void XcpTl_PrintConnectionInformation(void);

static void DisplayHelp(void);
static void SystemInformation(void);

Expand Down Expand Up @@ -161,6 +158,8 @@ static void termination_handler(int sig)
case SIGSEGV:
printf("SIGSEGV");
break;
default:
printf("Signal: %u", sig);
}
printf(".\n");
exit(9);
Expand Down Expand Up @@ -266,7 +265,7 @@ void XcpHw_Deinit(void)

void XcpHw_SignalApplicationState(uint32_t state, uint8_t signal_all)
{
int status;
int status = 0;

status = pthread_mutex_lock(&XcpHw_ApplicationState.stateMutex);
if (status != 0) {
Expand All @@ -290,7 +289,7 @@ void XcpHw_SignalApplicationState(uint32_t state, uint8_t signal_all)

void XcpHw_ResetApplicationState(uint32_t mask)
{
int status;
int status = 0;

status = pthread_mutex_lock(&XcpHw_ApplicationState.stateMutex);
if (status != 0) {
Expand All @@ -305,7 +304,7 @@ void XcpHw_ResetApplicationState(uint32_t mask)

void XcpHw_CondResetApplicationState(uint32_t mask)
{
uint8_t idx;
uint8_t idx = 0;

for (idx = 0; idx < 31; ++idx) {
//printf("idx: %u mask: %u\n");
Expand All @@ -318,7 +317,7 @@ void XcpHw_CondResetApplicationState(uint32_t mask)

uint32_t XcpHw_WaitApplicationState(uint32_t mask)
{
int status;
int status = 0;
int match = 0;
#if 0
struct timespec timeout;
Expand Down Expand Up @@ -364,7 +363,7 @@ uint32_t XcpHw_GetTimerCounter(void)
{
struct timespec now = {0};
struct timespec dt = {0};
unsigned long long timestamp;
unsigned long long timestamp = 0ULL;

if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) {
XcpHw_ErrorMsg("XcpHw_Init::clock_getres()", errno);
Expand Down Expand Up @@ -481,7 +480,7 @@ static void DisplayHelp(void)
static void SystemInformation(void)
{
#if XCP_ENABLE_STATISTICS == XCP_ON
Xcp_StateType * state;
Xcp_StateType * state = NULL;
#endif /* XCP_ENABLE_STATISTICS */

printf("\nSystem-Information\n");
Expand Down
16 changes: 10 additions & 6 deletions src/hw/linux/tui.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2007-2020 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2021 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand Down Expand Up @@ -67,7 +67,8 @@ static const char TITLE[] = "Blueparrot XCP";

static void centered_text(WINDOW * win, int row, char const * text, int attrs)
{
int maxX, maxY;
unsigned int maxX = 0;
unsigned int maxY = 0;

getmaxyx(win, maxY, maxX);
XCP_UNREFERENCED_PARAMETER(maxY);
Expand All @@ -85,7 +86,7 @@ static WINDOW * centered_window(int height, int width)

static WINDOW *create_newwin(int height, int width, int starty, int startx)
{
WINDOW *local_win;
WINDOW *local_win = NULL;
local_win = newwin(height, width, starty, startx);
box(local_win, 0 , 0); /* 0, 0 gives default characters
* for the vertical and horizontal
Expand All @@ -103,10 +104,13 @@ static void destroy_win(WINDOW *local_win)

void XcpTui_Init(void)
{
bool ext;
bool ext = FALSE;
char buf[128];
WINDOW *my_win;
int startx, starty, width, height;
WINDOW * my_win = NULL;
unsigned int startx = 0U;
unsigned int starty = 0U;
unsigned int width = 0U;
unsigned int height = 0U;

initscr();
raw();
Expand Down
12 changes: 2 additions & 10 deletions src/tl/can/linux_socket_can.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* BlueParrot XCP
*
* (C) 2007-2020 by Christoph Schueler <github.com/Christoph2,
* (C) 2007-2021 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
Expand Down Expand Up @@ -72,20 +72,12 @@ typedef struct tagXcpTl_ConnectionType {

unsigned char buf[XCP_COMM_BUFLEN];


static XcpTl_ConnectionType XcpTl_Connection;
extern Xcp_OptionsType Xcp_Options;

static uint8_t Xcp_PduOutBuffer[XCP_MAX_CTO] = {0};


void Xcp_DispatchCommand(Xcp_PDUType const * const pdu);

extern void endwin(void);

extern Xcp_PDUType Xcp_PduIn;
extern Xcp_PDUType Xcp_PduOut;


int locate_interface(int socket, char const * name)
{
Expand Down Expand Up @@ -156,7 +148,7 @@ void XcpTl_MainFunction(void)
void XcpTl_RxHandler(void)
{
struct canfd_frame frame;
int nbytes;
int nbytesi = 0;

nbytes = read(XcpTl_Connection.can_socket, &frame, CANFD_MTU);

Expand Down

0 comments on commit f0ddf31

Please sign in to comment.