Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/Interface/SolidSyslogBlockStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ EXTERN_C_BEGIN
enum
{
SOLIDSYSLOG_BLOCKSTORE_STORAGE_SIZE =
(sizeof(intptr_t) * 32) + SOLIDSYSLOG_MAX_MESSAGE_SIZE + SOLIDSYSLOG_MAX_INTEGRITY_SIZE + 16
(sizeof(intptr_t) * 32U) + SOLIDSYSLOG_MAX_MESSAGE_SIZE + SOLIDSYSLOG_MAX_INTEGRITY_SIZE + 16U
};

typedef struct
{
intptr_t slots[(SOLIDSYSLOG_BLOCKSTORE_STORAGE_SIZE + sizeof(intptr_t) - 1) / sizeof(intptr_t)];
intptr_t slots[(SOLIDSYSLOG_BLOCKSTORE_STORAGE_SIZE + sizeof(intptr_t) - 1U) / sizeof(intptr_t)];
} SolidSyslogBlockStoreStorage;

struct SolidSyslogStore* SolidSyslogBlockStore_Create(
Expand Down
2 changes: 1 addition & 1 deletion Core/Interface/SolidSyslogCircularBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ EXTERN_C_BEGIN
/* NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -- cannot compute array size as a constexpr in C */
#define SOLIDSYSLOG_CIRCULARBUFFER_STORAGE_SIZE_BYTES(ringBytes) \
(SOLIDSYSLOG_CIRCULARBUFFER_OVERHEAD + \
(((ringBytes) + sizeof(SolidSyslogCircularBufferStorage) - 1) / sizeof(SolidSyslogCircularBufferStorage)))
(((ringBytes) + sizeof(SolidSyslogCircularBufferStorage) - 1U) / sizeof(SolidSyslogCircularBufferStorage)))

/* NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -- cannot compute array size as a constexpr in C */
#define SOLIDSYSLOG_CIRCULARBUFFER_STORAGE_SIZE(maxMessages) \
Expand Down
4 changes: 2 additions & 2 deletions Core/Interface/SolidSyslogFileBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ EXTERN_C_BEGIN

enum
{
SOLIDSYSLOG_FILEBLOCKDEVICE_STORAGE_SIZE = sizeof(intptr_t) * 16
SOLIDSYSLOG_FILEBLOCKDEVICE_STORAGE_SIZE = sizeof(intptr_t) * 16U
};

typedef struct
{
intptr_t slots[(SOLIDSYSLOG_FILEBLOCKDEVICE_STORAGE_SIZE + sizeof(intptr_t) - 1) / sizeof(intptr_t)];
intptr_t slots[(SOLIDSYSLOG_FILEBLOCKDEVICE_STORAGE_SIZE + sizeof(intptr_t) - 1U) / sizeof(intptr_t)];
} SolidSyslogFileBlockDeviceStorage;

/* The driver caches at most one open SolidSyslogFile handle, re-pointed only when the
Expand Down
6 changes: 3 additions & 3 deletions Core/Interface/SolidSyslogFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ EXTERN_C_BEGIN

enum
{
SOLIDSYSLOG_FORMATTER_OVERHEAD = 2
SOLIDSYSLOG_FORMATTER_OVERHEAD = 2U
};

/* NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -- cannot compute array size as a constexpr in C */
#define SOLIDSYSLOG_FORMATTER_STORAGE_SIZE(bufferSize) \
(SOLIDSYSLOG_FORMATTER_OVERHEAD + \
(((bufferSize) + sizeof(SolidSyslogFormatterStorage) - 1) / sizeof(SolidSyslogFormatterStorage)))
(((bufferSize) + sizeof(SolidSyslogFormatterStorage) - 1U) / sizeof(SolidSyslogFormatterStorage)))

/* NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -- compile-time worst-case size for EscapedString output */
#define SOLIDSYSLOG_ESCAPED_MAX_SIZE(maxDecodedLength) (2 * (maxDecodedLength))
#define SOLIDSYSLOG_ESCAPED_MAX_SIZE(maxDecodedLength) (2U * (maxDecodedLength))

struct SolidSyslogFormatter;

Expand Down
2 changes: 1 addition & 1 deletion Core/Interface/SolidSyslogSecurityPolicyDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EXTERN_C_BEGIN
/* large enough for HMAC-SHA256 (32 bytes); CRC-16 uses 2 */
enum
{
SOLIDSYSLOG_MAX_INTEGRITY_SIZE = 32
SOLIDSYSLOG_MAX_INTEGRITY_SIZE = 32U
};

struct SolidSyslogSecurityPolicy
Expand Down
4 changes: 2 additions & 2 deletions Core/Interface/SolidSyslogStreamSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ EXTERN_C_BEGIN

enum
{
SOLIDSYSLOG_STREAM_SENDER_SIZE = (sizeof(intptr_t) * 7) + sizeof(uint32_t)
SOLIDSYSLOG_STREAM_SENDER_SIZE = (sizeof(intptr_t) * 7U) + sizeof(uint32_t)
};

typedef struct
{
intptr_t slots[(SOLIDSYSLOG_STREAM_SENDER_SIZE + sizeof(intptr_t) - 1) / sizeof(intptr_t)];
intptr_t slots[(SOLIDSYSLOG_STREAM_SENDER_SIZE + sizeof(intptr_t) - 1U) / sizeof(intptr_t)];
} SolidSyslogStreamSenderStorage;

struct SolidSyslogSender* SolidSyslogStreamSender_Create(
Expand Down
2 changes: 1 addition & 1 deletion Core/Interface/SolidSyslogTunablesDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#ifndef SOLIDSYSLOG_MAX_MESSAGE_SIZE
/* NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -- macro form required for preprocessor visibility (floor #if) and C array-size const-expr. */
#define SOLIDSYSLOG_MAX_MESSAGE_SIZE 2048 /* RFC 5424 section 6.1 SHOULD value */
#define SOLIDSYSLOG_MAX_MESSAGE_SIZE 2048U /* RFC 5424 section 6.1 SHOULD value */
#endif

#if SOLIDSYSLOG_MAX_MESSAGE_SIZE < 64
Expand Down
26 changes: 19 additions & 7 deletions Core/Source/BlockSequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

enum
{
MIN_MAX_BLOCKS = 2,
MAX_MAX_BLOCKS = 99,
SEQUENCE_MODULUS = 100
MIN_MAX_BLOCKS = 2U,
MAX_MAX_BLOCKS = 99U,
SEQUENCE_MODULUS = 100U
};

static inline uint8_t BlockSequence_NextSequence(uint8_t current)
{
return (uint8_t) ((current + 1) % SEQUENCE_MODULUS);
return (uint8_t) ((current + 1U) % SEQUENCE_MODULUS);
}

static inline size_t BlockSequence_BlockCount(const struct BlockSequence* blockSequence)
{
return (size_t) ((blockSequence->WriteSequence - blockSequence->OldestSequence + SEQUENCE_MODULUS) %
SEQUENCE_MODULUS) +
1;
1U;
}

// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) -- value, min, max have distinct semantics
Expand Down Expand Up @@ -151,6 +151,10 @@ static void BlockSequence_ScanForBlockPresence(struct BlockSequence* blockSequen
presence->FirstAbsent = seq;
presence->FoundAbsent = true;
}
else
{
/* present run already closed — nothing to record */
}
}
}

Expand Down Expand Up @@ -208,6 +212,10 @@ bool BlockSequence_PrepareForWrite(struct BlockSequence* blockSequence, size_t r
{
spaceAvailable = BlockSequence_RotateToNextBlock(blockSequence, readBlockChanged);
}
else
{
/* current block has room — leave spaceAvailable=true */
}

return spaceAvailable;
}
Expand Down Expand Up @@ -369,6 +377,10 @@ static inline void BlockSequence_NotifyThresholdCrossed(struct BlockSequence* bl
blockSequence->ThresholdCrossed = true;
blockSequence->OnThresholdCrossed(blockSequence->ThresholdContext);
}
else
{
/* still above threshold and already notified — no edge to report */
}
}
}

Expand All @@ -379,7 +391,7 @@ static inline bool BlockSequence_ThresholdEnabled(const struct BlockSequence* bl

static inline bool BlockSequence_IsAboveThreshold(const struct BlockSequence* blockSequence, size_t threshold)
{
return (threshold != 0) && (BlockSequence_UsedBytes(blockSequence) >= threshold);
return (threshold != 0U) && (BlockSequence_UsedBytes(blockSequence) >= threshold);
}

void BlockSequence_MarkWriteBlockCorrupt(struct BlockSequence* blockSequence)
Expand Down Expand Up @@ -482,7 +494,7 @@ size_t BlockSequence_UsedBytes(const struct BlockSequence* blockSequence)
}
else
{
size_t closedBlocks = BlockSequence_BlockCount(blockSequence) - 1;
size_t closedBlocks = BlockSequence_BlockCount(blockSequence) - 1U;
used = (closedBlocks * blockSequence->MaxBlockSize) + blockSequence->WritePosition;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Source/RecordStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct SolidSyslogBlockDevice;

enum
{
RECORD_BUFFER_SIZE = 2 + 2 + SOLIDSYSLOG_MAX_MESSAGE_SIZE + SOLIDSYSLOG_MAX_INTEGRITY_SIZE + 1
RECORD_BUFFER_SIZE = 2U + 2U + SOLIDSYSLOG_MAX_MESSAGE_SIZE + SOLIDSYSLOG_MAX_INTEGRITY_SIZE + 1U
};

struct RecordStore
Expand Down
15 changes: 8 additions & 7 deletions Core/Source/SolidSyslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ static inline bool SolidSyslog_PrivalComponentsAreValid(uint8_t facility, uint8_

static inline bool SolidSyslog_FacilityIsValid(uint8_t facility)
{
return facility <= SolidSyslogFacility_Local7;
return facility <= (uint8_t) SolidSyslogFacility_Local7;
}

static inline bool SolidSyslog_SeverityIsValid(uint8_t severity)
{
return severity <= SolidSyslogSeverity_Debug;
return severity <= (uint8_t) SolidSyslogSeverity_Debug;
}

static inline void SolidSyslog_FormatTimestamp(struct SolidSyslogFormatter* f, SolidSyslogClockFunction clock)
Expand Down Expand Up @@ -447,12 +447,12 @@ static inline void SolidSyslog_FormatUtcOffset(struct SolidSyslogFormatter* f, i

static inline void SolidSyslog_FormatNonZeroUtcOffset(struct SolidSyslogFormatter* f, int16_t offsetMinutes)
{
int16_t absoluteMinutes = SolidSyslog_AbsoluteInt16(offsetMinutes);
uint32_t absoluteMinutes = (uint32_t) SolidSyslog_AbsoluteInt16(offsetMinutes);

SolidSyslogFormatter_AsciiCharacter(f, (offsetMinutes > 0) ? '+' : '-');
SolidSyslogFormatter_TwoDigit(f, (uint32_t) (absoluteMinutes / 60));
SolidSyslogFormatter_TwoDigit(f, absoluteMinutes / 60U);
SolidSyslogFormatter_AsciiCharacter(f, ':');
SolidSyslogFormatter_TwoDigit(f, (uint32_t) (absoluteMinutes % 60));
SolidSyslogFormatter_TwoDigit(f, absoluteMinutes % 60U);
}

static inline int16_t SolidSyslog_AbsoluteInt16(int16_t value)
Expand Down Expand Up @@ -480,7 +480,7 @@ static inline void SolidSyslog_FormatStringField(

size_t fieldLength = SolidSyslogFormatter_Length(field);

if (fieldLength > 0)
if (fieldLength > 0U)
{
SolidSyslogFormatter_PrintUsAsciiString(f, SolidSyslogFormatter_AsFormattedBuffer(field), fieldLength);
}
Expand Down Expand Up @@ -544,7 +544,8 @@ static inline void SolidSyslog_FormatMsg(struct SolidSyslogFormatter* f, const c
* so the wire frame contains exactly one. */
static inline const char* SolidSyslog_SkipLeadingBom(const char* msg)
{
if ((msg[0] == '\xEF') && (msg[1] == '\xBB') && (msg[2] == '\xBF'))
const unsigned char* bytes = (const unsigned char*) msg;
if ((bytes[0] == 0xEFU) && (bytes[1] == 0xBBU) && (bytes[2] == 0xBFU))
{
return msg + 3;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Source/SolidSyslogAtomicCounter.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static struct SolidSyslogAtomicCounter instance;

static inline uint32_t AtomicCounter_NextSequenceId(uint32_t current)
{
return (current >= SEQUENCE_ID_MAX) ? 1U : current + 1U;
return (current >= SEQUENCE_ID_MAX) ? 1U : (current + 1U);
}

static inline bool AtomicCounter_TryAdvance(struct SolidSyslogAtomicU32* slot, uint32_t* nextOut)
Expand Down
8 changes: 4 additions & 4 deletions Core/Source/SolidSyslogCircularBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct SolidSyslogCircularBuffer

SOLIDSYSLOG_STATIC_ASSERT(
sizeof(struct SolidSyslogCircularBuffer) ==
SOLIDSYSLOG_CIRCULARBUFFER_OVERHEAD * sizeof(SolidSyslogCircularBufferStorage),
(SOLIDSYSLOG_CIRCULARBUFFER_OVERHEAD * sizeof(SolidSyslogCircularBufferStorage)),
"SOLIDSYSLOG_CIRCULARBUFFER_OVERHEAD does not match struct layout"
);

Expand Down Expand Up @@ -174,17 +174,17 @@ static inline bool CircularBuffer_RecordFitsAtTail(const struct SolidSyslogCircu
{
if (CircularBuffer_IsWrapped(circular))
{
return circular->Tail + recordBytes < circular->Head;
return (circular->Tail + recordBytes) < circular->Head;
}
return circular->Tail + recordBytes <= circular->Capacity;
return (circular->Tail + recordBytes) <= circular->Capacity;
}

static inline bool CircularBuffer_RecordFitsAfterWrap(
const struct SolidSyslogCircularBuffer* circular,
size_t recordBytes
)
{
return (!CircularBuffer_IsWrapped(circular)) && recordBytes < circular->Head;
return (!CircularBuffer_IsWrapped(circular)) && (recordBytes < circular->Head);
}

static inline void CircularBuffer_ResetToStart(struct SolidSyslogCircularBuffer* circular)
Expand Down
14 changes: 7 additions & 7 deletions Core/Source/SolidSyslogCrc16.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
* CRC-16/CCITT-FALSE (ITU-T V.41)
* Polynomial: 0x1021 Init: 0xFFFF RefIn: false RefOut: false XorOut: 0x0000
*
* Check value 0x29B1 from Greg Cook's CRC catalogue:
* https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-ibm-3740
* Check value 0x29B1 from Greg Cook's CRC catalogue
* (reveng.sourceforge.io/crc-catalogue/16.htm, entry crc-16-ibm-3740).
*/

#include "SolidSyslogCrc16.h"

enum
{
CRC16_CCITT_INIT = 0xFFFF,
CRC16_CCITT_POLY = 0x1021,
BITS_PER_BYTE = 8,
MSB_MASK = 0x8000
CRC16_CCITT_INIT = 0xFFFFU,
CRC16_CCITT_POLY = 0x1021U,
BITS_PER_BYTE = 8U,
MSB_MASK = 0x8000U
};

uint16_t SolidSyslogCrc16_Compute(const uint8_t* data, uint16_t length)
Expand All @@ -22,7 +22,7 @@ uint16_t SolidSyslogCrc16_Compute(const uint8_t* data, uint16_t length)

for (uint16_t i = 0; i < length; i++)
{
crc ^= (uint16_t) ((uint16_t) data[i] << BITS_PER_BYTE);
crc ^= (uint16_t) ((uint16_t) data[i] << 8U);

for (int bit = 0; bit < BITS_PER_BYTE; bit++)
{
Expand Down
12 changes: 6 additions & 6 deletions Core/Source/SolidSyslogFileBlockDevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ struct SolidSyslogFile;

enum
{
MAX_PATH_SIZE = 128
MAX_PATH_SIZE = 128U
};

static const char FILE_EXTENSION[] = ".log";

enum
{
SEQUENCE_DIGITS = 2,
FILENAME_SUFFIX = SEQUENCE_DIGITS + sizeof(FILE_EXTENSION) - 1,
MAX_PREFIX_LENGTH = MAX_PATH_SIZE - FILENAME_SUFFIX - 1,
SEQUENCE_DIGITS = 2U,
FILENAME_SUFFIX = SEQUENCE_DIGITS + sizeof(FILE_EXTENSION) - 1U,
MAX_PREFIX_LENGTH = (size_t) MAX_PATH_SIZE - (size_t) FILENAME_SUFFIX - 1U,
/* Two-digit on-disk sequence — indices > 99 cannot be represented
* uniquely. Without this guard, a wide blockIndex would be narrowed
* to uint8_t and alias an existing block (256 -> 00). */
MAX_BLOCK_INDEX = 99
MAX_BLOCK_INDEX = 99U
};

static inline bool FileBlockDevice_IsValidBlockIndex(size_t blockIndex)
Expand Down Expand Up @@ -247,7 +247,7 @@ static inline const char* FileBlockDevice_FormatBlockFilename(

SolidSyslogFormatter_BoundedString(formatter, device->PathPrefix, MAX_PREFIX_LENGTH);
SolidSyslogFormatter_TwoDigit(formatter, (uint8_t) blockIndex);
SolidSyslogFormatter_BoundedString(formatter, FILE_EXTENSION, sizeof(FILE_EXTENSION) - 1);
SolidSyslogFormatter_BoundedString(formatter, FILE_EXTENSION, sizeof(FILE_EXTENSION) - 1U);

return SolidSyslogFormatter_AsFormattedBuffer(formatter);
}
Expand Down
Loading
Loading