From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.raindrops.general Subject: Re: Re: [PATCH] Remove Scope IDs from IPv6 addresses. Date: Tue, 10 Sep 2013 20:17:06 +0000 Message-ID: <20130910201706.GA6250@dcvr.yhbt.net> References: <1378826261-10771-1-git-send-email-375gnu@gmail.com> <20130910183504.GA502@dcvr.yhbt.net> <20130910183630.GB502@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1378844241 27384 80.91.229.3 (10 Sep 2013 20:17:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Sep 2013 20:17:21 +0000 (UTC) To: raindrops@librelist.org Original-X-From: raindrops@librelist.org Tue Sep 10 22:17:23 2013 Return-path: Envelope-to: gclrrg-raindrops@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: raindrops@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.raindrops.general:132 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VJUND-000769-6I for gclrrg-raindrops@m.gmane.org; Tue, 10 Sep 2013 22:17:19 +0200 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 3822C7506B for ; Tue, 10 Sep 2013 20:26:47 +0000 (UTC) Hleb Valoshka <375gnu@gmail.com> wrote: > On 9/10/13, Eric Wong wrote: > >> + newaddr = strdup(addr); > >> + if (newaddr == NULL) > >> + perror("strdup"); > > > > We'll segfault on strchr below if we perrored above. If we continue > > using strdup, I would just use ruby_strdup() (works on both MRI/rbx). > > I haven't use C for a long time, so I thought that strchr checks its args. > > > But I'd rather avoid *strdup entirely. This is unlikely to > > remove, right? > > Frankly speaking I dislike functions similar to strdup(), because > using them you should remember to call free(), sometimes in many > places (or to use goto). But I'm unfamiliar with internal ruby api, so > it was the only variant for me. I try to avoid strdup, too. I can help you with Ruby C API :) The advantage of creating Ruby strings right away is it maintains length, so one can use mem* functions instead of str* functions (always faster and more explicit, often safer, and never less safe). > BTW, is anything bad with that variant: > char *newaddr = alloca(...); > remove_scope_id(oldaddr, newaddr); Probably OK in this case, but it would need a comment explaining to stack checkers the size is bounded and won't overflow. > > Perhaps something like this (totally untested, likely off-by-one errors) > > Ok, I'll test your code tomorrow. Thanks.