Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


  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) 1988 AT&T
  24  *        All Rights Reserved
  25  *
  26  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 /*
  31  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  32  */
  33 
  34 /*
  35  * Map file parsing (Shared Support Code).
  36  */
  37 #include        <stdio.h>
  38 #include        <errno.h>
  39 #include        "msg.h"
  40 #include        "_libld.h"
  41 #include        "_map.h"
  42 
  43 /*
  44  * Given a NULL terminated array of structures of arbitrary type, where
  45  * each struct contains (among other fields) a character pointer field
  46  * giving that struct a unique name, return the address of the struct
  47  * that matches the given name.
  48  *
  49  * entry:
  50  *      name - "Keyword" name to be found.
  51  *      array - Base address of array


  67  *      to solve the problem at hand.
  68  */
  69 #ifndef _ELF64
  70 void *
  71 ld_map_kwfind(const char *name, void *array, size_t name_offset,
  72     size_t elt_size)
  73 {
  74         for (; ; array = elt_size + (char *)array) {
  75                 /* LINTED E_BAD_PTR_CAST_ALIGN */
  76                 const char *arr_name = *((const char **)
  77                     (name_offset + (const char *) array));
  78 
  79                 if (arr_name == NULL)
  80                         return (NULL);
  81 
  82                 if (strcasecmp(name, arr_name) == 0)
  83                         return (array);
  84         }
  85 
  86         /*NOTREACHED*/
  87         assert(0);
  88         return (NULL);
  89 }
  90 #endif
  91 
  92 /*
  93  * Given the same NULL terminated array accepted by ld_map_kwfind(), format
  94  * the strings into a comma separated list of names.
  95  *
  96  * entry:
  97  *      array - Base address of array
  98  *      name_offset - Offset of the name field within the struct
  99  *              type used by this array, as generated via
 100  *              SGSOFFSETOF().
 101  *      elt_size - sizeof the basic array element type
 102  *      buf - Buffer to receive output
 103  *      bufsize - sizeof(buf)
 104  *
 105  * exit:
 106  *      As many of the names as will fit are formatted into buf. If all the
 107  *      names do not fit, the remainder are quietly clipped. The caller must
 108  *      ensure that there is sufficient room. buf is returned, for convenience




  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) 1988 AT&T
  24  *        All Rights Reserved
  25  *
  26  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 /*
  31  * Copyright 2019 Joyent, Inc.
  32  */
  33 
  34 /*
  35  * Map file parsing (Shared Support Code).
  36  */
  37 #include        <stdio.h>
  38 #include        <errno.h>
  39 #include        "msg.h"
  40 #include        "_libld.h"
  41 #include        "_map.h"
  42 
  43 /*
  44  * Given a NULL terminated array of structures of arbitrary type, where
  45  * each struct contains (among other fields) a character pointer field
  46  * giving that struct a unique name, return the address of the struct
  47  * that matches the given name.
  48  *
  49  * entry:
  50  *      name - "Keyword" name to be found.
  51  *      array - Base address of array


  67  *      to solve the problem at hand.
  68  */
  69 #ifndef _ELF64
  70 void *
  71 ld_map_kwfind(const char *name, void *array, size_t name_offset,
  72     size_t elt_size)
  73 {
  74         for (; ; array = elt_size + (char *)array) {
  75                 /* LINTED E_BAD_PTR_CAST_ALIGN */
  76                 const char *arr_name = *((const char **)
  77                     (name_offset + (const char *) array));
  78 
  79                 if (arr_name == NULL)
  80                         return (NULL);
  81 
  82                 if (strcasecmp(name, arr_name) == 0)
  83                         return (array);
  84         }
  85 
  86         /*NOTREACHED*/


  87 }
  88 #endif
  89 
  90 /*
  91  * Given the same NULL terminated array accepted by ld_map_kwfind(), format
  92  * the strings into a comma separated list of names.
  93  *
  94  * entry:
  95  *      array - Base address of array
  96  *      name_offset - Offset of the name field within the struct
  97  *              type used by this array, as generated via
  98  *              SGSOFFSETOF().
  99  *      elt_size - sizeof the basic array element type
 100  *      buf - Buffer to receive output
 101  *      bufsize - sizeof(buf)
 102  *
 103  * exit:
 104  *      As many of the names as will fit are formatted into buf. If all the
 105  *      names do not fit, the remainder are quietly clipped. The caller must
 106  *      ensure that there is sufficient room. buf is returned, for convenience