This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: two questions about GDB coding standards


   Date: Tue, 17 May 2005 11:13:21 -0400
   From: Wu Zhou <woodzltc@cn.ibm.com>

   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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]