LCOV - code coverage report
Current view: top level - libdw - dwarf_formblock.c (source / functions) Hit Total Coverage
Test: elfutils-0.183 Lines: 19 37 51.4 %
Date: 2021-02-07 19:08:58 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 24 29.2 %

           Branch data     Line data    Source code
       1                 :            : /* Return block represented by attribute.
       2                 :            :    Copyright (C) 2004-2010, 2014, 2018 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
       5                 :            : 
       6                 :            :    This file is free software; you can redistribute it and/or modify
       7                 :            :    it under the terms of either
       8                 :            : 
       9                 :            :      * the GNU Lesser General Public License as published by the Free
      10                 :            :        Software Foundation; either version 3 of the License, or (at
      11                 :            :        your option) any later version
      12                 :            : 
      13                 :            :    or
      14                 :            : 
      15                 :            :      * the GNU General Public License as published by the Free
      16                 :            :        Software Foundation; either version 2 of the License, or (at
      17                 :            :        your option) any later version
      18                 :            : 
      19                 :            :    or both in parallel, as here.
      20                 :            : 
      21                 :            :    elfutils is distributed in the hope that it will be useful, but
      22                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :    General Public License for more details.
      25                 :            : 
      26                 :            :    You should have received copies of the GNU General Public License and
      27                 :            :    the GNU Lesser General Public License along with this program.  If
      28                 :            :    not, see <http://www.gnu.org/licenses/>.  */
      29                 :            : 
      30                 :            : #ifdef HAVE_CONFIG_H
      31                 :            : # include <config.h>
      32                 :            : #endif
      33                 :            : 
      34                 :            : #include <dwarf.h>
      35                 :            : #include "libdwP.h"
      36                 :            : 
      37                 :            : 
      38                 :            : int
      39                 :     816251 : dwarf_formblock (Dwarf_Attribute *attr, Dwarf_Block *return_block)
      40                 :            : {
      41         [ +  - ]:     816251 :   if (attr == NULL)
      42                 :            :     return -1;
      43                 :            : 
      44                 :     816251 :   const unsigned char *datap = attr->valp;
      45                 :     816251 :   const unsigned char *endp = attr->cu->endp;
      46                 :            : 
      47   [ +  -  -  +  :     816251 :   switch (attr->form)
                   -  + ]
      48                 :            :     {
      49                 :         85 :     case DW_FORM_block1:
      50         [ +  - ]:         85 :       if (unlikely (endp - datap < 1))
      51                 :            :         goto invalid;
      52                 :         85 :       return_block->length = *(uint8_t *) attr->valp;
      53                 :         85 :       return_block->data = attr->valp + 1;
      54                 :         85 :       break;
      55                 :            : 
      56                 :          0 :     case DW_FORM_block2:
      57         [ #  # ]:          0 :       if (unlikely (endp - datap < 2))
      58                 :            :         goto invalid;
      59         [ #  # ]:          0 :       return_block->length = read_2ubyte_unaligned (attr->cu->dbg, attr->valp);
      60                 :          0 :       return_block->data = attr->valp + 2;
      61                 :          0 :       break;
      62                 :            : 
      63                 :          0 :     case DW_FORM_block4:
      64         [ #  # ]:          0 :       if (unlikely (endp - datap < 4))
      65                 :            :         goto invalid;
      66         [ #  # ]:          0 :       return_block->length = read_4ubyte_unaligned (attr->cu->dbg, attr->valp);
      67                 :          0 :       return_block->data = attr->valp + 4;
      68                 :          0 :       break;
      69                 :            : 
      70                 :     219187 :     case DW_FORM_block:
      71                 :            :     case DW_FORM_exprloc:
      72         [ +  - ]:     219187 :       if (unlikely (endp - datap < 1))
      73                 :            :         goto invalid;
      74                 :     219187 :       get_uleb128 (return_block->length, datap, endp);
      75                 :     219187 :       return_block->data = (unsigned char *) datap;
      76                 :     219187 :       break;
      77                 :            : 
      78                 :          0 :     case DW_FORM_data16:
      79                 :            :       /* The DWARFv5 spec calls this constant class, but we interpret
      80                 :            :          it as a block that the user will need to interpret when
      81                 :            :          converting to a value.  */
      82         [ #  # ]:          0 :       if (unlikely (endp - datap < 16))
      83                 :            :         goto invalid;
      84                 :          0 :       return_block->length = 16;
      85                 :          0 :       return_block->data = (unsigned char *) datap;
      86                 :          0 :       break;
      87                 :            : 
      88                 :     596979 :     default:
      89                 :     596979 :       __libdw_seterrno (DWARF_E_NO_BLOCK);
      90                 :     596979 :       return -1;
      91                 :            :     }
      92                 :            : 
      93         [ -  + ]:     219272 :   if (unlikely (return_block->length > (size_t) (endp - return_block->data)))
      94                 :            :     {
      95                 :            :       /* Block does not fit.  */
      96                 :          0 :     invalid:
      97                 :          0 :       __libdw_seterrno (DWARF_E_INVALID_DWARF);
      98                 :          0 :       return -1;
      99                 :            :     }
     100                 :            : 
     101                 :            :   return 0;
     102                 :            : }
     103                 :            : INTDEF(dwarf_formblock)

Generated by: LCOV version 1.13