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 476269FA5D8 for ; Fri, 9 Jun 2006 05:14:42 -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 99491-01 for ; Fri, 9 Jun 2006 05:14:37 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.pzkagis.cz (gis6.netbox.cz [83.240.30.214]) by postgresql.org (Postfix) with ESMTP id 2F0FD9FA5D2 for ; Fri, 9 Jun 2006 05:14:34 -0300 (ADT) Received: from soptik.pzkagis.cz (localhost.localdomain [127.0.0.1]) by smtp.pzkagis.cz (8.13.1/8.13.1) with ESMTP id k598Gcwc008255; Fri, 9 Jun 2006 10:16:38 +0200 Received: (from luf@localhost) by soptik.pzkagis.cz (8.13.1/8.13.1/Submit) id k598GbIB008254; Fri, 9 Jun 2006 10:16:37 +0200 Date: Fri, 9 Jun 2006 10:16:37 +0200 From: Ludek Finstrle To: Hiroshi Inoue Cc: pgsql-odbc@postgresql.org Subject: Re: Patch for snprintf problem (bug #1000650) Message-ID: <20060609081637.GA8153@soptik.pzkagis.cz> References: <20060607173910.GA28221@soptik.pzkagis.cz> <4488B6EA.9050107@tpf.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4488B6EA.9050107@tpf.co.jp> User-Agent: Mutt/1.4.1i X-Virus-Scanned: ClamAV 0.88.2/1523/Fri Jun 9 09:10:10 2006 on smtp.pzkagis.cz X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/43 X-Sequence-Number: 7791 > > 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; > } > > ... I'm not sure. There are a lot of strcat, my_strcat, schema_strcat calls between snprintf. There is only one place where snprintf could be called after another snprintf. BTW it's something what snprintf_addlen is doing. Or am I miss something? I do the patch with minimal changes in mind. In my opinion strcat may be faster in joining more char *. Regards, Luf