From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.bugs Subject: Re: Weird scm_to_latin1_string() behavior. Date: Sat, 10 Sep 2011 16:03:55 +0200 Message-ID: References: <877h5hji54.fsf@localhorst.mine.nu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=0015176f1128bb702604ac96c3ac X-Trace: dough.gmane.org 1315663445 697 80.91.229.12 (10 Sep 2011 14:04:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 10 Sep 2011 14:04:05 +0000 (UTC) To: bug-guile@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Sep 10 16:04:02 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 1R2OA4-0000b7-SG for guile-bugs@m.gmane.org; Sat, 10 Sep 2011 16:04:01 +0200 Original-Received: from localhost ([::1]:55247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2OA4-0001PU-6b for guile-bugs@m.gmane.org; Sat, 10 Sep 2011 10:04:00 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:48153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2OA1-0001NR-T0 for bug-guile@gnu.org; Sat, 10 Sep 2011 10:03:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R2OA0-0005pl-Sl for bug-guile@gnu.org; Sat, 10 Sep 2011 10:03:57 -0400 Original-Received: from mail-yx0-f169.google.com ([209.85.213.169]:55105) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2OA0-0005pg-QF for bug-guile@gnu.org; Sat, 10 Sep 2011 10:03:56 -0400 Original-Received: by yxi19 with SMTP id 19so1277307yxi.0 for ; Sat, 10 Sep 2011 07:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=4Ybqlsi92k8EMsc21KgwwOrF00wt3Y9ZFcoryrCv3Rs=; b=d6lb8q7EsOP9IkwPPqyWCADQAsBFSCxtpOxDZhgM0c6aVny+55/dsUMoXP4cInC2fQ 4fk69JkDp4Jp2iae0G2kV94ZHUFbDgBQ1oHZkmRwGh3ku6GI/APaM3V0ZuPLVPtd71tu B3kkypXt9OG22l0w+hIQVCg6a5qOYIyrQMr/Q= Original-Received: by 10.231.47.206 with SMTP id o14mr167602ibf.58.1315663435755; Sat, 10 Sep 2011 07:03:55 -0700 (PDT) Original-Received: by 10.231.127.83 with HTTP; Sat, 10 Sep 2011 07:03:55 -0700 (PDT) In-Reply-To: <877h5hji54.fsf@localhorst.mine.nu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.213.169 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:5821 Archived-At: --0015176f1128bb702604ac96c3ac Content-Type: multipart/alternative; boundary=0015176f1128bb702004ac96c3aa --0015176f1128bb702004ac96c3aa Content-Type: text/plain; charset=ISO-8859-1 using strndup in stead of strdup fixes this acording to the attached git-diff. so it remains to make sure strndup is portable I guess. /Stefan On Sat, Sep 10, 2011 at 3:33 AM, David Hansen wrote: > 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 > > --0015176f1128bb702004ac96c3aa Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable using strndup in stead of strdup fixes this acording to the attached git-di= ff.
so it remains to make sure strndup is portable I guess.

/Stef= an

On Sat, Sep 10, 2011 at 3:33 AM, David= Hansen <david= .hansen@gmx.net> wrote:
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&= #39;
will work as expected. =A0So I suspect this is some issue with strings
sharing memory and a missing '0' when scm_to_latin1_string calls scm_strdup.

David


--0015176f1128bb702004ac96c3aa-- --0015176f1128bb702604ac96c3ac Content-Type: text/x-patch; charset=US-ASCII; name="strndupfix.diff" Content-Disposition: attachment; filename="strndupfix.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gseo1oxg1 ZGlmZiAtLWdpdCBhL2xpYmd1aWxlL3N0cmluZ3MuYyBiL2xpYmd1aWxlL3N0cmluZ3MuYwppbmRl eCAyNGM4MmZjLi5kZDcwY2UxIDEwMDY0NAotLS0gYS9saWJndWlsZS9zdHJpbmdzLmMKKysrIGIv bGliZ3VpbGUvc3RyaW5ncy5jCkBAIC0xNzc5LDE0ICsxNzc5LDE1IEBAIHNjbV90b19sYXRpbjFf c3RyaW5nbiAoU0NNIHN0ciwgc2l6ZV90ICpsZW5wKQogCiAgIGlmIChzY21faV9pc19uYXJyb3df c3RyaW5nIChzdHIpKQogICAgIHsKKyAgICAgIHNpemVfdCBsZW4gPSBzY21faV9zdHJpbmdfbGVu Z3RoIChzdHIpOwogICAgICAgaWYgKGxlbnApCi0JKmxlbnAgPSBzY21faV9zdHJpbmdfbGVuZ3Ro IChzdHIpOwotCi0gICAgICByZXN1bHQgPSBzY21fc3RyZHVwIChzY21faV9zdHJpbmdfZGF0YSAo c3RyKSk7CisgICAgICAgICpsZW5wID0gbGVuOworICAgICAgcmVzdWx0ID0gc2NtX3N0cm5kdXAg KHNjbV9pX3N0cmluZ19kYXRhIChzdHIpLCBsZW4pOwogICAgIH0KICAgZWxzZQogICAgIHJlc3Vs dCA9IHNjbV90b19zdHJpbmduIChzdHIsIGxlbnAsIE5VTEwsCi0JCQkgICAgIFNDTV9GQUlMRURf Q09OVkVSU0lPTl9FUlJPUik7CisgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFNDTV9GQUlM RURfQ09OVkVSU0lPTl9FUlJPUik7Cit9CiAKICAgcmV0dXJuIHJlc3VsdDsKIH0K --0015176f1128bb702604ac96c3ac--