LCOV - code coverage report
Current view: top level - libasm - asm_newsubscn.c (source / functions) Hit Total Coverage
Test: elfutils-0.192 Lines: 21 22 95.5 %
Date: 2024-11-08 23:03:42 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 14 42.9 %

           Branch data     Line data    Source code
       1                 :            : /* Create new subsection section in given section.
       2                 :            :    Copyright (C) 2002 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 <stdlib.h>
      35                 :            : 
      36                 :            : #include <libasmP.h>
      37                 :            : #include <system.h>
      38                 :            : 
      39                 :            : 
      40                 :            : AsmScn_t *
      41                 :          4 : asm_newsubscn (AsmScn_t *asmscn, unsigned int nr)
      42                 :            : {
      43                 :          4 :   AsmScn_t *runp;
      44                 :          4 :   AsmScn_t *newp;
      45                 :            : 
      46                 :            :   /* Just return if no section is given.  The error must have been
      47                 :            :      somewhere else.  */
      48         [ -  + ]:          4 :   if (asmscn == NULL)
      49                 :            :     return NULL;
      50                 :            : 
      51                 :            :   /* Determine whether there is already a subsection with this number.  */
      52         [ -  + ]:          4 :   runp = asmscn->subsection_id == 0 ? asmscn : asmscn->data.up;
      53                 :          4 :   while (1)
      54                 :            :     {
      55         [ -  + ]:          4 :       if (runp->subsection_id == nr)
      56                 :            :         /* Found it.  */
      57                 :          0 :         return runp;
      58                 :            : 
      59   [ -  +  -  - ]:          4 :       if (runp->subnext == NULL || runp->subnext->subsection_id > nr)
      60                 :            :         break;
      61                 :            : 
      62                 :            :       runp = runp->subnext;
      63                 :            :     }
      64                 :            : 
      65                 :          4 :   newp = malloc (sizeof (AsmScn_t));
      66         [ -  + ]:          4 :   if (newp == NULL)
      67                 :            :     return NULL;
      68                 :            : 
      69                 :            :   /* Same assembler context than the original section.  */
      70                 :          4 :   newp->ctx = runp->ctx;
      71                 :            : 
      72                 :            :   /* User provided the subsectio nID.  */
      73                 :          4 :   newp->subsection_id = nr;
      74                 :            : 
      75                 :            :   /* Inherit the parent's type.  */
      76                 :          4 :   newp->type = runp->type;
      77                 :            : 
      78                 :            :   /* Pointer to the zeroth subsection.  */
      79         [ -  + ]:          4 :   newp->data.up = runp->subsection_id == 0 ? runp : runp->data.up;
      80                 :            : 
      81                 :            :   /* We start at offset zero.  */
      82                 :          4 :   newp->offset = 0;
      83                 :            :   /* And generic alignment.  */
      84                 :          4 :   newp->max_align = 1;
      85                 :            : 
      86                 :            :   /* No output yet.  */
      87                 :          4 :   newp->content = NULL;
      88                 :            : 
      89                 :            :   /* Inherit the fill pattern from the section this one is derived from.  */
      90                 :          4 :   newp->pattern = asmscn->pattern;
      91                 :            : 
      92                 :            :   /* Enqueue at the right position in the list.  */
      93                 :          4 :   newp->subnext = runp->subnext;
      94                 :          4 :   runp->subnext = newp;
      95                 :            : 
      96                 :          4 :   return newp;
      97                 :            : }

Generated by: LCOV version 1.16