This is a patch created against psqlodbc-0900.0200, that fixes
errors found by Coverity static analysis tool and that are easy and
obvious to fix.

Corresponding parts of the error report are attached.

============================================================================
Error: CONSTANT_EXPRESSION_RESULT (CWE-569):
/builddir/build/BUILD/psqlodbc-09.00.0200/convert.c:3944: result_independent_of_operands: npos >= 0UL is always true regardless of the values of its operands. This occurs as the logical first operand of '&&'.

diff -rup psqlodbc-09.00.0200/convert.c psqlodbc-09.00.0200-coverity/convert.c
--- psqlodbc-09.00.0200/convert.c	2010-10-23 05:33:19.000000000 +0200
+++ psqlodbc-09.00.0200-coverity/convert.c	2011-12-20 10:37:33.232610229 +0100
@@ -3864,7 +3864,8 @@ ResolveOneParam(QueryBuild *qb, QueryPar
 	OID		lobj_oid;
 	int		lobj_fd, retval;
 	SQLULEN	offset = apdopts->param_offset_ptr ? *apdopts->param_offset_ptr : 0;
-	size_t	current_row = qb->current_row, npos = 0;
+	size_t	current_row = qb->current_row;
+	int npos = 0;
 	BOOL	handling_large_object = FALSE, req_bind, add_quote = FALSE;
 	ParameterInfoClass	*apara;
 	ParameterImplClass	*ipara;

============================================================================
Error: STRING_OVERFLOW (CWE-120):
/builddir/build/BUILD/psqlodbc-09.00.0200/dlg_specific.c:1446: string_overflow: You might overrun the 10 byte destination string "comval->protocol" by writing 256 bytes from "temp".

diff -rup psqlodbc-09.00.0200/dlg_specific.c psqlodbc-09.00.0200-coverity/dlg_specific.c
--- psqlodbc-09.00.0200/dlg_specific.c	2010-06-21 23:48:01.000000000 +0200
+++ psqlodbc-09.00.0200-coverity/dlg_specific.c	2011-12-20 10:45:39.801576957 +0100
@@ -1442,8 +1442,11 @@ getCommonDefaults(const char *section, c
 		 */
 		SQLGetPrivateProfileString(section, INI_PROTOCOL, "@@@",
 								   temp, sizeof(temp), filename);
-		if (strcmp(temp, "@@@"))
-			strcpy(comval->protocol, temp);
+		if (strcmp(temp, "@@@")) 
+		{
+			strncpy(comval->protocol, temp, sizeof(comval->protocol)-1);
+			comval->protocol[sizeof(comval->protocol)-1] = '\0';
+		}
 		else
 			strcpy(comval->protocol, DEFAULT_PROTOCOL);
 	}

============================================================================
Error: CONSTANT_EXPRESSION_RESULT (CWE-569):
/builddir/build/BUILD/psqlodbc-09.00.0200/misc.c:254: result_independent_of_operands: i >= 0UL is always true regardless of the values of its operands. This occurs as the logical operand of for.

diff -rup psqlodbc-09.00.0200/misc.c psqlodbc-09.00.0200-coverity/misc.c
--- psqlodbc-09.00.0200/misc.c	2010-10-05 16:21:11.000000000 +0200
+++ psqlodbc-09.00.0200-coverity/misc.c	2011-12-20 10:36:45.464613493 +0100
@@ -249,7 +249,7 @@ remove_newlines(char *string)
 char *
 my_trim(char *s)
 {
-	size_t		i;
+	int		i;
 
 	for (i = strlen(s) - 1; i >= 0; i--)
 	{

============================================================================
Error: MISSING_BREAK (CWE-484):
/builddir/build/BUILD/psqlodbc-09.00.0200/pgapi30.c:1423: unterminated_case: This case (value 91) is not terminated by a 'break' statement.
/builddir/build/BUILD/psqlodbc-09.00.0200/pgapi30.c:1425: fallthrough: The above case falls through to this one.

Error: MISSING_BREAK (CWE-484):
/builddir/build/BUILD/psqlodbc-09.00.0200/pgapi30.c:1763: unterminated_case: This case (value 29) is not terminated by a 'break' statement.
/builddir/build/BUILD/psqlodbc-09.00.0200/pgapi30.c:1765: fallthrough: The above case falls through to this one.

diff -rup psqlodbc-09.00.0200/pgapi30.c psqlodbc-09.00.0200-coverity/pgapi30.c
--- psqlodbc-09.00.0200/pgapi30.c	2009-04-04 12:44:46.000000000 +0200
+++ psqlodbc-09.00.0200-coverity/pgapi30.c	2011-12-20 11:58:37.234277624 +0100
@@ -1422,6 +1422,7 @@ inolog("IPDGetField RecN=%d allocated=%d
 			{
 				case SQL_TYPE_DATE:
 					ival = SQL_CODE_DATE;
+					break;
 				case SQL_TYPE_TIME:
 					ival = SQL_CODE_TIME;
 					break;
@@ -1762,6 +1763,7 @@ PGAPI_SetDescField(SQLHDESC DescriptorHa
 			{
 				case DESC_INVALID_DESCRIPTOR_IDENTIFIER:
 					DC_set_errormsg(desc, "can't SQLSetDescField for this descriptor identifier");
+					break;
 				case DESC_INVALID_COLUMN_NUMBER_ERROR:
 					DC_set_errormsg(desc, "can't SQLSetDescField for this column number");
 					break;


