]> Cypherpunks repositories - keks.git/commitdiff
Satisfy linter
authorSergey Matveev <stargrave@stargrave.org>
Fri, 25 Oct 2024 11:58:42 +0000 (14:58 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 25 Oct 2024 11:58:42 +0000 (14:58 +0300)
19 files changed:
cyac/.clang-tidy [new file with mode: 0644]
cyac/cmd/cer-verify/cer-verify.c
cyac/cmd/lib/hex.c
cyac/cmd/lib/mmap.c
cyac/cmd/lib/printai.c
cyac/cmd/print-items/print-items.c
cyac/cmd/print-itered/print-itered.c
cyac/cmd/test-vector/test-vector.c
cyac/lib/dec.c
cyac/lib/dectai.c
cyac/lib/enc.c
cyac/lib/enctai.c
cyac/lib/items.c
cyac/lib/leapsecs.c
cyac/lib/leapsecs.h
cyac/lib/pki/cer.c
cyac/lib/tobe.c
cyac/lib/utf8.c
cyac/lib/utf8.h

diff --git a/cyac/.clang-tidy b/cyac/.clang-tidy
new file mode 100644 (file)
index 0000000..486254d
--- /dev/null
@@ -0,0 +1,13 @@
+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-*,
+"
index 50c9cc1af12914764fe48c5963aceb9a50d32d9469a5026cf285a5be5a0eac9a..86b12015e7621d618f699f5c26ed72dbf1c04703bc8385ea2fab37d95d79c24f 100644 (file)
@@ -44,8 +44,12 @@ main(int argc, char **argv)
         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);
@@ -67,7 +71,7 @@ main(int argc, char **argv)
     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;
     }
 
@@ -84,8 +88,7 @@ main(int argc, char **argv)
         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;
index 25c1a3c415cd51d6d6e12f3f28972c3e5299e0fae60bf593afb347cb62430904..e6e6907545cd0c6cccc84bbd92c2ce0ec66c395a251928ffc0572ac4e248b4db 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdint.h>
 #include <stdlib.h>
 
 #include "hex.h"
@@ -14,8 +15,9 @@ HexEnc(const unsigned char *src, const size_t srcLen)
     }
     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;
index 45f4b93054fac2d6260e0dbb4b3f6b4aadb51de89ca497fe5b28ce88e7294bc3..d3d3a2f9ad2a6243a7906da5c81ca40c50c205bb11978f5ccede537fa1897ea2 100644 (file)
@@ -12,7 +12,7 @@
 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;
     }
@@ -24,8 +24,8 @@ Mmap(unsigned char **buf, size_t *len, const char *path)
     (*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;
index afc4e939c981b6fc4e3bfe1d0b5d5ab842af2d735bb51943d563123663b68b86..8e2ffd224f119f285dbe988ac21793c04d7fdbd33cb511812242feb396ecb1d9 100644 (file)
@@ -26,6 +26,8 @@ PrintTAI64(const unsigned char *buf, const size_t len)
     case 12:
         fputs("TAI64N(", stdout);
         break;
+    default:
+        break;
     }
     struct timespec tv;
     enum YACErr err = YACTAI64ToTimespec(&tv, buf, len);
@@ -59,7 +61,7 @@ PrintTAI64(const unsigned char *buf, const size_t 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);
index b314cb34f1ac73a51c9ef1a8a5d715a32dacfb56790eaedc12fa91eee47af65b..db2ffc0f61f48de14e63e1be2df4df0c4e06b7531c4322bd099e68bbcc58b9c5 100644 (file)
 
 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)
@@ -48,13 +64,17 @@ 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,
@@ -261,10 +281,10 @@ main(int argc, char **argv)
     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);
 
@@ -293,7 +313,7 @@ main(int argc, char **argv)
         "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;
index c9923e7304c554c36ef310b0cd5058aa95460bd6cd902eb2f0d6a1ac770c63ed..663622104f5e2fd2e98a3f2d424ccc6330d73850d8e46f17363de5a8c3efa00b 100644 (file)
@@ -163,7 +163,7 @@ main(int argc, char **argv)
     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));
index 8230e362a920eab2373f93568e5092a3b1c847c59be4fbcca5cc7e3a31f246e1..b68260449c4f8a5c7661f71277865f7bc3ce8377046216bb00ad0241925b58d6 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -9,8 +10,8 @@
 #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)
@@ -20,12 +21,12 @@ 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)); // .
index 2b3b19c19e94ae388eb98b52a42bf9f033783a535d5adc68b167444101ae0c6a..abd04ecb317c1754e2b9d70a2fcba45e7e4226f740be008c7fe4b493e374952c 100644 (file)
@@ -37,9 +37,10 @@ YACAtomDecode(
     }
     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:
@@ -53,6 +54,8 @@ YACAtomDecode(
             ll = 8;
             l += 255 + 65535;
             break;
+        default:
+            break;
         }
         if (ll != 0) {
             (*got) += ll;
@@ -81,12 +84,11 @@ YACAtomDecode(
             }
             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;
@@ -102,12 +104,13 @@ YACAtomDecode(
         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;
@@ -125,7 +128,7 @@ YACAtomDecode(
                 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;
@@ -237,7 +240,7 @@ YACAtomDecode(
         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) {
@@ -253,6 +256,8 @@ YACAtomDecode(
                 return YACErrTAI64BadAsec;
             }
             break;
+        default:
+            break;
         }
         break;
     }
index 642dc8bcbf000c9011a57b04b9ca396937f0f7f4f8add1dca7ab3f9df9a7e77c..e0d0b9d4a16feef58a0b698afa015b1c4280dd5d881c29e215ab4e6dcd23b188 100644 (file)
@@ -50,9 +50,9 @@ YACTimespecToUTC(struct timespec *ts)
     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;
             }
         }
index 737a6549210c824a1a4fc62213c36f28675af176595e2fe412f8cce56a1265e5..81df522b155c34a145c3bc82752021966cc032e168df6d3dd4d0972c55e13b09 100644 (file)
@@ -106,7 +106,7 @@ YACAtomUintEncode(size_t *len, unsigned char *buf, const size_t cap, const uint6
 {
     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;
 }
@@ -120,7 +120,7 @@ YACAtomSintEncode(size_t *len, unsigned char *buf, const size_t cap, const int64
     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;
 }
@@ -186,7 +186,7 @@ yacAtomStrEncode(
     } 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;
     }
@@ -198,9 +198,9 @@ yacAtomStrEncode(
     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);
index 2538c0bc3dd02f9b6812f5bace387a721f6533a4c3e16efd8ef165015c0651a5..f9956f8e2b75ac603a8cf0c89f2ea2cbb5cf2e419c89d303d6498228ba50e60f 100644 (file)
@@ -40,7 +40,7 @@ YACTimespecToTAI(struct timespec *ts)
 {
     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;
index c9182ca927f10f3f294b20ce41401f31e781f61be22bff7a9b8a3c04e5d36c14..d85b9a24f4d5c493a9c0541732085e1abe8e0bce2744d17d414cd64b68250ea8 100644 (file)
@@ -114,7 +114,7 @@ yacItemsAdd(
 }
 
 enum YACErr
-YACItemsParse(
+YACItemsParse( // NOLINT(misc-no-recursion)
     struct YACItems *items,
     size_t *off,
     const unsigned char *buf,
@@ -270,7 +270,7 @@ YACItemsParse(
 }
 
 bool
-YACItemsEncode(
+YACItemsEncode( // NOLINT(misc-no-recursion)
     const struct YACItems *items,
     size_t idx,
     size_t *off,
index b1d86ae085e34176ef77166b8abbe9454e356cc5075920a8fefaf2562412daff..7f703d490fc98912208e9035873c3647d49d6eddc5913532edd2f6423c0852a0 100644 (file)
@@ -1,9 +1,8 @@
-#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
index 206c6f3746232d91c4c41f984ba68885477864cdab6926f77ec9066dd60345e2..71c0efeb869ebc813034473548fcf7c1890e7a5d2f453092e7575474f09e759d 100644 (file)
@@ -10,7 +10,7 @@
 // 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
index 0807e838a19c7a1da04b6bd67ef10014fe099d879d5749e8d8ea054ffa0ad39a..8b3dce068180ad2a763eb9b78adb66bc8850913b8a63c6b9c702f8eebdc8a51e 100644 (file)
@@ -1,4 +1,5 @@
 #include <stddef.h>
+#include <stdint.h>
 #include <string.h>
 
 #include "../dec.h"
@@ -265,8 +266,8 @@ YACCerVerify(
             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;
index 530a7988fc56548829df513771aec76da2514c4e34edec7a54a7f78bbef891fa..a66fb1cfaecca9900db311b60df484b4e4eb8e1da108ef01b0cf459ab571c58b 100644 (file)
@@ -8,7 +8,7 @@ yacToBE(unsigned char *buf, const size_t len, const uint64_t v)
 {
     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
index 9d6c4a88c4cd143febda248b4f6be5b50027cb9ccd893d2b55216a1ca34171db..865ec081c4e64e09b5d5a7def0019af966eb6a904d7e42de7f22cc892f0e83a0 100644 (file)
@@ -10,7 +10,7 @@
 
 #define BETWEEN(c, l, u) (((c) >= (l)) && ((c) <= (u)))
 
-uint32_t YACUTF8InvalidCp = 0xFFFD;
+const uint32_t YACUTF8InvalidCp = 0xFFFD;
 
 static const struct {
     uint32_t mincp;
@@ -25,31 +25,31 @@ static const struct {
             .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 */
         },
 };
 
@@ -91,7 +91,8 @@ YACUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len)
             (*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;
index 4a3dd6428c81ce9ec6c79c9bc2420a3c5d3c065ecf45a2539e3943f44ce80353..6c455e06815bff4805a4506a6d3fa36bb750c1f99aa8f95e5fb7e43a95cfc9e6 100644 (file)
@@ -4,7 +4,7 @@
 #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);