X-Original-To: pgsql-odbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 0CCCD9FA5C3 for ; Thu, 8 Jun 2006 20:47:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 45331-10 for ; Thu, 8 Jun 2006 20:47:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sd.tpf.co.jp (sd.tpf.co.jp [210.161.239.34]) by postgresql.org (Postfix) with SMTP id 1D8239FA3CD for ; Thu, 8 Jun 2006 20:47:24 -0300 (ADT) Received: (qmail 22652 invoked from network); 9 Jun 2006 08:47:21 +0900 Received: from unknown (HELO ?100.0.32.254?) (100.0.32.254) by sd2.tpf-fw-c.co.jp with SMTP; 9 Jun 2006 08:47:21 +0900 Message-ID: <4488B6EA.9050107@tpf.co.jp> Date: Fri, 09 Jun 2006 08:46:50 +0900 From: Hiroshi Inoue User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Ludek Finstrle CC: pgsql-odbc@postgresql.org Subject: Re: Patch for snprintf problem (bug #1000650) References: <20060607173910.GA28221@soptik.pzkagis.cz> In-Reply-To: <20060607173910.GA28221@soptik.pzkagis.cz> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/41 X-Sequence-Number: 7789 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