diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-10-27 11:21:38 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-10-27 11:21:38 -0400 |
commit | 0015289fec2c54de481cab87fb5b43bc2d1f2a4a (patch) | |
tree | 6b26187ebe05d47224bfa21e77c3dbb5cfdbbbf9 | |
parent | caeff0108d59d36a3c3fc62fd5ed788eaaf4f0a5 (diff) | |
download | bfs-0015289fec2c54de481cab87fb5b43bc2d1f2a4a.tar.xz |
Use {0} to initialize mbstate_t rather than memset()
-rw-r--r-- | src/bfstd.c | 15 | ||||
-rw-r--r-- | src/eval.c | 3 |
2 files changed, 6 insertions, 12 deletions
diff --git a/src/bfstd.c b/src/bfstd.c index a5a7e54..eee02b8 100644 --- a/src/bfstd.c +++ b/src/bfstd.c @@ -593,7 +593,7 @@ wint_t xmbrtowc(const char *str, size_t *i, size_t len, mbstate_t *mb) { case -1: // Invalid byte sequence case -2: // Incomplete byte sequence *i += 1; - memset(mb, 0, sizeof(*mb)); + *mb = (mbstate_t){0}; return WEOF; default: *i += mblen; @@ -605,9 +605,7 @@ size_t xstrwidth(const char *str) { size_t len = strlen(str); size_t ret = 0; - mbstate_t mb; - memset(&mb, 0, sizeof(mb)); - + mbstate_t mb = {0}; for (size_t i = 0; i < len;) { wint_t wc = xmbrtowc(str, &i, len, &mb); if (wc == WEOF) { @@ -724,9 +722,8 @@ static size_t printable_len(const char *str, size_t len, enum wesc_flags flags) } } - mbstate_t mb; -multibyte: - memset(&mb, 0, sizeof(mb)); +multibyte:; + mbstate_t mb = {0}; for (size_t j = i; i < len; i = j) { wint_t wc = xmbrtowc(str, &j, len, &mb); @@ -774,9 +771,7 @@ static const char *dollar_esc(char c) { static char *dollar_quote(char *dest, char *end, const char *str, size_t len, enum wesc_flags flags) { dest = xstpecpy(dest, end, "$'"); - mbstate_t mb; - memset(&mb, 0, sizeof(mb)); - + mbstate_t mb = {0}; for (size_t i = 0; i < len;) { size_t start = i; bool safe = false; @@ -1147,8 +1147,7 @@ static void eval_status(struct bfs_eval *state, struct bfs_bar *bar, struct time size_t pathmax = width - rhslen - 3; size_t pathwidth = 0; size_t lhslen = 0; - mbstate_t mb; - memset(&mb, 0, sizeof(mb)); + mbstate_t mb = {0}; for (size_t i = lhslen; lhslen < pathlen; lhslen = i) { wint_t wc = xmbrtowc(status, &i, pathlen, &mb); int cwidth; |