From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 809B7385BF92 for ; Wed, 1 Apr 2020 20:34:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 809B7385BF92 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-92-0MGYKY_DO1eEVvJnf5dXsQ-1; Wed, 01 Apr 2020 16:34:11 -0400 X-MC-Unique: 0MGYKY_DO1eEVvJnf5dXsQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C8161937FC1; Wed, 1 Apr 2020 20:34:10 +0000 (UTC) Received: from greed.delorie.com (ovpn-114-252.phx2.redhat.com [10.3.114.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E265DA10A; Wed, 1 Apr 2020 20:34:10 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id 031KY9sf009055; Wed, 1 Apr 2020 16:34:09 -0400 From: DJ Delorie To: Girish Joshi Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] manual: Fix backtraces code example [BZ #10441] In-Reply-To: (message from Girish Joshi on Tue, 10 Mar 2020 21:40:29 +0530) Date: Wed, 01 Apr 2020 16:34:09 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 20:34:14 -0000 LGTM but I've noted some suggestions for clarity too. Reviewed-by: DJ Delorie Girish Joshi writes: > Validation for pointer returned by backtrace_symbols () added. Do we want to add some printf for the "else" case? I don't think it adds to the example... > Type of variables size and i is changed from size_t to int. Protypes are (stripped): extern int backtrace (void **__array, int __size); extern char **backtrace_symbols (void *const *__array, int __size); So "int" for size is OK. i loops size, so "int" for i also ok. > void *array[10]; > - size_t size; > char **strings; > - size_t i; > + int size, i; Ok; prototypes call for "int" not "size_t". > size =3D backtrace (array, 10); > strings =3D backtrace_symbols (array, size); > + if (strings) > + { Checking for valid pointer should be "if (strings !=3D NULL)" in our coding standards, but OK. > - printf ("Obtained %zd stack frames.\n", size); > - > - for (i =3D 0; i < size; i++) > - printf ("%s\n", strings[i]); > + printf ("Obtained %d stack frames.\n", size); %zd -> %d, no other changes. > + for (i =3D 0; i < size; i++) > + printf ("%s\n", strings[i]); Indent only, ok. > + } close new block, ok.