| File: | src/lib/libelf/libelf_allocate.c |
| Warning: | line 183, column 3 Value stored to 'd' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /*- |
| 2 | * Copyright (c) 2006,2008,2010 Joseph Koshy |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 24 | * SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * Internal APIs |
| 29 | */ |
| 30 | |
| 31 | #include <assert.h> |
| 32 | #include <errno(*__errno()).h> |
| 33 | #include <libelf.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
| 36 | |
| 37 | #include "_libelf.h" |
| 38 | |
| 39 | ELFTC_VCSID("$Id: libelf_allocate.c,v 1.3 2020/05/18 06:46:23 jsg Exp $")__asm__(".ident\t\"" "$Id: libelf_allocate.c,v 1.3 2020/05/18 06:46:23 jsg Exp $" "\""); |
| 40 | |
| 41 | Elf * |
| 42 | _libelf_allocate_elf(void) |
| 43 | { |
| 44 | Elf *e; |
| 45 | |
| 46 | if ((e = calloc((size_t) 1, sizeof(*e))) == NULL((void *)0)) { |
| 47 | LIBELF_SET_ERROR(RESOURCE, errno)do { (_libelf.libelf_error) = (((ELF_E_RESOURCE) & 0xFF) | ((((*__errno()))) << 8)); } while (0); |
| 48 | return NULL((void *)0); |
| 49 | } |
| 50 | |
| 51 | e->e_activations = 1; |
| 52 | e->e_byteorder = ELFDATANONE0; |
| 53 | e->e_class = ELFCLASSNONE0; |
| 54 | e->e_cmd = ELF_C_NULL; |
| 55 | e->e_fd = -1; |
| 56 | e->e_kind = ELF_K_NONE; |
| 57 | e->e_version = LIBELF_PRIVATE(version)(_libelf.libelf_version); |
| 58 | |
| 59 | return (e); |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | _libelf_init_elf(Elf *e, Elf_Kind kind) |
| 64 | { |
| 65 | assert(e != NULL)((e != ((void *)0)) ? (void)0 : __assert2("/usr/src/lib/libelf/libelf_allocate.c" , 65, __func__, "e != NULL")); |
| 66 | assert(e->e_kind == ELF_K_NONE)((e->e_kind == ELF_K_NONE) ? (void)0 : __assert2("/usr/src/lib/libelf/libelf_allocate.c" , 66, __func__, "e->e_kind == ELF_K_NONE")); |
| 67 | |
| 68 | e->e_kind = kind; |
| 69 | |
| 70 | switch (kind) { |
| 71 | case ELF_K_ELF: |
| 72 | STAILQ_INIT(&e->e_u.e_elf.e_scn)do { (((&e->e_u.e_elf.e_scn))->stqh_first) = ((void *)0); (&e->e_u.e_elf.e_scn)->stqh_last = &(((& e->e_u.e_elf.e_scn))->stqh_first); } while (0); |
| 73 | break; |
| 74 | default: |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | _libelf_release_elf(Elf *e) |
| 81 | { |
| 82 | Elf_Arhdr *arh; |
| 83 | |
| 84 | switch (e->e_kind) { |
| 85 | case ELF_K_AR: |
| 86 | free(e->e_u.e_ar.e_symtab); |
| 87 | break; |
| 88 | |
| 89 | case ELF_K_ELF: |
| 90 | switch (e->e_class) { |
| 91 | case ELFCLASS321: |
| 92 | free(e->e_u.e_elf.e_ehdr.e_ehdr32); |
| 93 | free(e->e_u.e_elf.e_phdr.e_phdr32); |
| 94 | break; |
| 95 | case ELFCLASS642: |
| 96 | free(e->e_u.e_elf.e_ehdr.e_ehdr64); |
| 97 | free(e->e_u.e_elf.e_phdr.e_phdr64); |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn))(((((&e->e_u.e_elf.e_scn)->stqh_first) == ((void *) 0))) ? (void)0 : __assert2("/usr/src/lib/libelf/libelf_allocate.c" , 101, __func__, "STAILQ_EMPTY(&e->e_u.e_elf.e_scn)")); |
| 102 | |
| 103 | if (e->e_flags & LIBELF_F_AR_HEADER0x010000U) { |
| 104 | arh = e->e_hdr.e_arhdr; |
| 105 | free(arh->ar_name); |
| 106 | free(arh->ar_rawname); |
| 107 | free(arh); |
| 108 | } |
| 109 | |
| 110 | break; |
| 111 | |
| 112 | default: |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | free(e); |
| 117 | } |
| 118 | |
| 119 | struct _Libelf_Data * |
| 120 | _libelf_allocate_data(Elf_Scn *s) |
| 121 | { |
| 122 | struct _Libelf_Data *d; |
| 123 | |
| 124 | if ((d = calloc((size_t) 1, sizeof(*d))) == NULL((void *)0)) { |
| 125 | LIBELF_SET_ERROR(RESOURCE, 0)do { (_libelf.libelf_error) = (((ELF_E_RESOURCE) & 0xFF) | (((0)) << 8)); } while (0); |
| 126 | return (NULL((void *)0)); |
| 127 | } |
| 128 | |
| 129 | d->d_scn = s; |
| 130 | |
| 131 | return (d); |
| 132 | } |
| 133 | |
| 134 | struct _Libelf_Data * |
| 135 | _libelf_release_data(struct _Libelf_Data *d) |
| 136 | { |
| 137 | |
| 138 | if (d->d_flags & LIBELF_F_DATA_MALLOCED0x040000U) |
| 139 | free(d->d_data.d_buf); |
| 140 | |
| 141 | free(d); |
| 142 | |
| 143 | return (NULL((void *)0)); |
| 144 | } |
| 145 | |
| 146 | Elf_Scn * |
| 147 | _libelf_allocate_scn(Elf *e, size_t ndx) |
| 148 | { |
| 149 | Elf_Scn *s; |
| 150 | |
| 151 | if ((s = calloc((size_t) 1, sizeof(Elf_Scn))) == NULL((void *)0)) { |
| 152 | LIBELF_SET_ERROR(RESOURCE, errno)do { (_libelf.libelf_error) = (((ELF_E_RESOURCE) & 0xFF) | ((((*__errno()))) << 8)); } while (0); |
| 153 | return (NULL((void *)0)); |
| 154 | } |
| 155 | |
| 156 | s->s_elf = e; |
| 157 | s->s_ndx = ndx; |
| 158 | |
| 159 | STAILQ_INIT(&s->s_data)do { (((&s->s_data))->stqh_first) = ((void *)0); (& s->s_data)->stqh_last = &(((&s->s_data))-> stqh_first); } while (0); |
| 160 | STAILQ_INIT(&s->s_rawdata)do { (((&s->s_rawdata))->stqh_first) = ((void *)0); (&s->s_rawdata)->stqh_last = &(((&s->s_rawdata ))->stqh_first); } while (0); |
| 161 | |
| 162 | STAILQ_INSERT_TAIL(&e->e_u.e_elf.e_scn, s, s_next)do { (((s))->s_next.stqe_next) = ((void *)0); *(&e-> e_u.e_elf.e_scn)->stqh_last = (s); (&e->e_u.e_elf.e_scn )->stqh_last = &(((s))->s_next.stqe_next); } while ( 0); |
| 163 | |
| 164 | return (s); |
| 165 | } |
| 166 | |
| 167 | Elf_Scn * |
| 168 | _libelf_release_scn(Elf_Scn *s) |
| 169 | { |
| 170 | Elf *e; |
| 171 | struct _Libelf_Data *d, *td; |
| 172 | |
| 173 | assert(s != NULL)((s != ((void *)0)) ? (void)0 : __assert2("/usr/src/lib/libelf/libelf_allocate.c" , 173, __func__, "s != NULL")); |
| 174 | |
| 175 | STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td)for ((d) = ((&s->s_data)->stqh_first); (d) && ((td) = ((d)->d_next.stqe_next), 1); (d) = (td)) { |
| 176 | STAILQ_REMOVE(&s->s_data, d, _Libelf_Data, d_next)do { if ((((&s->s_data))->stqh_first) == (d)) { do { if ((((((&s->s_data)))->stqh_first) = ((((((&s ->s_data)))->stqh_first))->d_next.stqe_next)) == ((void *)0)) ((&s->s_data))->stqh_last = &((((&s-> s_data)))->stqh_first); } while (0); } else { struct _Libelf_Data *curelm = (&s->s_data)->stqh_first; while (((curelm )->d_next.stqe_next) != (d)) curelm = ((curelm)->d_next .stqe_next); do { if ((((curelm)->d_next.stqe_next) = (((( curelm)->d_next.stqe_next))->d_next.stqe_next)) == ((void *)0)) (&s->s_data)->stqh_last = &(((curelm))-> d_next.stqe_next); } while (0); } } while (0); |
| 177 | d = _libelf_release_data(d); |
| 178 | } |
| 179 | |
| 180 | STAILQ_FOREACH_SAFE(d, &s->s_rawdata, d_next, td)for ((d) = ((&s->s_rawdata)->stqh_first); (d) && ((td) = ((d)->d_next.stqe_next), 1); (d) = (td)) { |
| 181 | assert((d->d_flags & LIBELF_F_DATA_MALLOCED) == 0)(((d->d_flags & 0x040000U) == 0) ? (void)0 : __assert2 ("/usr/src/lib/libelf/libelf_allocate.c", 181, __func__, "(d->d_flags & LIBELF_F_DATA_MALLOCED) == 0" )); |
| 182 | STAILQ_REMOVE(&s->s_rawdata, d, _Libelf_Data, d_next)do { if ((((&s->s_rawdata))->stqh_first) == (d)) { do { if ((((((&s->s_rawdata)))->stqh_first) = ((((((& s->s_rawdata)))->stqh_first))->d_next.stqe_next)) == ((void *)0)) ((&s->s_rawdata))->stqh_last = &( (((&s->s_rawdata)))->stqh_first); } while (0); } else { struct _Libelf_Data *curelm = (&s->s_rawdata)->stqh_first ; while (((curelm)->d_next.stqe_next) != (d)) curelm = ((curelm )->d_next.stqe_next); do { if ((((curelm)->d_next.stqe_next ) = ((((curelm)->d_next.stqe_next))->d_next.stqe_next)) == ((void *)0)) (&s->s_rawdata)->stqh_last = & (((curelm))->d_next.stqe_next); } while (0); } } while (0); |
| 183 | d = _libelf_release_data(d); |
Value stored to 'd' is never read | |
| 184 | } |
| 185 | |
| 186 | e = s->s_elf; |
| 187 | |
| 188 | assert(e != NULL)((e != ((void *)0)) ? (void)0 : __assert2("/usr/src/lib/libelf/libelf_allocate.c" , 188, __func__, "e != NULL")); |
| 189 | |
| 190 | STAILQ_REMOVE(&e->e_u.e_elf.e_scn, s, _Elf_Scn, s_next)do { if ((((&e->e_u.e_elf.e_scn))->stqh_first) == ( s)) { do { if ((((((&e->e_u.e_elf.e_scn)))->stqh_first ) = ((((((&e->e_u.e_elf.e_scn)))->stqh_first))-> s_next.stqe_next)) == ((void *)0)) ((&e->e_u.e_elf.e_scn ))->stqh_last = &((((&e->e_u.e_elf.e_scn)))-> stqh_first); } while (0); } else { struct _Elf_Scn *curelm = ( &e->e_u.e_elf.e_scn)->stqh_first; while (((curelm)-> s_next.stqe_next) != (s)) curelm = ((curelm)->s_next.stqe_next ); do { if ((((curelm)->s_next.stqe_next) = ((((curelm)-> s_next.stqe_next))->s_next.stqe_next)) == ((void *)0)) (& e->e_u.e_elf.e_scn)->stqh_last = &(((curelm))->s_next .stqe_next); } while (0); } } while (0); |
| 191 | |
| 192 | free(s); |
| 193 | |
| 194 | return (NULL((void *)0)); |
| 195 | } |