Another defncopy patch - check dbopen results

Nem W Schlecht <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <CA+2x6-KL6A_+RvkpZWvyJcZPN8o1PQsg1vt5xspJFQs3f9JeCw@mail.gmail.com>
I have another defncopy patch to fix another issue.  The results from
dbopen() are just checked with an assert() call.  Thus, if I type in
the wrong database name, username, whatever, I get a core dump that I
have to clean up from a typo on my part.  What do you all think of a
quick check/message/exit, similar to what happens with tsql?

Patch attached.  Just checks to see if dbproc has a value.  If not,
prints an error message and exit(1)s.  Otherwise, continues on.

I deal with a lot of servers and a lot of usernames/passwords, so this
one hits me fairly often.


-- 
Nem W Schlecht
 "Perl did the magic.  I just waved the wand."

_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
defncopyfix-20160616.patch (application/octet-stream, 534 B)
diff --git a/freetds-1.00.3/src/apps/defncopy.c b/freetds-1.00.3-defncopyfix/src/apps/defncopy.c
index e76d1b3..dee13e0 100644
--- a/freetds-1.00.3/src/apps/defncopy.c
+++ b/freetds-1.00.3-defncopyfix/src/apps/defncopy.c
@@ -195,6 +195,10 @@ main(int argc, char *argv[])
 	 * Connect to the server 
 	 */
 	dbproc = dbopen(login, options.servername);
+	if (! dbproc) {
+		fprintf(stderr, "There was a problem connecting to the server.\n");
+		exit(1);
+	}
 	assert(dbproc != NULL);
 	
 	/* Switch to the specified database, if any */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.