From 3dc4058ef9a2aa1fc9af1d843dc10d249a8d7170 Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 17 Mar 2022 16:48:52 +0600 Subject: [PATCH 1/4] conform to the C and POSIX standard C standard explicitly states that sources must end with a newline From C99 5.1.1.2: A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place. And POSIX defines a line as: A sequence of zero or more non- characters plus a terminating character. --- herbe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/herbe.c b/herbe.c index 51d3990..a213b19 100644 --- a/herbe.c +++ b/herbe.c @@ -217,4 +217,4 @@ int main(int argc, char *argv[]) XCloseDisplay(display); return exit_code; -} \ No newline at end of file +} From b6404ce5c465b92a897731a979a072fc51fc3cab Mon Sep 17 00:00:00 2001 From: NRK Date: Wed, 16 Mar 2022 18:16:30 +0600 Subject: [PATCH 2/4] rebuild on Makefile changes if someone edits his CFLAGS or such, it makes sense to triggr a rebuild. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3225e36..b2d5c94 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ all: herbe config.h: config.def.h cp config.def.h config.h -herbe: herbe.c config.h +herbe: herbe.c config.h Makefile $(CC) herbe.c $(CFLAGS) -o herbe install: herbe From fd48b9dbcde96da6d611db8c17b7ca78334dbf89 Mon Sep 17 00:00:00 2001 From: NRK Date: Wed, 16 Mar 2022 18:31:26 +0600 Subject: [PATCH 3/4] more strict error checking --- herbe.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/herbe.c b/herbe.c index a213b19..60320b3 100644 --- a/herbe.c +++ b/herbe.c @@ -117,9 +117,11 @@ int main(int argc, char *argv[]) XSetWindowAttributes attributes; attributes.override_redirect = True; XftColor color; - XftColorAllocName(display, visual, colormap, background_color, &color); + if (!XftColorAllocName(display, visual, colormap, background_color, &color)) + die("Failed to allocate background color"); attributes.background_pixel = color.pixel; - XftColorAllocName(display, visual, colormap, border_color, &color); + if (!XftColorAllocName(display, visual, colormap, border_color, &color)) + die("Failed to allocate border color"); attributes.border_pixel = color.pixel; int num_of_lines = 0; @@ -130,6 +132,8 @@ int main(int argc, char *argv[]) die("malloc failed"); XftFont *font = XftFontOpenName(display, screen, font_pattern); + if (!font) + die("Couldn't open font"); for (int i = 1; i < argc; i++) { @@ -166,12 +170,16 @@ int main(int argc, char *argv[]) CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); XftDraw *draw = XftDrawCreate(display, window, visual, colormap); + if (!draw) + die("Failed to create Xft drawable object"); XftColorAllocName(display, visual, colormap, font_color, &color); XSelectInput(display, window, ExposureMask | ButtonPress); XMapWindow(display, window); sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1); + if (mutex == SEM_FAILED) + die("Failed to open semaphore"); sem_wait(mutex); sigaction(SIGUSR1, &act_expire, 0); From 709105cebbb5994c43b5eee747b8a26f51c9ecad Mon Sep 17 00:00:00 2001 From: NRK Date: Wed, 16 Mar 2022 22:16:12 +0600 Subject: [PATCH 4/4] add missing static qualifier these functions and variables are not used outside the translation unit, so there's little sense in not marking them as static. --- herbe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/herbe.c b/herbe.c index 60320b3..a9b8e2a 100644 --- a/herbe.c +++ b/herbe.c @@ -15,9 +15,9 @@ #define EXIT_FAIL 1 #define EXIT_DISMISS 2 -Display *display; -Window window; -int exit_code = EXIT_DISMISS; +static Display *display; +static Window window; +static int exit_code = EXIT_DISMISS; static void die(const char *format, ...) { @@ -29,7 +29,7 @@ static void die(const char *format, ...) exit(EXIT_FAIL); } -int get_max_len(char *string, XftFont *font, int max_text_width) +static int get_max_len(char *string, XftFont *font, int max_text_width) { int eol = strlen(string); XGlyphInfo info; @@ -70,7 +70,7 @@ int get_max_len(char *string, XftFont *font, int max_text_width) return ++eol; } -void expire(int sig) +static void expire(int sig) { XEvent event; event.type = ButtonPress;