Print this page
10138 smatch fixes for usr/src/cmd/sgs


  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  *      Copyright (c) 1988 AT&T
  28  *        All Rights Reserved
  29  */
  30 




  31 #include <ar.h>
  32 #include <stdlib.h>
  33 #include <memory.h>
  34 #include <errno.h>
  35 #include <libelf.h>
  36 #include "decl.h"
  37 #include "msg.h"
  38 #include "member.h"
  39 
  40 #define MANGLE  '\177'
  41 
  42 
  43 /*
  44  * Archive processing
  45  *      When processing an archive member, two things can happen
  46  *      that are a little tricky.
  47  *
  48  * Sliding
  49  *      Sliding support is left in for backward compatibility and for
  50  *      support of Archives produced on other systems.  The bundled


 139                         if (i->m_offset == file)
 140                                 return (i->m_member);
 141 
 142         if (f->ar_fmag[0] != fmag[0] || f->ar_fmag[1] != fmag[1]) {
 143                 _elf_seterr(EFMT_ARFMAG, 0);
 144                 return (0);
 145         }
 146 
 147         /*
 148          * Allocate a new member structure and assign it to the next free
 149          * free memlist ident.
 150          */
 151         if ((m = (Member *)malloc(sizeof (Member))) == 0) {
 152                 _elf_seterr(EMEM_ARMEM, errno);
 153                 return (0);
 154         }
 155         if ((elf->ed_memlist == 0) || (ol->m_free == ol->m_end)) {
 156                 if ((l = (Memlist *)malloc(sizeof (Memlist) +
 157                     (sizeof (Memident) * MEMIDENTNO))) == 0) {
 158                         _elf_seterr(EMEM_ARMEM, errno);

 159                         return (0);
 160                 }
 161                 l->m_next = 0;
 162                 l->m_free = (Memident *)(l + 1);
 163                 l->m_end = (Memident *)((uintptr_t)l->m_free +
 164                     (sizeof (Memident) * MEMIDENTNO));
 165 
 166                 if (elf->ed_memlist == 0)
 167                         elf->ed_memlist = l;
 168                 else
 169                         ol->m_next = l;
 170                 ol = l;
 171         }
 172         ol->m_free->m_offset = file;
 173         ol->m_free->m_member = m;
 174         ol->m_free++;
 175 
 176         m->m_err = 0;
 177         (void) memcpy(m->m_name, f->ar_name, ARSZ(ar_name));
 178         m->m_name[ARSZ(ar_name)] = '\0';




  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  *      Copyright (c) 1988 AT&T
  28  *        All Rights Reserved
  29  */
  30 
  31 /*
  32  * Copyright (c) 2018, Joyent, Inc.
  33  */
  34 
  35 #include <ar.h>
  36 #include <stdlib.h>
  37 #include <memory.h>
  38 #include <errno.h>
  39 #include <libelf.h>
  40 #include "decl.h"
  41 #include "msg.h"
  42 #include "member.h"
  43 
  44 #define MANGLE  '\177'
  45 
  46 
  47 /*
  48  * Archive processing
  49  *      When processing an archive member, two things can happen
  50  *      that are a little tricky.
  51  *
  52  * Sliding
  53  *      Sliding support is left in for backward compatibility and for
  54  *      support of Archives produced on other systems.  The bundled


 143                         if (i->m_offset == file)
 144                                 return (i->m_member);
 145 
 146         if (f->ar_fmag[0] != fmag[0] || f->ar_fmag[1] != fmag[1]) {
 147                 _elf_seterr(EFMT_ARFMAG, 0);
 148                 return (0);
 149         }
 150 
 151         /*
 152          * Allocate a new member structure and assign it to the next free
 153          * free memlist ident.
 154          */
 155         if ((m = (Member *)malloc(sizeof (Member))) == 0) {
 156                 _elf_seterr(EMEM_ARMEM, errno);
 157                 return (0);
 158         }
 159         if ((elf->ed_memlist == 0) || (ol->m_free == ol->m_end)) {
 160                 if ((l = (Memlist *)malloc(sizeof (Memlist) +
 161                     (sizeof (Memident) * MEMIDENTNO))) == 0) {
 162                         _elf_seterr(EMEM_ARMEM, errno);
 163                         free(m);
 164                         return (0);
 165                 }
 166                 l->m_next = 0;
 167                 l->m_free = (Memident *)(l + 1);
 168                 l->m_end = (Memident *)((uintptr_t)l->m_free +
 169                     (sizeof (Memident) * MEMIDENTNO));
 170 
 171                 if (elf->ed_memlist == 0)
 172                         elf->ed_memlist = l;
 173                 else
 174                         ol->m_next = l;
 175                 ol = l;
 176         }
 177         ol->m_free->m_offset = file;
 178         ol->m_free->m_member = m;
 179         ol->m_free++;
 180 
 181         m->m_err = 0;
 182         (void) memcpy(m->m_name, f->ar_name, ARSZ(ar_name));
 183         m->m_name[ARSZ(ar_name)] = '\0';