From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Hansen Newsgroups: gmane.lisp.guile.bugs Subject: Weird scm_to_latin1_string() behavior. Date: Sat, 10 Sep 2011 03:33:27 +0200 Organization: disorganized Message-ID: <877h5hji54.fsf@localhorst.mine.nu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1315619417 28042 80.91.229.12 (10 Sep 2011 01:50:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 10 Sep 2011 01:50:17 +0000 (UTC) To: bug-guile@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Sep 10 03:50:14 2011 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R2Chx-0007mY-FH for guile-bugs@m.gmane.org; Sat, 10 Sep 2011 03:50:13 +0200 Original-Received: from localhost ([::1]:35648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2Chx-0008G5-3H for guile-bugs@m.gmane.org; Fri, 09 Sep 2011 21:50:13 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:48362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2Chu-0008Fy-Ql for bug-guile@gnu.org; Fri, 09 Sep 2011 21:50:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R2Cht-0007pu-QM for bug-guile@gnu.org; Fri, 09 Sep 2011 21:50:10 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:55997) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2Cht-0007po-Ix for bug-guile@gnu.org; Fri, 09 Sep 2011 21:50:09 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1R2Chq-0007kU-1B for bug-guile@gnu.org; Sat, 10 Sep 2011 03:50:06 +0200 Original-Received: from g225129240.adsl.alicedsl.de ([92.225.129.240]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 10 Sep 2011 03:50:05 +0200 Original-Received: from david.hansen by g225129240.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 10 Sep 2011 03:50:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: bug-guile@gnu.org Original-Lines: 68 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: g225129240.adsl.alicedsl.de Mail-Copies-To: nobody User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:ygJKs21GEZRZl6tbLxJu3QryLuU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:5819 Archived-At: --=-=-= Content-Type: text/plain Hello, the attached code produces $ ./a.out foo,bar bar while I would expect $ ./a.out foo bar Similar behavior can be produced with `substring', but `substring/copy' will work as expected. So I suspect this is some issue with strings sharing memory and a missing '0' when scm_to_latin1_string calls scm_strdup. David --=-=-= Content-Type: text/x-csrc Content-Disposition: inline; filename=main.c #include /* This outputs: dhansen@localhorst ~/tmp $ ./a.out foo,bar bar */ static void inner_main (void *data, int argc, char **argv) { char *cstr; SCM string = scm_from_latin1_string ("foo,bar"); SCM tokens = scm_string_split (string, SCM_MAKE_CHAR (',')); SCM tok; for (tok = tokens; !scm_is_null (tok); tok = scm_cdr (tok)) { cstr = scm_to_latin1_string (scm_car (tok)); printf ("%s\n", cstr); free (cstr); } } int main (int argc, char **argv) { scm_boot_guile (argc, argv, inner_main, NULL); } /* Local Variables: */ /* compile-command: "gcc `pkg-config --cflags --libs guile-2.0` main.c" */ /* End: */ --=-=-=--