From 40c83196e13bccf09d672c3491b4c894defd747332551fd3d7382603bb669c62 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 21 Nov 2025 10:49:48 +0300 Subject: [PATCH] {0} initialiser --- c/cmd/deatomiser/deatomiser.c | 3 +-- c/cmd/lib/mmap.c | 3 +-- c/cmd/pp/pp.c | 6 +++--- c/cmd/test-vector/test-vector.c | 4 +--- c/lib/dec.c | 9 +++------ c/lib/schema.c | 4 ++-- 6 files changed, 11 insertions(+), 18 deletions(-) diff --git a/c/cmd/deatomiser/deatomiser.c b/c/cmd/deatomiser/deatomiser.c index a684d02..11f3b59 100644 --- a/c/cmd/deatomiser/deatomiser.c +++ b/c/cmd/deatomiser/deatomiser.c @@ -38,8 +38,7 @@ main(void) fprintf(stderr, "stdinread(): %s\n", strerror(errno)); exit(EXIT_FAILURE); } - struct KEKSAtom atom; - memset(&atom, 0, sizeof(struct KEKSAtom)); + struct KEKSAtom atom = {0}; size_t off = 0; size_t got = 0; int indent = 0; diff --git a/c/cmd/lib/mmap.c b/c/cmd/lib/mmap.c index 7807926..5cf01d7 100644 --- a/c/cmd/lib/mmap.c +++ b/c/cmd/lib/mmap.c @@ -18,8 +18,7 @@ Mmap(unsigned char **buf, size_t *len, const char *path) fprintf(stderr, "open: %s\n", strerror(errno)); return false; } - struct stat sb; - memset(&sb, 0, sizeof(struct stat)); + struct stat sb = {0}; if (fstat(fd, &sb) != 0) { fprintf(stderr, "fstat: %s\n", strerror(errno)); return false; diff --git a/c/cmd/pp/pp.c b/c/cmd/pp/pp.c index 3bf7118..dbd042f 100644 --- a/c/cmd/pp/pp.c +++ b/c/cmd/pp/pp.c @@ -366,11 +366,11 @@ main(int argc, char **argv) OffDigits = NoOffsets ? -1 : (int)(1 + floor(log10((double)len))); snprintf(OffFmt, sizeof OffFmt, "%%s%%0%dzd%%s ", OffDigits); - struct KEKSItems items; + struct KEKSItems items = {0}; enum KEKSErr err = KEKSErrInvalid; size_t off = 0; - struct timespec started; - struct timespec finished; + struct timespec started = {0}; + struct timespec finished = {0}; ptrdiff_t parseCycles = 0; while (off < len) { err = KEKSItemsInit(&items, itemsInitialLen); diff --git a/c/cmd/test-vector/test-vector.c b/c/cmd/test-vector/test-vector.c index ea8c5af..20abea5 100644 --- a/c/cmd/test-vector/test-vector.c +++ b/c/cmd/test-vector/test-vector.c @@ -227,9 +227,7 @@ main(void) &Got, buf + Off, len - Off, (const unsigned char *)"dates", 5)); adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .dates { - struct timespec ts; - ts.tv_sec = 1234567890; - ts.tv_nsec = 0; + struct timespec ts = {.tv_sec = 1234567890, .tv_nsec = 0}; assert(KEKSTimespecToTAI(&ts)); unsigned char tai[12] = {0}; assert(KEKSTimespecToTAI64(tai, &ts)); diff --git a/c/lib/dec.c b/c/lib/dec.c index 8ee2794..c726d1d 100644 --- a/c/lib/dec.c +++ b/c/lib/dec.c @@ -183,8 +183,7 @@ KEKSAtomDecode( // NOLINT(misc-no-recursion) case KEKSAtomNint: { atom->typ = (tag == KEKSAtomPint) ? KEKSItemPint : KEKSItemNint; size_t binGot = 0; - struct KEKSAtom bin; - memset(&bin, 0, sizeof(struct KEKSAtom)); + struct KEKSAtom bin = {0}; if ((buf[1] & (unsigned char)KEKSAtomStrings) == 0) { return KEKSErrIntNonBin; } @@ -241,8 +240,7 @@ KEKSAtomDecode( // NOLINT(misc-no-recursion) case KEKSAtomFloat: { atom->typ = KEKSItemFloat; size_t mGot = 0; - struct KEKSAtom m; - memset(&m, 0, sizeof(struct KEKSAtom)); + struct KEKSAtom m = {0}; enum KEKSErr err = KEKSAtomDecode(&mGot, &m, buf + 1, len - 1); if (err != KEKSErrNo) { return err; @@ -253,8 +251,7 @@ KEKSAtomDecode( // NOLINT(misc-no-recursion) } size_t eGot = 0; - struct KEKSAtom e; - memset(&e, 0, sizeof(struct KEKSAtom)); + struct KEKSAtom e = {0}; err = KEKSAtomDecode(&eGot, &e, buf + 1 + mGot, len - 1 - mGot); if (err != KEKSErrNo) { return err; diff --git a/c/lib/schema.c b/c/lib/schema.c index 6d056e0..f051611 100644 --- a/c/lib/schema.c +++ b/c/lib/schema.c @@ -158,7 +158,7 @@ keksSchemaCmd( // NOLINT(misc-no-recursion) assert(schema != NULL); assert(data != NULL); size_t origIdxSchema = idxSchema; - struct KEKSSchemaErr err; + struct KEKSSchemaErr err = {0}; size_t v = *taken; Eached: idxSchema = origIdxSchema; @@ -596,7 +596,7 @@ Eached: err.msg = "non-TAI64 taken"; return err; } - struct timespec tv; + struct timespec tv = {0}; enum KEKSErr errConvert = KEKSTAI64ToTimespec( &tv, data->list[v].atom.v.str.ptr, data->list[v].atom.v.str.len); if (errConvert != KEKSErrNo) { -- 2.52.0