Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/README.Coding

    r740 r988  
    1717common and supported by tools and editors.
    1818
    19 The basic style, also mentioned in prog_guide4.txt, is the Linux kernel
     19The basic style for C code, also mentioned in prog_guide4.txt, is the Linux kernel
    2020coding style (See Documentation/CodingStyle in the kernel source tree). This
    2121closely matches what most Samba developers use already anyways, with a few
    2222exceptions as mentioned below.
     23
     24The coding style for Python code is documented in PEP8,
     25http://www.python.org/pep/pep8 (with spaces).
     26If you have ever worked on another free software Python project, you are
     27probably already familiar with it.
    2328
    2429But to save you the trouble of reading the Linux kernel style guide, here
     
    276281
    277282                if (y < 10) {
    278                         z = malloc(sizeof(int)*y);
    279                         if (!z) {
     283                        z = malloc(sizeof(int) * y);
     284                        if (z == NULL) {
    280285                                ret = 1;
    281286                                goto done;
     
    286291
    287292         done:
    288                 if (z) {
     293                if (z != NULL) {
    289294                        free(z);
    290295                }
    291296
    292297                return ret;
    293         }
    294 
    295 
    296 Checking Pointer Values
    297 -----------------------
    298 
    299 When invoking functions that return pointer values, either of the following
    300 are acceptable. Use your best judgement and choose the more readable option.
    301 Remember that many other persons will review it:
    302 
    303         if ((x = malloc(sizeof(short)*10)) == NULL ) {
    304                 fprintf(stderr, "Unable to alloc memory!\n");
    305         }
    306 
    307 or:
    308 
    309         x = malloc(sizeof(short)*10);
    310         if (!x) {
    311                 fprintf(stderr, "Unable to alloc memory!\n");
    312298        }
    313299
     
    335321but for new code, please don't do that anymore.
    336322
     323Initialize pointers
     324-------------------
     325
     326All pointer variables MUST be initialized to NULL. History has
     327demonstrated that uninitialized pointer variables have lead to various
     328bugs and security issues.
     329
     330Pointers MUST be initialized even if the assignment directly follows
     331the declaration, like pointer2 in the example below, because the
     332instructions sequence may change over time.
     333
     334Good Example:
     335
     336        char *pointer1 = NULL;
     337        char *pointer2 = NULL;
     338
     339        pointer2 = some_func2();
     340
     341        ...
     342
     343        pointer1 = some_func1();
     344
     345Bad Example:
     346
     347        char *pointer1;
     348        char *pointer2;
     349
     350        pointer2 = some_func2();
     351
     352        ...
     353
     354        pointer1 = some_func1();
     355
    337356Make use of helper variables
    338357----------------------------
     
    344363Good Example:
    345364
    346         char *name;
     365        char *name = NULL;
    347366
    348367        name = get_some_name();
     
    360379        ...
    361380
     381Please try to avoid passing function return values to if- or
     382while-conditions. The reason for this is better handling of code under a
     383debugger.
     384
     385Good example:
     386
     387        x = malloc(sizeof(short)*10);
     388        if (x == NULL) {
     389                fprintf(stderr, "Unable to alloc memory!\n");
     390        }
     391
     392Bad example:
     393
     394        if ((x = malloc(sizeof(short)*10)) == NULL ) {
     395                fprintf(stderr, "Unable to alloc memory!\n");
     396        }
     397
     398There are exceptions to this rule. One example is walking a data structure in
     399an iterator style:
     400
     401        while ((opt = poptGetNextOpt(pc)) != -1) {
     402                   ... do something with opt ...
     403        }
     404
     405But in general, please try to avoid this pattern.
     406
     407
     408Control-Flow changing macros
     409----------------------------
     410
     411Macros like NT_STATUS_NOT_OK_RETURN that change control flow
     412(return/goto/etc) from within the macro are considered bad, because
     413they look like function calls that never change control flow. Please
     414do not use them in new code.
     415
     416The only exception is the test code that depends repeated use of calls
     417like CHECK_STATUS, CHECK_VAL and others.
     418
     419
     420DEBUG statements
     421----------------
     422
     423Use these following macros instead of DEBUG:
     424
     425DBG_ERR log level 0             error conditions
     426DBG_WARNING     log level 1             warning conditions
     427DBG_NOTICE      log level 3             normal, but significant, condition
     428DBG_INFO        log level 5             informational message
     429DBG_DEBUG       log level 10            debug-level message
     430
     431Example usage:
     432
     433DBG_ERR("Memory allocation failed\n");
     434DBG_DEBUG("Received %d bytes\n", count);
     435
     436The messages from these macros are automatically prefixed with the
     437function name.
Note: See TracChangeset for help on using the changeset viewer.