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
This commit is contained in:
David Maciejak 2019-05-31 18:38:10 +08:00 committed by GitHub
parent 5df0ab39c0
commit 392bb0e3b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}