From 55cabab847075f83bd163587ff0097560bcd5f7f Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Wed, 28 Jun 2023 12:22:51 +0200 Subject: [PATCH] examples: Check for null earlier Thanks coverity CID 1461476 Signed-off-by: Jakub Jelen Reviewed-by: Norbert Pocs --- examples/libssh_scp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/libssh_scp.c b/examples/libssh_scp.c index 6fdf8a4f..adb82ef0 100644 --- a/examples/libssh_scp.c +++ b/examples/libssh_scp.c @@ -229,11 +229,11 @@ static int open_location(struct location *loc, int flag) { return -1; } return 0; - } else { + } else if (loc->path != NULL) { loc->file = fopen(loc->path, flag == READ ? "r":"w"); if (!loc->file) { if (errno == EISDIR) { - if (loc->path != NULL && chdir(loc->path)) { + if (chdir(loc->path)) { fprintf(stderr, "Error changing directory to %s: %s\n", loc->path, strerror(errno));