From 6578e6eb6533a6651bd88ecae7720aced88c8c2f Mon Sep 17 00:00:00 2001 From: NRK Date: Tue, 16 Aug 2022 10:53:05 +0200 Subject: code-style: various cleanups (#356) * run_key_handler: make the logic easier to follow * remove timeout_t the typedef is not needed. inline the declaration similar to the other static structs. * simplify estrdup reuse emalloc, instead of calling malloc and null-checking. * win_clear: initialize `e` right away * process_bindings: explicitly check against NULL most pointer checks in the codebase do explicit check. * use a named constant instead of magic number also changes the padding from 3 to 4 bytes according to [0]. but i couldn't find any situtation where this mattered, so perhaps the current padding is enough. but doesn't hurt adding one more byte. [0]: https://nullprogram.com/blog/2017/10/06/ Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/356 Reviewed-by: explosion-mental --- util.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 65c39e5..f03fe23 100644 --- a/util.c +++ b/util.c @@ -60,14 +60,8 @@ void* erealloc(void *ptr, size_t size) char* estrdup(const char *s) { - char *d; size_t n = strlen(s) + 1; - - d = malloc(n); - if (d == NULL) - error(EXIT_FAILURE, errno, NULL); - memcpy(d, s, n); - return d; + return memcpy(emalloc(n), s, n); } void error(int eval, int err, const char* fmt, ...) -- cgit v1.2.3-70-g09d2