From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 191531F855 for ; Fri, 5 Aug 2016 06:24:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030287AbcHEGYh (ORCPT ); Fri, 5 Aug 2016 02:24:37 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:50267 "EHLO sasl.smtp.pobox.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1030269AbcHEGYg (ORCPT ); Fri, 5 Aug 2016 02:24:36 -0400 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 2B12B2B8A8; Fri, 5 Aug 2016 02:24:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=nDGnBQyeol8Avm4gTlAe5blr9JI=; b=EY4J3O YqVgStzfP72nUpjmgSG1V1jYZHSoeYlsP6aPJjhoaBpziDvyoJV25Oihy0OKEZYE oF8IrLXuOMN91cb1CMLZMxaVVVL55o9Ub4nPes8Q0tBPaivnZ97WKMBlVYXMWBwB JHRm6rMUmB76Just5ZfJSiw0VKkS69A8Ak+jE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=tJjwOsaejzGAC5NrctmNL8b8/ppnC49p YyOf9wV04vTkH8eG0/bd85GRvZFL4mM8UmLI3M2IuzM2BXaJGmdjVr+mxUime3Q9 7PKaHgrjoqz1HtE3qO/JkHhXKSJZlFeE5IQ1OVvwDulm/pIAquRiIcaouwuT0Kw/ mMx30eygMeQ= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 234DD2B8A7; Fri, 5 Aug 2016 02:24:35 -0400 (EDT) Received: from pobox.com (unknown [104.132.0.95]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 9E1D42B8A6; Fri, 5 Aug 2016 02:24:34 -0400 (EDT) From: Junio C Hamano To: Johannes Sixt Cc: Johannes Schindelin , =?utf-8?Q?Ren=C3=A9?= Scharfe , git@vger.kernel.org Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning References: <57360f4885bdd5c36e190bea288f1e1f7f706071.1470326812.git.johannes.schindelin@gmx.de> <57A3BA26.5080601@web.de> <5ce2ec67-aa7d-0079-54fe-d73a70a46825@kdbg.org> <68c24062-7fcc-758f-373f-2f123c5eb78b@kdbg.org> Date: Thu, 04 Aug 2016 23:24:32 -0700 In-Reply-To: <68c24062-7fcc-758f-373f-2f123c5eb78b@kdbg.org> (Johannes Sixt's message of "Fri, 5 Aug 2016 07:40:48 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 46F85F58-5AD5-11E6-AD61-EE617A1B28F4-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Johannes Sixt writes: > Oh! This is a typo. You meant to check s2 for NULL. > > And the declaration for s2 should remain, of course. Yeah, the moral of the story is don't try to do something you do not usually do X-<. The second try (the log message is the same). I do not know if we want to worry about st_add(1, strlen(s1)) overflow around here, though. compat/nedmalloc/nedmalloc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c index 677d1b2..2d4ef59 100644 --- a/compat/nedmalloc/nedmalloc.c +++ b/compat/nedmalloc/nedmalloc.c @@ -955,12 +955,11 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void ** */ char *strdup(const char *s1) { - char *s2 = 0; - if (s1) { - size_t len = strlen(s1) + 1; - s2 = malloc(len); + size_t len = strlen(s1) + 1; + char *s2 = malloc(len); + + if (s2) memcpy(s2, s1, len); - } return s2; } #endif