LCOV - code coverage report
Current view: top level - libebl - eblmachineflagname.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 20 25 80.0 %
Date: 2024-03-01 16:42:08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 14 71.4 %

           Branch data     Line data    Source code
       1                 :            : /* Return machine flag names.
       2                 :            :    Copyright (C) 2001, 2002 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2001.
       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 <stdio.h>
      35                 :            : #include <string.h>
      36                 :            : #include <system.h>
      37                 :            : #include <libeblP.h>
      38                 :            : 
      39                 :            : 
      40                 :            : const char *
      41                 :        226 : ebl_machine_flag_name (Ebl *ebl, Elf64_Word flags, char *buf, size_t len)
      42                 :            : {
      43                 :            :   const char *res;
      44                 :            : 
      45         [ +  + ]:        226 :   if (flags == 0)
      46                 :        224 :     res = "";
      47                 :            :   else
      48                 :            :     {
      49                 :          2 :       Elf64_Word orig_flags = flags;
      50                 :          2 :       char *cp = buf;
      51                 :          2 :       bool first = true;
      52                 :            :       const char *machstr;
      53                 :            :       size_t machstrlen;
      54                 :            : 
      55                 :            :       do
      56                 :            :         {
      57         [ +  + ]:          4 :           if (! first)
      58                 :            :             {
      59         [ -  + ]:          2 :               if (cp + 2 >= buf + len)
      60                 :          0 :                 break;
      61                 :          2 :               *cp++ = ',';
      62                 :          2 :               *cp++ = ' ';
      63                 :            :             }
      64                 :            : 
      65         [ +  - ]:          4 :           machstr = ebl != NULL ? ebl->machine_flag_name (orig_flags, &flags) : NULL;
      66         [ -  + ]:          4 :           if (machstr == NULL)
      67                 :            :             {
      68                 :            :               /* No more known flag.  */
      69                 :          0 :               snprintf (cp, buf + len - cp, "%#x", flags);
      70                 :          0 :               break;
      71                 :            :             }
      72                 :            : 
      73                 :          4 :           machstrlen = strlen (machstr) + 1;
      74         [ -  + ]:          4 :           if ((size_t) (buf + len - cp) < machstrlen)
      75                 :            :             {
      76                 :          0 :               *((char *) mempcpy (cp, machstr, buf + len - cp - 1)) = '\0';
      77                 :          0 :               break;
      78                 :            :             }
      79                 :            : 
      80                 :          4 :           cp = mempcpy (cp, machstr, machstrlen);
      81                 :          4 :           --cp;
      82                 :            : 
      83                 :          4 :           first = false;
      84                 :            :         }
      85         [ +  + ]:          4 :       while (flags != 0);
      86                 :            : 
      87                 :          2 :       res = buf;
      88                 :            :     }
      89                 :            : 
      90                 :        226 :   return res;
      91                 :            : }

Generated by: LCOV version 1.14