--- /dev/null
+Checks: "
+ *,
+ -altera-id-dependent-backward-branch,
+ -altera-struct-pack-align,
+ -altera-unroll-loops,
+ -bugprone-easily-swappable-parameters,
+ -cert-err33-c,
+ -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
+ -cppcoreguidelines-avoid-magic-numbers,
+ -llvm-header-guard,
+ -llvmlibc-restrict-system-libc-headers,
+ -readability-*,
+"
unsigned char *buf = NULL;
size_t len = 0;
if (!Mmap(&buf, &len, argv[i])) {
- fprintf(stderr, "%s: %s\n", argv[i], strerror(errno));
- exit(EXIT_FAILURE);
+ fprintf(
+ stderr,
+ "%s: %s\n",
+ argv[i],
+ strerror(errno)); // NOLINT(concurrency-mt-unsafe)
+ exit(EXIT_FAILURE); // NOLINT(concurrency-mt-unsafe)
}
fputs(argv[i], stdout);
fputs(":\t", stdout);
struct timespec now;
errno = 0;
if (clock_gettime(CLOCK_REALTIME, &now) != 0) {
- fprintf(stderr, "%s\n", strerror(errno));
+ fprintf(stderr, "%s\n", strerror(errno)); // NOLINT(concurrency-mt-unsafe)
return EXIT_FAILURE;
}
fputs("verifying ", stdout);
UUIDPrint(toVerify->cid);
fputs(": ", stdout);
- if (!YACCerVerify(
- &failReason, &verifier, toVerify, cers, (size_t)cersLen, opts)) {
+ if (!YACCerVerify(&failReason, &verifier, toVerify, cers, cersLen, opts)) {
fputs(failReason, stdout);
fputs("\n", stdout);
return EXIT_FAILURE;
+#include <stdint.h>
#include <stdlib.h>
#include "hex.h"
}
size_t i = 0;
for (; i < srcLen; i++) {
- dst[(i * 2) + 0] = hexdigits[(src[i] >> 4) & 0x0F];
- dst[(i * 2) + 1] = hexdigits[src[i] & 0x0F];
+ dst[(i * 2) + 0] = hexdigits
+ [(src[i] >> (uint8_t)4) & (uint8_t)0x0F]; // NOLINT(hicpp-signed-bitwise)
+ dst[(i * 2) + 1] = hexdigits[src[i] & (uint8_t)0x0F];
}
dst[srcLen * 2] = 0;
return dst;
bool
Mmap(unsigned char **buf, size_t *len, const char *path)
{
- int fd = open(path, O_RDONLY | O_CLOEXEC);
+ int fd = open(path, O_RDONLY | O_CLOEXEC); // NOLINT(hicpp-signed-bitwise)
if (fd == -1) {
return false;
}
(*len) = (size_t)sb.st_size;
errno = 0;
(*buf) = mmap(NULL, *len, PROT_READ, MAP_SHARED, fd, 0);
- if ((*buf) == MAP_FAILED) {
- fprintf(stderr, "mmap: %s\n", strerror(errno));
+ if ((*buf) == MAP_FAILED) { // NOLINT(performance-no-int-to-ptr)
+ fprintf(stderr, "mmap: %s\n", strerror(errno)); // NOLINT(concurrency-mt-unsafe)
return false;
}
return true;
case 12:
fputs("TAI64N(", stdout);
break;
+ default:
+ break;
}
struct timespec tv;
enum YACErr err = YACTAI64ToTimespec(&tv, buf, len);
return err;
}
time_t t = tv.tv_sec;
- struct tm *tm = localtime(&t);
+ struct tm *tm = localtime(&t); // NOLINT(concurrency-mt-unsafe)
if (tm == NULL) {
hex = HexEnc(buf, len);
fprintf(stdout, "unrepresentable: %s)\n", hex);
static const size_t maxStrLen = 40;
-static const char *ColourRed = "\x1b[31m";
-static const char *ColourGreen = "\x1b[32m";
-static const char *ColourYellow = "\x1b[33m";
-static const char *ColourBlue = "\x1b[34m";
-static const char *ColourMagenta = "\x1b[35m";
-static const char *ColourCyan = "\x1b[36m";
-static const char *ColourWhite = "\x1b[37m";
-static const char *ColourReset = "\x1b[0m";
+static const char
+ *ColourRed = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[31m";
+static const char
+ *ColourGreen = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[32m";
+static const char
+ *ColourYellow = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[33m";
+static const char
+ *ColourBlue = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[34m";
+static const char
+ *ColourMagenta = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[35m";
+static const char
+ *ColourCyan = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[36m";
+static const char
+ *ColourWhite = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[37m";
+static const char
+ *ColourReset = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ "\x1b[0m";
static void
printIndent(const size_t indent)
}
}
-static bool NoColour = false;
-static bool NoOffsets = false;
-static int OffDigits = 0;
-static char OffFmt[16] = {0};
+static bool NoColour = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ false;
+static bool NoOffsets = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ false;
+static int OffDigits = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ 0;
+static char OffFmt[16] = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+ {0};
static enum YACErr
-printer(
+printer( // NOLINT(misc-no-recursion)
const struct YACItems *items,
size_t idx,
size_t indent,
size_t len = 0;
unsigned char *buf = NULL;
if (!Mmap(&buf, &len, argv[1])) {
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE); // NOLINT(concurrency-mt-unsafe)
}
- NoColour = getenv("NO_COLOR") != NULL;
- NoOffsets = getenv("NO_OFFSETS") != NULL;
+ NoColour = getenv("NO_COLOR") != NULL; // NOLINT(concurrency-mt-unsafe)
+ NoOffsets = getenv("NO_OFFSETS") != NULL; // NOLINT(concurrency-mt-unsafe)
OffDigits = (int)(1 + floor(log10((double)len)));
snprintf(OffFmt, sizeof OffFmt, "%%s%%0%dzd%%s ", OffDigits);
"items: %zu size: %zu\n",
items.len,
items.len * (sizeof(struct YACItem) + (NoOffsets ? 0 : sizeof(size_t))));
- if (getenv("DO_ENCODE") != NULL) {
+ if (getenv("DO_ENCODE") != NULL) { // NOLINT(concurrency-mt-unsafe)
unsigned char *dst = malloc(len);
assert(dst != NULL);
off = 0;
size_t len = 0;
unsigned char *buf = NULL;
if (!Mmap(&buf, &len, argv[1])) {
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE); // NOLINT(concurrency-mt-unsafe)
}
struct YACAtom atom;
memset(&atom, 0, sizeof(struct YACAtom));
#include <assert.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <yac/enc.h>
#include <yac/enctai.h>
-static size_t Off = 0;
-static size_t Got = 0;
+static size_t Off = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+static size_t Got = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static void
adder(const bool ok)
}
int
-main(int argc, char **argv)
+main(int argc, char **argv) // NOLINT(misc-unused-parameters)
{
- const size_t len = 68 * 1024;
+ const size_t len = (size_t)68 * (uint16_t)1024;
unsigned char *buf = malloc(len);
assert(buf != NULL);
- unsigned char *bin = malloc(1 << 17);
+ unsigned char *bin = malloc((uint32_t)1 << (uint8_t)17);
assert(bin != NULL);
adder(YACAtomMapEncode(&Got, buf + Off, len - Off)); // .
}
atom->tag = buf[0];
- if ((atom->tag & YACAtomStrings) > 0) {
- atom->typ = ((atom->tag & YACAtomIsUTF8) == 0) ? YACItemBin : YACItemStr;
- uint64_t l = atom->tag & 63;
+ if ((atom->tag & (uint8_t)YACAtomStrings) > 0) {
+ atom->typ =
+ ((atom->tag & (uint8_t)YACAtomIsUTF8) == 0) ? YACItemBin : YACItemStr;
+ uint64_t l = atom->tag & (uint8_t)63;
size_t ll = 0;
switch (l) {
case 61:
ll = 8;
l += 255 + 65535;
break;
+ default:
+ break;
}
if (ll != 0) {
(*got) += ll;
}
size_t cpl = 0;
uint32_t cp = YACUTF8InvalidCp;
- for (size_t n = 0; n < l;) {
+ for (size_t n = 0; n < l; n += cpl) {
cpl = YACUTF8CpDecode(&cp, atom->v.str.ptr + (ptrdiff_t)n, l - n);
if (cp == YACUTF8InvalidCp) {
return YACErrBadUTF8;
}
- n += cpl;
}
}
return YACErrNo;
atom->v.nint = -1 - (int64_t)(atom->tag - YACAtomIntN1);
return YACErrNo;
}
- switch (atom->tag & 0xF0) {
+ switch (atom->tag & (uint8_t)0xF0) {
case YACAtomIntPos1:
case YACAtomIntNeg1: {
- atom->typ = ((atom->tag & YACAtomIntNeg1) == YACAtomIntNeg1) ? YACItemNint :
- YACItemPint;
- const size_t l = (atom->tag & 0x0F) + 1;
+ atom->typ = ((atom->tag & (uint8_t)YACAtomIntNeg1) == YACAtomIntNeg1) ?
+ YACItemNint :
+ YACItemPint;
+ const size_t l = (atom->tag & (uint8_t)0x0F) + 1;
(*got) += l;
if (len < (*got)) {
return YACErrNotEnough;
return YACErrIntNonMinimal;
}
if (atom->typ == YACItemNint) {
- if (atom->v.pint >= ((uint64_t)1 << 63)) {
+ if (atom->v.pint >= ((uint64_t)1 << (uint8_t)63)) {
atom->typ = YACItemRaw;
atom->v.str.len = l;
atom->v.str.ptr = buf + 1;
atom->v.str.len = l;
atom->v.str.ptr = buf + 1;
uint64_t v = yacFromBE(buf + 1, 8);
- if (v > ((uint64_t)1 << 63)) {
+ if (v > ((uint64_t)1 << (uint8_t)63)) {
return YACErrTAI64TooBig;
}
switch (l) {
return YACErrTAI64BadAsec;
}
break;
+ default:
+ break;
}
break;
}
int64_t v = (int64_t)(ts->tv_sec);
{
int64_t diff = 0;
- for (size_t i = 0; i < YACLeapsecsN; i++) {
- if (v > (YACLeapsecs[i] + (int64_t)YACLeapsecsN - (int64_t)i)) {
- diff = 10 + (int64_t)YACLeapsecsN - (int64_t)i;
+ for (int64_t i = 0; i < YACLeapsecsN; i++) {
+ if (v > (YACLeapsecs[i] + YACLeapsecsN - i)) {
+ diff = 10 + YACLeapsecsN - i;
break;
}
}
{
bool ok = yacAtomIntEncode(len, buf, cap, v);
if (ok) {
- buf[0] |= (v < 32) ? YACAtomInt0 : YACAtomIntPos1;
+ buf[0] |= (unsigned char)((v < 32) ? YACAtomInt0 : YACAtomIntPos1);
}
return ok;
}
const uint64_t vp = (uint64_t)(-(v + 1));
bool ok = yacAtomIntEncode(len, buf, cap, vp);
if (ok) {
- buf[0] |= (vp < 32) ? YACAtomIntN1 : YACAtomIntNeg1;
+ buf[0] |= (unsigned char)((vp < 32) ? YACAtomIntN1 : YACAtomIntNeg1);
}
return ok;
}
} else if (srcLen >= 61) {
lVal = 61;
lLen = 1;
- lBuf[0] = (unsigned char)((srcLen - 61) & 0xFF);
+ lBuf[0] = (unsigned char)((srcLen - 61) & (uint8_t)0xFF);
} else {
lVal = (unsigned char)srcLen;
}
if (cap < (*len)) {
return false;
}
- buf[0] = YACAtomStrings | lVal;
+ buf[0] = (uint8_t)YACAtomStrings | lVal;
if (utf8) {
- buf[0] |= YACAtomIsUTF8;
+ buf[0] |= (unsigned char)YACAtomIsUTF8;
}
memcpy(buf + 1, lBuf, lLen);
memcpy(buf + 1 + lLen, src, srcLen);
{
int64_t v = (int64_t)(ts->tv_sec);
int64_t diff = 10;
- for (size_t i = 0; i < YACLeapsecsN; i++) {
+ for (int64_t i = 0; i < YACLeapsecsN; i++) {
if (v > YACLeapsecs[i]) {
diff += YACLeapsecsN - i;
break;
}
enum YACErr
-YACItemsParse(
+YACItemsParse( // NOLINT(misc-no-recursion)
struct YACItems *items,
size_t *off,
const unsigned char *buf,
}
bool
-YACItemsEncode(
+YACItemsEncode( // NOLINT(misc-no-recursion)
const struct YACItems *items,
size_t idx,
size_t *off,
-#include <stddef.h>
#include <stdint.h>
#include "leapsecs.h"
-const size_t YACLeapsecsN = 27;
+const int64_t YACLeapsecsN = 27;
const int64_t YACLeapsecs[] = {
1483228800, // 2017-01
1435708800, // 2015-07
// second was added. @var{YACLeapsecsN} variable holds the length of
// that list.
// @end deftypevar
-extern const size_t YACLeapsecsN;
+extern const int64_t YACLeapsecsN;
extern const int64_t YACLeapsecs[];
#endif // YAC_LEAPSECS_H
#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#include "../dec.h"
return false;
}
}
- const size_t cap = 1 << 10;
- unsigned char buf[1 << 10] = {0};
+ const size_t cap = (size_t)1 << (uint8_t)10;
+ unsigned char buf[(uint16_t)1 << (uint8_t)10] = {0};
size_t off = 0;
{
const size_t items = 5;
{
for (size_t i = 0; i < len; i++) {
buf[i] =
- (unsigned char)(((v & ((uint64_t)0xFF << ((len - i - 1) * 8))) >> ((len - i - 1) * 8)) & 0xFF);
+ (unsigned char)(((v & ((uint64_t)0xFF << ((len - i - 1) * 8))) >> ((len - i - 1) * 8)) & (uint8_t)0xFF);
}
// this can be replaced by a switch with hard-coded decoding
// sequence without any loops for each of eight possible lengths
#define BETWEEN(c, l, u) (((c) >= (l)) && ((c) <= (u)))
-uint32_t YACUTF8InvalidCp = 0xFFFD;
+const uint32_t YACUTF8InvalidCp = 0xFFFD;
static const struct {
uint32_t mincp;
.lower = 0x00, /* 00000000 */
.upper = 0x7F, /* 01111111 */
.mincp = (uint32_t)0,
- .maxcp = ((uint32_t)1 << 7) - 1, /* 7 bits capacity */
+ .maxcp = ((uint32_t)1 << (uint8_t)7) - 1, /* 7 bits capacity */
},
[1] =
{
/* 110xxxxx */
.lower = 0xC0, /* 11000000 */
.upper = 0xDF, /* 11011111 */
- .mincp = (uint32_t)1 << 7,
- .maxcp = ((uint32_t)1 << 11) - 1, /* 5+6=11 bits capacity */
+ .mincp = (uint32_t)1 << (uint8_t)7,
+ .maxcp = ((uint32_t)1 << (uint8_t)11) - 1, /* 5+6=11 bits capacity */
},
[2] =
{
/* 1110xxxx */
.lower = 0xE0, /* 11100000 */
.upper = 0xEF, /* 11101111 */
- .mincp = (uint32_t)1 << 11,
- .maxcp = ((uint32_t)1 << 16) - 1, /* 4+6+6=16 bits capacity */
+ .mincp = (uint32_t)1 << (uint8_t)11,
+ .maxcp = ((uint32_t)1 << (uint8_t)16) - 1, /* 4+6+6=16 bits capacity */
},
[3] =
{
/* 11110xxx */
.lower = 0xF0, /* 11110000 */
.upper = 0xF7, /* 11110111 */
- .mincp = (uint32_t)1 << 16,
- .maxcp = ((uint32_t)1 << 21) - 1, /* 3+6+6+6=21 bits capacity */
+ .mincp = (uint32_t)1 << (uint8_t)16,
+ .maxcp = ((uint32_t)1 << (uint8_t)21) - 1, /* 3+6+6+6=21 bits capacity */
},
};
(*cp) = YACUTF8InvalidCp;
return 1 + (i - 1);
}
- (*cp) = (*cp << 6) | (str[i] & 0x3F);
+ (*cp) = (*cp << (uint8_t)6) | // NOLINT(hicpp-signed-bitwise)
+ (str[i] & (uint8_t)0x3F);
}
if ((*cp < lut[off].mincp) || BETWEEN(*cp, 0xD800, 0xDFFF) || (*cp > 0x10FFFF)) {
(*cp) = YACUTF8InvalidCp;
#include <stddef.h>
#include <stdint.h>
-extern uint32_t YACUTF8InvalidCp;
+extern const uint32_t YACUTF8InvalidCp;
size_t
YACUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len);