Re: SQLGetInfo Bug - Mailing list pgsql-odbc

From Tom Lane
Subject Re: SQLGetInfo Bug
Date
Msg-id 20229.1041519792@sss.pgh.pa.us
Whole thread Raw
In response to Re: SQLGetInfo Bug  ("Dave Page" <dpage@vale-housing.co.uk>)
List pgsql-odbc
"Dave Page" <dpage@vale-housing.co.uk> writes:
> The garbage is not there if I use sprintf with a larger size of
> tmp. I've tried variations of the code to check (without luck) but I
> assume I'm not somehow knocking the null off the end of the string?

You would be losing the trailing null if the snprintf is unable to fit
its output into the buffer size it's told to use (at least, that's how
most implementations of snprintf react, I think).

It doesn't look like this should be enough data to overrun your buffer,
but I don't have a better theory at the moment.

Perhaps

    snprintf(tmp, sizeof(tmp) - 1, "%s %s", ...);
    tmp[sizeof(tmp) - 1] = '\0';

would be better coding practice if you don't want to actually check
snprintf's result.

            regards, tom lane

pgsql-odbc by date:

Previous
From: "Dave Page"
Date:
Subject: Re: SQLGetInfo Bug
Next
From: "Dave Page"
Date:
Subject: Re: SQLGetInfo Bug