From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18067 invoked by alias); 17 May 2005 20:19:18 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 17729 invoked from network); 17 May 2005 20:19:05 -0000 Received: from unknown (HELO sibelius.xs4all.nl) (82.92.89.47) by sourceware.org with SMTP; 17 May 2005 20:19:05 -0000 Received: from elgar.sibelius.xs4all.nl (root@elgar.sibelius.xs4all.nl [192.168.0.2]) by sibelius.xs4all.nl (8.13.0/8.13.0) with ESMTP id j4HKIuvl014372; Tue, 17 May 2005 22:18:56 +0200 (CEST) Received: from elgar.sibelius.xs4all.nl (kettenis@localhost.sibelius.xs4all.nl [127.0.0.1]) by elgar.sibelius.xs4all.nl (8.13.4/8.13.3) with ESMTP id j4HKItvW011177; Tue, 17 May 2005 22:18:55 +0200 (CEST) Received: (from kettenis@localhost) by elgar.sibelius.xs4all.nl (8.13.4/8.13.4/Submit) id j4HKIlks006900; Tue, 17 May 2005 22:18:47 +0200 (CEST) Date: Tue, 17 May 2005 20:33:00 -0000 Message-Id: <200505172018.j4HKIlks006900@elgar.sibelius.xs4all.nl> From: Mark Kettenis To: woodzltc@cn.ibm.com CC: gdb-patches@sources.redhat.com In-reply-to: <1116342801.428a0a113167f@imap.linux.ibm.com> (message from Wu Zhou on Tue, 17 May 2005 11:13:21 -0400) Subject: Re: two questions about GDB coding standards References: <1116342801.428a0a113167f@imap.linux.ibm.com> X-SW-Source: 2005-05/txt/msg00428.txt.bz2 Date: Tue, 17 May 2005 11:13:21 -0400 From: Wu Zhou Hello all, I am now reading GDB coding standards(section 13.4 of GDB Internals) and have two questions as follow. Maybe someone of you could clarify for me. Thanks in advance. 1. In section 13.4.2(memory management), it is said that gdb uses the string function xstrdup and the print function xasprintf. But I saw in the source codes that most places use sprintf instead. Besides this in-consistence, we also know that sprintf is very prone to buffer overflow error. So my question here is whether sprintf should be replaced by xasprintf here or is there any plan to achieve this? As OpenBSD warns these days: "sprintf() is often misused, please use snprintf()" The usage of sprintf is mainly historic, and a bad example that shouldn't be followed. Patches to get rid of it are welcome, and mostly obvious ;-). Whether xasprintf is the right replacement, depends on the context. In some cases the usage of xsnprintf might be more appropriate. The later is a version of snprintf that checks whether the generated string fits in the buffer. Hmm. Perhaps I should change the aforementioned paragraph. 2. In section 13.4.3(compiler warnings), it is said that: due to the way that gdb is implemented most functions have unused parameters. Consequently the warning "-Wunused-parameter" is precluded from the list. What is the way it refered in this context? BTW, I also find there are many unused variables in gdb source codes by using a static analysis tool. But there is no "-Wunused-variable" in compiler option to detect this. My question here is: should this kind of unused variables be detected or furthermore be removed out of the source to make it more readable? The coding standards doesn't say anything about this. As configure.ac says, -Wunused-variable is up for debate. Looks like you just started that debate ;-). But before we enable it someone will have to do the dirty work of finding most of the unused variables, such that compiling with -Werror keeps being possible. Elimination of unused variables is defenitely obvious, but watch out for tricky #ifdef's. Mark