Re: RFC: Add a short doc with libvirt coding style guidelines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
> Thoughts.. ?

Thanks for writing that up.
I like them all -- of course :-)

>        Libvirt Hacking Guidelines
>        --------------------------
>   1. Apply sizeof to the return variable, not the type.
>   2. Do not use conditionals in front of 'free'.
>   3. Include "config.h" in all source files
>   4. Indent in 4 space units, without tabs
>   5. Ensure any user visible strings are marked for translation

Here are a few proposed additions:
(IMHO, each that we agree on should be automatically checked)

  * avoid global-scoped variables
  * avoid trailing blanks and blank lines at end of file
  * avoid SPACE-TAB (i.e., " 	") esp. in indentation, but even in
      other contexts, like globs and regular expressions: i.e., prefer to
      use the TAB-SPACE sequence, grep '[	 ]$' ..., to the SPACE-TAB one.
      Of course, it's even better if you can use the syntax where the TAB
      is actually visible: /[\t ]$/.
  * use const-correct types (I don't know how to check this automatically)

With these, it is easier (or "possible") to reject invalid inputs:

  * avoid atof, atoi, atol, etc.
  * if you use strto*, be very careful, or consider the xstrto* wrappers
  * avoid parsing with sscanf

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]