Skip site navigation (1) Skip section navigation (2)

Re: Patch for snprintf problem (bug #1000650)

From: Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>
To: Ludek Finstrle <luf(at)pzkagis(dot)cz>
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: Re: Patch for snprintf problem (bug #1000650)
Date: 2006-06-08 23:46:50
Message-ID: 4488B6EA.9050107@tpf.co.jp (view raw or flat)
Thread:
Lists: pgsql-odbc
Ludek Finstrle wrote:
> Hello,
> 
>   I found the problem in snprintf on linux (maybe another unix) boxes
> in info.c (CVS HEAD). The problematic part is something like:
> 
> buf = "text";
> snprintf(buf,size,"%s append",buf);
> 
> buf = "text append" on Windows (MS VC compiler)
> buf = " append" on linux (gcc compiler)
> 
> I solve it this way (main idea):
> snprintf(buf + strlen(buf), " append");

Hmm bad news.
If so, it may be better to use the sequence like the following for example.

	char	*query_ptr;
	size_t	bufsize_res;
	int	slen;

	/* Initialize */
	query_ptr = columns_query;
	bufsize_res = sizeof(columns_query);

	if (..)
	{
		if ((slen = snprintf(query_ptr, bufsize_res, .., )) <= 0)
		{
			.. error_handling ..
		}
		query_ptr += slen;
		bufsize_res -= slen;
	}

	...

regards,
Hiroshi Inoue

In response to

Responses

pgsql-odbc by date

Next:From: Hiroshi InoueDate: 2006-06-08 23:53:38
Subject: Re: CVS and open cursor
Previous:From: Mr. DBADate: 2006-06-08 21:40:21
Subject: windows ODBC driver issues

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group