From 8ed55657283c8b061c5d860c4737bbb17b9077c7 Mon Sep 17 00:00:00 2001 From: ngie Date: Sun, 12 Mar 2017 04:53:27 +0000 Subject: MFC r314189,r314190,r314191: r314189: Fix up NULL/'\0' uses and fix 2 derefs after NULL CID: 1018898, 1018899 r314190: Fix some minor style nits: put parentheses around return values r314191: Fix up r314189 The conditional in do_buff_decode(..) after the while loop was accidentally inverted. Only increment the pointer for fmt if it's not NUL. --- lib/libcam/scsi_cmdparse.c | 57 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'lib/libcam/scsi_cmdparse.c') diff --git a/lib/libcam/scsi_cmdparse.c b/lib/libcam/scsi_cmdparse.c index 8b43066..4561b0b 100644 --- a/lib/libcam/scsi_cmdparse.c +++ b/lib/libcam/scsi_cmdparse.c @@ -128,14 +128,14 @@ do_buff_decode(u_int8_t *buff, size_t len, *(va_arg(*ap, int *)) = (ARG); \ assigned++; \ } \ - field_name[0] = 0; \ + field_name[0] = '\0'; \ suppress = 0; \ } while (0) u_char bits = 0; /* For bit fields */ int shift = 0; /* Bits already shifted out */ suppress = 0; - field_name[0] = 0; + field_name[0] = '\0'; while (!done) { switch(letter = *fmt) { @@ -169,9 +169,9 @@ do_buff_decode(u_int8_t *buff, size_t len, fmt++; } - if (fmt) + if (*fmt != '\0') fmt++; /* Skip '}' */ - field_name[i] = 0; + field_name[i] = '\0'; break; } @@ -255,7 +255,7 @@ do_buff_decode(u_int8_t *buff, size_t len, break; } if (!suppress) { - if (arg_put) + if (arg_put != NULL) (*arg_put)(puthook, (letter == 't' ? 'b' : letter), &buff[ind], width, field_name); @@ -268,7 +268,7 @@ do_buff_decode(u_int8_t *buff, size_t len, for (p = dest + width - 1; p >= dest && *p == ' '; p--) - *p = 0; + *p = '\0'; } } assigned++; @@ -379,22 +379,22 @@ next_field(const char **pp, char *fmt, int *width_p, int *value_p, char *name, field_size = 8; /* Default to byte field type... */ *fmt = 'i'; field_width = 1; /* 1 byte wide */ - if (name) - *name = 0; + if (name != NULL) + *name = '\0'; state = BETWEEN_FIELDS; while (state != DONE) { switch(state) { case BETWEEN_FIELDS: - if (*p == 0) + if (*p == '\0') state = DONE; else if (isspace(*p)) p++; else if (*p == '#') { while (*p && *p != '\n') p++; - if (p) + if (*p != '\0') p++; } else if (*p == '{') { int i = 0; @@ -410,7 +410,7 @@ next_field(const char **pp, char *fmt, int *width_p, int *value_p, char *name, } if(name && i < n_name) - name[i] = 0; + name[i] = '\0'; if (*p == '}') p++; @@ -530,7 +530,7 @@ next_field(const char **pp, char *fmt, int *width_p, int *value_p, char *name, if (is_error) { *error_p = 1; - return 0; + return (0); } *error_p = 0; @@ -568,7 +568,7 @@ do_encode(u_char *buff, size_t vec_max, size_t *used, if (suppress) value = 0; else - value = arg_get ? + value = arg_get != NULL ? (*arg_get)(gethook, field_name) : va_arg(*ap, int); } @@ -659,9 +659,9 @@ do_encode(u_char *buff, size_t vec_max, size_t *used, *used = ind; if (error) - return -1; + return (-1); - return encoded; + return (encoded); } int @@ -672,8 +672,8 @@ csio_decode(struct ccb_scsiio *csio, const char *fmt, ...) va_start(ap, fmt); - retval = do_buff_decode(csio->data_ptr, (size_t)csio->dxfer_len, 0, 0, - fmt, &ap); + retval = do_buff_decode(csio->data_ptr, (size_t)csio->dxfer_len, + NULL, NULL, fmt, &ap); va_end(ap); @@ -705,7 +705,7 @@ buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...) va_start(ap, fmt); - retval = do_buff_decode(buff, len, 0, 0, fmt, &ap); + retval = do_buff_decode(buff, len, NULL, NULL, fmt, &ap); va_end(ap); @@ -723,7 +723,7 @@ buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt, * the arg_put function. */ if (arg_put == NULL) - return(-1); + return (-1); return (do_buff_decode(buff, len, arg_put, puthook, fmt, NULL)); } @@ -779,20 +779,20 @@ csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, int retval; if (csio == NULL) - return(0); + return (0); /* * We need something to encode, but we can't get it without the * arg_get function. */ if (arg_get == NULL) - return(-1); + return (-1); bzero(csio, sizeof(struct ccb_scsiio)); if ((retval = do_encode(csio->cdb_io.cdb_bytes, SCSI_MAX_CDBLEN, &cmdlen, arg_get, gethook, cmd_spec, NULL)) == -1) - return(retval); + return (retval); cam_fill_csio(csio, /* retries */ retry_count, @@ -805,7 +805,7 @@ csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, /* cdb_len */ cmdlen, /* timeout */ timeout ? timeout : 5000); - return(retval); + return (retval); } int @@ -819,7 +819,8 @@ csio_encode(struct ccb_scsiio *csio, const char *fmt, ...) va_start(ap, fmt); - retval = do_encode(csio->data_ptr, csio->dxfer_len, 0, 0, 0, fmt, &ap); + retval = do_encode(csio->data_ptr, csio->dxfer_len, NULL, NULL, NULL, + fmt, &ap); va_end(ap); @@ -836,9 +837,9 @@ buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt, * arg_get function. */ if (arg_get == NULL) - return(-1); + return (-1); - return (do_encode(buff, len, 0, arg_get, gethook, fmt, NULL)); + return (do_encode(buff, len, NULL, arg_get, gethook, fmt, NULL)); } int @@ -851,8 +852,8 @@ csio_encode_visit(struct ccb_scsiio *csio, const char *fmt, * arg_get function. */ if (arg_get == NULL) - return(-1); + return (-1); - return (do_encode(csio->data_ptr, csio->dxfer_len, 0, arg_get, + return (do_encode(csio->data_ptr, csio->dxfer_len, NULL, arg_get, gethook, fmt, NULL)); } -- cgit v1.1