Coverage report for dbus/dbus-internals.c.gcov

        -:    0:Source:dbus-internals.c
        -:    0:Graph:.libs/dbus-internals.gcno
        -:    0:Data:.libs/dbus-internals.gcda
        -:    0:Runs:11817
        -:    0:Programs:5
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* dbus-internals.c  random utility stuff (internal to D-BUS implementation)
        -:    3: *
        -:    4: * Copyright (C) 2002, 2003  Red Hat, Inc.
        -:    5: *
        -:    6: * Licensed under the Academic Free License version 2.1
        -:    7: * 
        -:    8: * This program is free software; you can redistribute it and/or modify
        -:    9: * it under the terms of the GNU General Public License as published by
        -:   10: * the Free Software Foundation; either version 2 of the License, or
        -:   11: * (at your option) any later version.
        -:   12: *
        -:   13: * This program is distributed in the hope that it will be useful,
        -:   14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   16: * GNU General Public License for more details.
        -:   17: * 
        -:   18: * You should have received a copy of the GNU General Public License
        -:   19: * along with this program; if not, write to the Free Software
        -:   20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        -:   21: *
        -:   22: */
        -:   23:#include "dbus-internals.h"
        -:   24:#include "dbus-protocol.h"
        -:   25:#include "dbus-test.h"
        -:   26:#include <stdio.h>
        -:   27:#include <stdarg.h>
        -:   28:#include <string.h>
        -:   29:#include <sys/types.h>
        -:   30:#include <errno.h>
        -:   31:#include <unistd.h>
        -:   32:#include <fcntl.h>
        -:   33:#include <stdlib.h>
        -:   34:
        -:   35:/**
        -:   36: * @defgroup DBusInternals D-BUS internal implementation details
        -:   37: * @brief Documentation useful when developing or debugging D-BUS itself.
        -:   38: * 
        -:   39: */
        -:   40:
        -:   41:/**
        -:   42: * @defgroup DBusInternalsUtils Utilities and portability
        -:   43: * @ingroup DBusInternals
        -:   44: * @brief Utility functions (_dbus_assert(), _dbus_warn(), etc.)
        -:   45: * @{
        -:   46: */
        -:   47:
        -:   48:/**
        -:   49: * @def _dbus_assert
        -:   50: *
        -:   51: * Aborts with an error message if the condition is false.
        -:   52: * 
        -:   53: * @param condition condition which must be true.
        -:   54: */
        -:   55:
        -:   56:/**
        -:   57: * @def _dbus_assert_not_reached
        -:   58: *
        -:   59: * Aborts with an error message if called.
        -:   60: * The given explanation will be printed.
        -:   61: * 
        -:   62: * @param explanation explanation of what happened if the code was reached.
        -:   63: */
        -:   64:
        -:   65:/**
        -:   66: * @def _DBUS_N_ELEMENTS
        -:   67: *
        -:   68: * Computes the number of elements in a fixed-size array using
        -:   69: * sizeof().
        -:   70: *
        -:   71: * @param array the array to count elements in.
        -:   72: */
        -:   73:
        -:   74:/**
        -:   75: * @def _DBUS_POINTER_TO_INT
        -:   76: *
        -:   77: * Safely casts a void* to an integer; should only be used on void*
        -:   78: * that actually contain integers, for example one created with
        -:   79: * _DBUS_INT_TO_POINTER.  Only guaranteed to preserve 32 bits.
        -:   80: * (i.e. it's used to store 32-bit ints in pointers, but
        -:   81: * can't be used to store 64-bit pointers in ints.)
        -:   82: *
        -:   83: * @param pointer pointer to extract an integer from.
        -:   84: */
        -:   85:/**
        -:   86: * @def _DBUS_INT_TO_POINTER
        -:   87: *
        -:   88: * Safely stuffs an integer into a pointer, to be extracted later with
        -:   89: * _DBUS_POINTER_TO_INT. Only guaranteed to preserve 32 bits.
        -:   90: *
        -:   91: * @param integer the integer to stuff into a pointer.
        -:   92: */
        -:   93:/**
        -:   94: * @def _DBUS_ZERO
        -:   95: *
        -:   96: * Sets all bits in an object to zero.
        -:   97: *
        -:   98: * @param object the object to be zeroed.
        -:   99: */
        -:  100:/**
        -:  101: * @def _DBUS_INT16_MIN
        -:  102: *
        -:  103: * Minimum value of type "int16"
        -:  104: */
        -:  105:/**
        -:  106: * @def _DBUS_INT16_MAX
        -:  107: *
        -:  108: * Maximum value of type "int16"
        -:  109: */
        -:  110:/**
        -:  111: * @def _DBUS_UINT16_MAX
        -:  112: *
        -:  113: * Maximum value of type "uint16"
        -:  114: */
        -:  115:
        -:  116:/**
        -:  117: * @def _DBUS_INT32_MIN
        -:  118: *
        -:  119: * Minimum value of type "int32"
        -:  120: */
        -:  121:/**
        -:  122: * @def _DBUS_INT32_MAX
        -:  123: *
        -:  124: * Maximum value of type "int32"
        -:  125: */
        -:  126:/**
        -:  127: * @def _DBUS_UINT32_MAX
        -:  128: *
        -:  129: * Maximum value of type "uint32"
        -:  130: */
        -:  131:
        -:  132:/**
        -:  133: * @def _DBUS_INT_MIN
        -:  134: *
        -:  135: * Minimum value of type "int"
        -:  136: */
        -:  137:/**
        -:  138: * @def _DBUS_INT_MAX
        -:  139: *
        -:  140: * Maximum value of type "int"
        -:  141: */
        -:  142:/**
        -:  143: * @def _DBUS_UINT_MAX
        -:  144: *
        -:  145: * Maximum value of type "uint"
        -:  146: */
        -:  147:
        -:  148:/**
        -:  149: * @typedef DBusForeachFunction
        -:  150: * 
        -:  151: * Used to iterate over each item in a collection, such as
        -:  152: * a DBusList.
        -:  153: */
        -:  154:
        -:  155:/**
        -:  156: * @def _DBUS_LOCK_NAME
        -:  157: *
        -:  158: * Expands to name of a global lock variable.
        -:  159: */
        -:  160:
        -:  161:/**
        -:  162: * @def _DBUS_DEFINE_GLOBAL_LOCK
        -:  163: *
        -:  164: * Defines a global lock variable with the given name.
        -:  165: * The lock must be added to the list to initialize
        -:  166: * in dbus_threads_init().
        -:  167: */
        -:  168:
        -:  169:/**
        -:  170: * @def _DBUS_DECLARE_GLOBAL_LOCK
        -:  171: *
        -:  172: * Expands to declaration of a global lock defined
        -:  173: * with _DBUS_DEFINE_GLOBAL_LOCK.
        -:  174: * The lock must be added to the list to initialize
        -:  175: * in dbus_threads_init().
        -:  176: */
        -:  177:
        -:  178:/**
        -:  179: * @def _DBUS_LOCK
        -:  180: *
        -:  181: * Locks a global lock
        -:  182: */
        -:  183:
        -:  184:/**
        -:  185: * @def _DBUS_UNLOCK
        -:  186: *
        -:  187: * Unlocks a global lock
        -:  188: */
        -:  189:
        -:  190:/**
        -:  191: * Fixed "out of memory" error message, just to avoid
        -:  192: * making up a different string every time and wasting
        -:  193: * space.
        -:  194: */
        -:  195:const char _dbus_no_memory_message[] = "Not enough memory";
        -:  196:
        -:  197:/**
        -:  198: * Prints a warning message to stderr.
        -:  199: *
        -:  200: * @param format printf-style format string.
        -:  201: */
        -:  202:void
        -:  203:_dbus_warn (const char *format,
        -:  204:            ...)
function _dbus_warn called 31 returned 100% blocks executed 100%
       31:  205:{
        -:  206:  /* FIXME not portable enough? */
        -:  207:  va_list args;
        -:  208:
       31:  209:  va_start (args, format);
call    0 returned 100%
       31:  210:  vfprintf (stderr, format, args);
call    0 returned 100%
       31:  211:  va_end (args);
call    0 returned 100%
       31:  212:}
        -:  213:
        -:  214:#ifdef DBUS_ENABLE_VERBOSE_MODE
        -:  215:
        -:  216:static dbus_bool_t verbose_initted = FALSE;
        -:  217:
        -:  218:#define PTHREAD_IN_VERBOSE 0
        -:  219:#if PTHREAD_IN_VERBOSE
        -:  220:#include <pthread.h>
        -:  221:#endif
        -:  222:
        -:  223:/**
        -:  224: * Prints a warning message to stderr
        -:  225: * if the user has enabled verbose mode.
        -:  226: * This is the real function implementation,
        -:  227: * use _dbus_verbose() macro in code.
        -:  228: *
        -:  229: * @param format printf-style format string.
        -:  230: */
        -:  231:void
        -:  232:_dbus_verbose_real (const char *format,
        -:  233:                    ...)
function _dbus_verbose_real called 46369425 returned 100% blocks executed 39%
 46369425:  234:{
        -:  235:  va_list args;
        -:  236:  static dbus_bool_t verbose = TRUE;
        -:  237:  static dbus_bool_t need_pid = TRUE;
        -:  238:  int len;
        -:  239:  
        -:  240:  /* things are written a bit oddly here so that
        -:  241:   * in the non-verbose case we just have the one
        -:  242:   * conditional and return immediately.
        -:  243:   */
 46369425:  244:  if (!verbose)
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
 46368493:  245:    return;
        -:  246:  
      932:  247:  if (!verbose_initted)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  248:    {
      932:  249:      verbose = _dbus_getenv ("DBUS_VERBOSE") != NULL;
call    0 returned 100%
      932:  250:      verbose_initted = TRUE;
      932:  251:      if (!verbose)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
      932:  252:        return;
        -:  253:    }
        -:  254:
        -:  255:  /* Print out pid before the line */
    #####:  256:  if (need_pid)
branch  0 never executed
branch  1 never executed
        -:  257:    {
        -:  258:#if PTHREAD_IN_VERBOSE
        -:  259:      fprintf (stderr, "%lu: 0x%lx: ", _dbus_getpid (), pthread_self ());
        -:  260:#else
    #####:  261:      fprintf (stderr, "%lu: ", _dbus_getpid ());
call    0 never executed
call    1 never executed
        -:  262:#endif
        -:  263:    }
        -:  264:      
        -:  265:
        -:  266:  /* Only print pid again if the next line is a new line */
    #####:  267:  len = strlen (format);
call    0 never executed
    #####:  268:  if (format[len-1] == '\n')
branch  0 never executed
branch  1 never executed
    #####:  269:    need_pid = TRUE;
        -:  270:  else
    #####:  271:    need_pid = FALSE;
        -:  272:  
    #####:  273:  va_start (args, format);
call    0 never executed
    #####:  274:  vfprintf (stderr, format, args);
call    0 never executed
    #####:  275:  va_end (args);
call    0 never executed
        -:  276:
    #####:  277:  fflush (stderr);
call    0 never executed
        -:  278:}
        -:  279:
        -:  280:/**
        -:  281: * Reinitializes the verbose logging code, used
        -:  282: * as a hack in dbus-spawn.c so that a child
        -:  283: * process re-reads its pid
        -:  284: *
        -:  285: */
        -:  286:void
        -:  287:_dbus_verbose_reset_real (void)
function _dbus_verbose_reset_real called 4611 returned 100% blocks executed 100%
     4611:  288:{
     4611:  289:  verbose_initted = FALSE;
     4611:  290:}
        -:  291:
        -:  292:#endif /* DBUS_ENABLE_VERBOSE_MODE */
        -:  293:
        -:  294:/**
        -:  295: * Duplicates a string. Result must be freed with
        -:  296: * dbus_free(). Returns #NULL if memory allocation fails.
        -:  297: * If the string to be duplicated is #NULL, returns #NULL.
        -:  298: * 
        -:  299: * @param str string to duplicate.
        -:  300: * @returns newly-allocated copy.
        -:  301: */
        -:  302:char*
        -:  303:_dbus_strdup (const char *str)
function _dbus_strdup called 160005 returned 100% blocks executed 100%
   160005:  304:{
        -:  305:  size_t len;
        -:  306:  char *copy;
        -:  307:  
   160005:  308:  if (str == NULL)
branch  0 taken 4% (fallthrough)
branch  1 taken 96%
     6112:  309:    return NULL;
        -:  310:  
   153893:  311:  len = strlen (str);
call    0 returned 100%
        -:  312:
   153893:  313:  copy = dbus_malloc (len + 1);
call    0 returned 100%
   153893:  314:  if (copy == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
      481:  315:    return NULL;
        -:  316:
   153412:  317:  memcpy (copy, str, len + 1);
call    0 returned 100%
        -:  318:  
   153412:  319:  return copy;
        -:  320:}
        -:  321:
        -:  322:/**
        -:  323: * Duplicates a block of memory. Returns
        -:  324: * #NULL on failure.
        -:  325: *
        -:  326: * @param mem memory to copy
        -:  327: * @param n_bytes number of bytes to copy
        -:  328: * @returns the copy
        -:  329: */
        -:  330:void*
        -:  331:_dbus_memdup (const void  *mem,
        -:  332:              size_t       n_bytes)
function _dbus_memdup called 8358 returned 100% blocks executed 100%
     8358:  333:{
        -:  334:  void *copy;
        -:  335:
     8358:  336:  copy = dbus_malloc (n_bytes);
call    0 returned 100%
     8358:  337:  if (copy == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
       20:  338:    return NULL;
        -:  339:
     8338:  340:  memcpy (copy, mem, n_bytes);
call    0 returned 100%
        -:  341:  
     8338:  342:  return copy;
        -:  343:}
        -:  344:
        -:  345:/**
        -:  346: * Duplicates a string array. Result may be freed with
        -:  347: * dbus_free_string_array(). Returns #NULL if memory allocation fails.
        -:  348: * If the array to be duplicated is #NULL, returns #NULL.
        -:  349: * 
        -:  350: * @param array array to duplicate.
        -:  351: * @returns newly-allocated copy.
        -:  352: */
        -:  353:char**
        -:  354:_dbus_dup_string_array (const char **array)
function _dbus_dup_string_array called 4004 returned 100% blocks executed 94%
     4004:  355:{
        -:  356:  int len;
        -:  357:  int i;
        -:  358:  char **copy;
        -:  359:  
     4004:  360:  if (array == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  361:    return NULL;
        -:  362:
     4004:  363:  for (len = 0; array[len] != NULL; ++len)
branch  0 taken 50%
branch  1 taken 50% (fallthrough)
        -:  364:    ;
        -:  365:
     4004:  366:  copy = dbus_new0 (char*, len + 1);
call    0 returned 100%
     4004:  367:  if (copy == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        3:  368:    return NULL;
        -:  369:
     4001:  370:  i = 0;
    12000:  371:  while (i < len)
branch  0 taken 50%
branch  1 taken 50% (fallthrough)
        -:  372:    {
     4001:  373:      copy[i] = _dbus_strdup (array[i]);
call    0 returned 100%
     4001:  374:      if (copy[i] == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  375:        {
        3:  376:          dbus_free_string_array (copy);
call    0 returned 100%
        3:  377:          return NULL;
        -:  378:        }
        -:  379:
     3998:  380:      ++i;
        -:  381:    }
        -:  382:
     3998:  383:  return copy;
        -:  384:}
        -:  385:
        -:  386:/**
        -:  387: * Checks whether a string array contains the given string.
        -:  388: * 
        -:  389: * @param array array to search.
        -:  390: * @param str string to look for
        -:  391: * @returns #TRUE if array contains string
        -:  392: */
        -:  393:dbus_bool_t
        -:  394:_dbus_string_array_contains (const char **array,
        -:  395:                             const char  *str)
function _dbus_string_array_contains called 8493 returned 100% blocks executed 100%
     8493:  396:{
        -:  397:  int i;
        -:  398:
     8493:  399:  i = 0;
    20892:  400:  while (array[i] != NULL)
branch  0 taken 68%
branch  1 taken 32% (fallthrough)
        -:  401:    {
     8493:  402:      if (strcmp (array[i], str) == 0)
call    0 returned 100%
branch  1 taken 54% (fallthrough)
branch  2 taken 46%
     4587:  403:        return TRUE;
     3906:  404:      ++i;
        -:  405:    }
        -:  406:
     3906:  407:  return FALSE;
        -:  408:}
        -:  409:
        -:  410:#ifdef DBUS_BUILD_TESTS
        -:  411:/**
        -:  412: * Returns a string describing the given name.
        -:  413: *
        -:  414: * @param header_field the field to describe
        -:  415: * @returns a constant string describing the field
        -:  416: */
        -:  417:const char *
        -:  418:_dbus_header_field_to_string (int header_field)
function _dbus_header_field_to_string called 0 returned 0% blocks executed 0%
    #####:  419:{
    #####:  420:  switch (header_field)
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
branch  6 never executed
branch  7 never executed
branch  8 never executed
branch  9 never executed
        -:  421:    {
        -:  422:    case DBUS_HEADER_FIELD_INVALID:
    #####:  423:      return "invalid";
        -:  424:    case DBUS_HEADER_FIELD_PATH:
    #####:  425:      return "path";
        -:  426:    case DBUS_HEADER_FIELD_INTERFACE:
    #####:  427:      return "interface";
        -:  428:    case DBUS_HEADER_FIELD_MEMBER:
    #####:  429:      return "member";
        -:  430:    case DBUS_HEADER_FIELD_ERROR_NAME:
    #####:  431:      return "error-name";
        -:  432:    case DBUS_HEADER_FIELD_REPLY_SERIAL:
    #####:  433:      return "reply-serial";
        -:  434:    case DBUS_HEADER_FIELD_DESTINATION:
    #####:  435:      return "destination";
        -:  436:    case DBUS_HEADER_FIELD_SENDER:
    #####:  437:      return "sender";
        -:  438:    case DBUS_HEADER_FIELD_SIGNATURE:
    #####:  439:      return "signature";
        -:  440:    default:
    #####:  441:      return "unknown";
        -:  442:    }
        -:  443:}
        -:  444:#endif /* DBUS_BUILD_TESTS */
        -:  445:
        -:  446:#ifndef DBUS_DISABLE_CHECKS
        -:  447:/** String used in _dbus_return_if_fail macro */
        -:  448:const char _dbus_return_if_fail_warning_format[] =
        -:  449:"%lu: arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
        -:  450:"This is normally a bug in some application using the D-BUS library.\n";
        -:  451:#endif
        -:  452:
        -:  453:#ifndef DBUS_DISABLE_ASSERT
        -:  454:/**
        -:  455: * Internals of _dbus_assert(); it's a function
        -:  456: * rather than a macro with the inline code so
        -:  457: * that the assertion failure blocks don't show up
        -:  458: * in test suite coverage, and to shrink code size.
        -:  459: *
        -:  460: * @param condition TRUE if assertion succeeded
        -:  461: * @param condition_text condition as a string
        -:  462: * @param file file the assertion is in
        -:  463: * @param line line the assertion is in
        -:  464: * @param func function the assertion is in
        -:  465: */
        -:  466:void
        -:  467:_dbus_real_assert (dbus_bool_t  condition,
        -:  468:                   const char  *condition_text,
        -:  469:                   const char  *file,
        -:  470:                   int          line,
        -:  471:                   const char  *func)
function _dbus_real_assert called 3871174413 returned 100% blocks executed 40%
3871174413:  472:{
3871174413:  473:  if (_DBUS_UNLIKELY (!condition))
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  474:    {
    #####:  475:      _dbus_warn ("%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n",
call    0 never executed
call    1 never executed
        -:  476:                  _dbus_getpid (), condition_text, file, line, func);
    #####:  477:      _dbus_abort ();
call    0 never executed
        -:  478:    }
3871174413:  479:}
        -:  480:
        -:  481:/**
        -:  482: * Internals of _dbus_assert_not_reached(); it's a function
        -:  483: * rather than a macro with the inline code so
        -:  484: * that the assertion failure blocks don't show up
        -:  485: * in test suite coverage, and to shrink code size.
        -:  486: *
        -:  487: * @param explanation what was reached that shouldn't have been
        -:  488: * @param file file the assertion is in
        -:  489: * @param line line the assertion is in
        -:  490: */
        -:  491:void
        -:  492:_dbus_real_assert_not_reached (const char *explanation,
        -:  493:                               const char *file,
        -:  494:                               int         line)
function _dbus_real_assert_not_reached called 0 returned 0% blocks executed 0%
    #####:  495:{
    #####:  496:  _dbus_warn ("File \"%s\" line %d process %lu should not have been reached: %s\n",
call    0 never executed
call    1 never executed
        -:  497:              file, line, _dbus_getpid (), explanation);
    #####:  498:  _dbus_abort ();
call    0 never executed
        -:  499:}
        -:  500:#endif /* DBUS_DISABLE_ASSERT */
        -:  501:  
        -:  502:#ifdef DBUS_BUILD_TESTS
        -:  503:static dbus_bool_t
        -:  504:run_failing_each_malloc (int                    n_mallocs,
        -:  505:                         const char            *description,
        -:  506:                         DBusTestMemoryFunction func,
        -:  507:                         void                  *data)
function run_failing_each_malloc called 58 returned 100% blocks executed 100%
       58:  508:{
       58:  509:  n_mallocs += 10; /* fudge factor to ensure reallocs etc. are covered */
        -:  510:  
    14215:  511:  while (n_mallocs >= 0)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  512:    {      
    14100:  513:      _dbus_set_fail_alloc_counter (n_mallocs);
call    0 returned 100%
        -:  514:
    14100:  515:      _dbus_verbose ("\n===\n%s: (will fail malloc %d with %d failures)\n===\n",
call    0 returned 100%
call    1 returned 100%
        -:  516:                     description, n_mallocs,
        -:  517:                     _dbus_get_fail_alloc_failures ());
        -:  518:
    14100:  519:      if (!(* func) (data))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        1:  520:        return FALSE;
        -:  521:      
    14099:  522:      n_mallocs -= 1;
        -:  523:    }
        -:  524:
       57:  525:  _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
call    0 returned 100%
        -:  526:
       57:  527:  return TRUE;
        -:  528:}                        
        -:  529:
        -:  530:/**
        -:  531: * Tests how well the given function responds to out-of-memory
        -:  532: * situations. Calls the function repeatedly, failing a different
        -:  533: * call to malloc() each time. If the function ever returns #FALSE,
        -:  534: * the test fails. The function should return #TRUE whenever something
        -:  535: * valid (such as returning an error, or succeeding) occurs, and #FALSE
        -:  536: * if it gets confused in some way.
        -:  537: *
        -:  538: * @param description description of the test used in verbose output
        -:  539: * @param func function to call
        -:  540: * @param data data to pass to function
        -:  541: * @returns #TRUE if the function never returns FALSE
        -:  542: */
        -:  543:dbus_bool_t
        -:  544:_dbus_test_oom_handling (const char             *description,
        -:  545:                         DBusTestMemoryFunction  func,
        -:  546:                         void                   *data)
function _dbus_test_oom_handling called 20 returned 100% blocks executed 75%
       20:  547:{
        -:  548:  int approx_mallocs;
        -:  549:  const char *setting;
        -:  550:  int max_failures_to_try;
        -:  551:  int i;
        -:  552:
        -:  553:  /* Run once to see about how many mallocs are involved */
        -:  554:  
       20:  555:  _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
call    0 returned 100%
        -:  556:
       20:  557:  _dbus_verbose ("Running once to count mallocs\n");
call    0 returned 100%
        -:  558:  
       20:  559:  if (!(* func) (data))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  560:    return FALSE;
        -:  561:  
       20:  562:  approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
call    0 returned 100%
        -:  563:
       20:  564:  _dbus_verbose ("\n=================\n%s: about %d mallocs total\n=================\n",
call    0 returned 100%
        -:  565:                 description, approx_mallocs);
        -:  566:
       20:  567:  setting = _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES");
call    0 returned 100%
       20:  568:  if (setting != NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  569:    {
        -:  570:      DBusString str;
        -:  571:      long v;
    #####:  572:      _dbus_string_init_const (&str, setting);
call    0 never executed
    #####:  573:      v = 4;
    #####:  574:      if (!_dbus_string_parse_int (&str, 0, &v, NULL))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  575:        _dbus_warn ("couldn't parse '%s' as integer\n", setting);
call    0 never executed
    #####:  576:      max_failures_to_try = v;
        -:  577:    }
        -:  578:  else
        -:  579:    {
       20:  580:      max_failures_to_try = 4;
        -:  581:    }
        -:  582:
       20:  583:  i = setting ? max_failures_to_try - 1 : 1;
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
       97:  584:  while (i < max_failures_to_try)
branch  0 taken 75%
branch  1 taken 25% (fallthrough)
        -:  585:    {
       58:  586:      _dbus_set_fail_alloc_failures (i);
call    0 returned 100%
       58:  587:      if (!run_failing_each_malloc (approx_mallocs, description, func, data))
call    0 returned 100%
branch  1 taken 2% (fallthrough)
branch  2 taken 98%
        1:  588:        return FALSE;
       57:  589:      ++i;
        -:  590:    }
        -:  591:  
       19:  592:  _dbus_verbose ("\n=================\n%s: all iterations passed\n=================\n",
call    0 returned 100%
        -:  593:                 description);
        -:  594:
       19:  595:  return TRUE;
        -:  596:}
        -:  597:#endif /* DBUS_BUILD_TESTS */
        -:  598:
        -:  599:/** @} */