From 392bb0e3b30c6b70517318a41e7465eea3109494 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Fri, 31 May 2019 18:38:10 +0800 Subject: [PATCH] Fixing open() off by one error As reported by coverity: off_by_one: Testing whether handle fd is strictly greater than zero is suspicious. fd leaks when it is zero --- hydra-gtk/src/callbacks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydra-gtk/src/callbacks.c b/hydra-gtk/src/callbacks.c index 62c441c..5600f15 100644 --- a/hydra-gtk/src/callbacks.c +++ b/hydra-gtk/src/callbacks.c @@ -690,7 +690,7 @@ void on_btnSave_clicked(GtkButton * button, gpointer user_data) { text = gtk_text_buffer_get_text(outputbuf, &start, &end, TRUE); fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644); - if (fd > 0) { + if (fd >= 0) { write(fd, text, strlen(text)); close(fd); }