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>


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 




  26 #include <sys/types.h>
  27 #include <sys/scsi/generic/commands.h>
  28 #include <sys/scsi/impl/spc3_types.h>
  29 
  30 #include <stddef.h>
  31 #include <stdlib.h>
  32 #include <string.h>
  33 #include <strings.h>
  34 #include <alloca.h>
  35 #include <stdio.h>
  36 #include <unistd.h>
  37 #include <dlfcn.h>
  38 
  39 #include <scsi/libscsi.h>
  40 #include "libscsi_impl.h"
  41 
  42 int
  43 libscsi_assert(const char *expr, const char *file, int line)
  44 {
  45         char *msg;
  46         size_t len;
  47 
  48         len = snprintf(NULL, 0,
  49             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  50 
  51         msg = alloca(len + 1);
  52 
  53         (void) snprintf(msg, len + 1,
  54             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  55 
  56         (void) write(STDERR_FILENO, msg, strlen(msg));
  57 
  58         abort();
  59         _exit(1);
  60 
  61         /*NOTREACHED*/
  62         return (0);
  63 }
  64 
  65 int
  66 libscsi_set_errno(libscsi_hdl_t *hp, libscsi_errno_t err)
  67 {
  68         hp->lsh_errno = err;
  69         hp->lsh_errmsg[0] = '\0';
  70 
  71         return (-1);
  72 }
  73 
  74 /*
  75  * Internal routine for setting both _ue_errno and _ue_errmsg.  We save
  76  * and restore the UNIX errno across this routing so the caller can use either
  77  * libscsi_set_errno(), libscsi_error(), or libscsi_verror() without this value
  78  * changing.
  79  */
  80 int
  81 libscsi_verror(libscsi_hdl_t *hp, libscsi_errno_t err, const char *fmt,
  82     va_list ap)




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2019 Joyent, Inc.
  28  */
  29 
  30 #include <sys/types.h>
  31 #include <sys/scsi/generic/commands.h>
  32 #include <sys/scsi/impl/spc3_types.h>
  33 
  34 #include <stddef.h>
  35 #include <stdlib.h>
  36 #include <string.h>
  37 #include <strings.h>
  38 #include <alloca.h>
  39 #include <stdio.h>
  40 #include <unistd.h>
  41 #include <dlfcn.h>
  42 
  43 #include <scsi/libscsi.h>
  44 #include "libscsi_impl.h"
  45 
  46 int
  47 libscsi_assert(const char *expr, const char *file, int line)
  48 {
  49         char *msg;
  50         size_t len;
  51 
  52         len = snprintf(NULL, 0,
  53             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  54 
  55         msg = alloca(len + 1);
  56 
  57         (void) snprintf(msg, len + 1,
  58             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  59 
  60         (void) write(STDERR_FILENO, msg, strlen(msg));
  61 
  62         abort();


  63         /*NOTREACHED*/

  64 }
  65 
  66 int
  67 libscsi_set_errno(libscsi_hdl_t *hp, libscsi_errno_t err)
  68 {
  69         hp->lsh_errno = err;
  70         hp->lsh_errmsg[0] = '\0';
  71 
  72         return (-1);
  73 }
  74 
  75 /*
  76  * Internal routine for setting both _ue_errno and _ue_errmsg.  We save
  77  * and restore the UNIX errno across this routing so the caller can use either
  78  * libscsi_set_errno(), libscsi_error(), or libscsi_verror() without this value
  79  * changing.
  80  */
  81 int
  82 libscsi_verror(libscsi_hdl_t *hp, libscsi_errno_t err, const char *fmt,
  83     va_list ap)