LCOV - code coverage report
Current view: top level - libelf - elf_getshdrnum.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 18 20 90.0 %
Date: 2024-05-08 16:53:58 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 10 60.0 %

           Branch data     Line data    Source code
       1                 :            : /* Return number of sections in the ELF file.
       2                 :            :    Copyright (C) 2002, 2009, 2015 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
       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 <assert.h>
      35                 :            : #include <gelf.h>
      36                 :            : #include <stddef.h>
      37                 :            : 
      38                 :            : #include "libelfP.h"
      39                 :            : 
      40                 :            : 
      41                 :            : int
      42                 :            : internal_function
      43                 :      11176 : __elf_getshdrnum_rdlock (Elf *elf, size_t *dst)
      44                 :            : {
      45                 :      11176 :   int result = 0;
      46                 :      11176 :   int idx;
      47                 :            : 
      48         [ -  + ]:      11176 :   if (elf == NULL)
      49                 :            :     return -1;
      50                 :            : 
      51         [ -  + ]:      11176 :   if (unlikely (elf->kind != ELF_K_ELF))
      52                 :            :     {
      53                 :          0 :       __libelf_seterrno (ELF_E_INVALID_HANDLE);
      54                 :          0 :       return -1;
      55                 :            :     }
      56                 :            : 
      57                 :      11176 :   idx = elf->state.elf.scns_last->cnt;
      58         [ +  + ]:      11176 :   if (idx != 0
      59                 :        278 :       || (elf->state.elf.scns_last
      60                 :            :           != (elf->class == ELFCLASS32
      61                 :            :               || (offsetof (Elf, state.elf32.scns)
      62                 :            :                   == offsetof (Elf, state.elf64.scns))
      63         [ -  + ]:        278 :               ? &elf->state.elf32.scns : &elf->state.elf64.scns)))
      64                 :            :     /* There is at least one section.  */
      65                 :      10898 :     *dst = 1 + elf->state.elf.scns_last->data[idx - 1].index;
      66                 :            :   else
      67                 :        278 :     *dst = 0;
      68                 :            : 
      69                 :            :   return result;
      70                 :            : }
      71                 :            : 
      72                 :            : int
      73                 :       6246 : elf_getshdrnum (Elf *elf, size_t *dst)
      74                 :            : {
      75                 :       6246 :   int result;
      76                 :            : 
      77         [ +  - ]:       6246 :   if (elf == NULL)
      78                 :            :     return -1;
      79                 :            : 
      80                 :       6246 :   rwlock_rdlock (elf->lock);
      81                 :       6246 :   result = __elf_getshdrnum_rdlock (elf, dst);
      82                 :       6246 :   rwlock_unlock (elf->lock);
      83                 :            : 
      84                 :       6246 :   return result;
      85                 :            : }
      86                 :            : /* Alias for the deprecated name.  */
      87                 :            : strong_alias (elf_getshdrnum, elf_getshnum)

Generated by: LCOV version 1.16