The Linux Page

Negative constant ... was passed to a negative sink

Today, as I was working with Coverity, I got this one message...

Negative constant passed to a negative sink.

Although I understood the meaning, I thought that this message was very confusing, How about:

Unexpected negative value in parameter #<position>

The annoying part is that it is called on SQLColumns() which like most ODBC functions uses SQL_NTS for string sizes. This special definition means Null Terminated String. The system will transform the SQL_NTS value to the value of strlen(<your string>);

So, this is a false positive in my case. The negative sink views -3 as a valid value.


     SQLHDBC        ConnectionHandle,
     SQLCHAR *      ServerName,
     SQLSMALLINT    NameLength1,
     SQLCHAR *      UserName,
     SQLSMALLINT    NameLength2,
     SQLCHAR *      Authentication,
     SQLSMALLINT    NameLength3);

SQLConnect(hsql, "MyServer", SQL_NTS, "User1", SQL_NTS, NULL, SQL_NTS);

In that call we see that the last parameter is passed as NULL & SQL_NTS. Coverity does not like the SQL_NTS which is fine for the call, but since strlen(NULL) is not safe, they ask you to fix it. The proper call is using 0 instead of SQL_NTS.

SQLConnect(hsql, "MyServer", SQL_NTS, "User1", SQL_NTS, NULL, 0);

Code sample?

It would help me if I could see a sample of the code. Make something up if you like, to avoid publishing proprietary code.