Remove the discard_const() macro
Declare dynamically allocated strings as 'char *' instead of 'const char *'. Remove the discard_const() macro. Do not test whether or not a pointer is NULL before calling free() because it is allowed to pass NULL to free(). Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This commit is contained in:
@@ -37,10 +37,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
int showluns;
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-ls";
|
||||
|
||||
@@ -318,7 +314,7 @@ int main(int argc, char *argv[])
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
struct client_state state;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
int c;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
|
||||
@@ -384,9 +380,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
iscsi_url = iscsi_parse_portal_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
@@ -549,12 +549,12 @@ EXTERN int iscsi_logout_sync(struct iscsi_context *iscsi);
|
||||
|
||||
struct iscsi_target_portal {
|
||||
struct iscsi_target_portal *next;
|
||||
const char *portal;
|
||||
char *portal;
|
||||
};
|
||||
|
||||
struct iscsi_discovery_address {
|
||||
struct iscsi_discovery_address *next;
|
||||
const char *target_name;
|
||||
char *target_name;
|
||||
struct iscsi_target_portal *portals;
|
||||
};
|
||||
|
||||
|
||||
@@ -89,14 +89,14 @@ iscsi_free_discovery_addresses(struct iscsi_context *iscsi, struct iscsi_discove
|
||||
while (addresses != NULL) {
|
||||
struct iscsi_discovery_address *next = addresses->next;
|
||||
|
||||
iscsi_free(iscsi, discard_const(addresses->target_name));
|
||||
iscsi_free(iscsi, addresses->target_name);
|
||||
addresses->target_name = NULL;
|
||||
|
||||
while (addresses->portals != NULL) {
|
||||
struct iscsi_target_portal *next_portal = addresses->portals->next;
|
||||
|
||||
iscsi_free(iscsi, discard_const(addresses->portals->portal));
|
||||
iscsi_free(iscsi, discard_const(addresses->portals));
|
||||
iscsi_free(iscsi, addresses->portals->portal);
|
||||
iscsi_free(iscsi, addresses->portals);
|
||||
|
||||
addresses->portals = next_portal;
|
||||
}
|
||||
|
||||
@@ -1828,11 +1828,12 @@ void iscsi_free_discovery_data(struct iscsi_context *iscsi _U_,
|
||||
|
||||
while (da->portals) {
|
||||
struct iscsi_target_portal *ponext = da->portals->next;
|
||||
free(discard_const(da->portals->portal));
|
||||
|
||||
free(da->portals->portal);
|
||||
free(da->portals);
|
||||
da->portals = ponext;
|
||||
}
|
||||
free(discard_const(da->target_name));
|
||||
free(da->target_name);
|
||||
free(da);
|
||||
da = danext;
|
||||
}
|
||||
|
||||
@@ -298,10 +298,8 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
if (sdev->iscsi_url) {
|
||||
time_t current_time = time(NULL);
|
||||
|
||||
if (sdev->error_str != NULL) {
|
||||
free(discard_const(sdev->error_str));
|
||||
sdev->error_str = NULL;
|
||||
}
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = NULL;
|
||||
task = iscsi_scsi_command_sync(sdev->iscsi_ctx, sdev->iscsi_lun, task, NULL);
|
||||
if (task == NULL) {
|
||||
sdev->error_str = strdup(iscsi_get_error(sdev->iscsi_ctx));
|
||||
@@ -372,9 +370,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
if(ioctl(sdev->sgio_fd, SG_IO, &io_hdr) < 0){
|
||||
int err = errno;
|
||||
|
||||
if (sdev->error_str != NULL) {
|
||||
free(discard_const(sdev->error_str));
|
||||
}
|
||||
free(sdev->error_str);
|
||||
if (asprintf(&sdev->error_str, "SG_IO ioctl failed: %s",
|
||||
strerror(err)) < 0)
|
||||
sdev->error_str = NULL;
|
||||
@@ -401,18 +397,14 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
task->sense.key,
|
||||
scsi_sense_ascq_str(task->sense.ascq),
|
||||
task->sense.ascq);
|
||||
if (sdev->error_str != NULL) {
|
||||
free(discard_const(sdev->error_str));
|
||||
}
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = strdup(buf);
|
||||
return task;
|
||||
}
|
||||
|
||||
if(io_hdr.status == SCSI_STATUS_RESERVATION_CONFLICT){
|
||||
task->status = SCSI_STATUS_RESERVATION_CONFLICT;
|
||||
if (sdev->error_str != NULL) {
|
||||
free(discard_const(sdev->error_str));
|
||||
}
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = strdup("Reservation Conflict");
|
||||
return task;
|
||||
}
|
||||
@@ -422,9 +414,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
task->sense.key = 0x0f;
|
||||
task->sense.ascq = 0xffff;
|
||||
|
||||
if (sdev->error_str != NULL) {
|
||||
free(discard_const(sdev->error_str));
|
||||
}
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = strdup("SCSI masked error");
|
||||
return NULL;
|
||||
}
|
||||
@@ -434,9 +424,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
task->sense.ascq = 0xffff;
|
||||
|
||||
snprintf(buf, sizeof(buf), "SCSI host error. Status=0x%x", io_hdr.host_status);
|
||||
if (sdev->error_str != NULL) {
|
||||
free(discard_const(sdev->error_str));
|
||||
}
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = strdup(buf);
|
||||
return task;
|
||||
}
|
||||
@@ -445,9 +433,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
task->sense.key = 0x0f;
|
||||
task->sense.ascq = 0xffff;
|
||||
|
||||
if (sdev->error_str != NULL) {
|
||||
free(discard_const(sdev->error_str));
|
||||
}
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = strdup("SCSI driver error");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -30,10 +30,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
extern const char *initiatorname1;
|
||||
extern const char *initiatorname2;
|
||||
|
||||
|
||||
@@ -37,10 +37,6 @@
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-header-digest";
|
||||
|
||||
struct client_state {
|
||||
@@ -136,7 +132,7 @@ int main(int argc, char *argv[])
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
struct client_state state;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
int c;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
|
||||
@@ -210,10 +206,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -37,10 +37,6 @@
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-noop-reply";
|
||||
|
||||
struct client_state {
|
||||
@@ -136,7 +132,7 @@ int main(int argc, char *argv[])
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
struct client_state state;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
int c;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
|
||||
@@ -210,10 +206,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -34,10 +34,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-readwrite-iov";
|
||||
|
||||
void print_usage(void)
|
||||
@@ -84,7 +80,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
int c, i, count;
|
||||
|
||||
@@ -156,10 +152,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -34,10 +34,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-readwrite-iov";
|
||||
|
||||
void print_usage(void)
|
||||
@@ -75,7 +71,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
struct scsi_task *task;
|
||||
struct scsi_iovec iov[4];
|
||||
@@ -152,10 +148,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -34,10 +34,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-reconnect";
|
||||
|
||||
struct client_state {
|
||||
@@ -194,7 +190,7 @@ int main(int argc, char *argv[])
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
struct client_state state;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
int i, c;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
struct scsi_readcapacity10 *rc10;
|
||||
@@ -270,10 +266,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -34,10 +34,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-reconnect-timeout";
|
||||
|
||||
struct client_state {
|
||||
@@ -217,7 +213,7 @@ int main(int argc, char *argv[])
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
struct client_state state;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
int i, c;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
struct scsi_readcapacity10 *rc10;
|
||||
@@ -293,10 +289,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -38,10 +38,6 @@
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-timeout";
|
||||
|
||||
void print_usage(void)
|
||||
@@ -108,7 +104,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
int c;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
uint32_t count;
|
||||
@@ -182,9 +178,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-inq";
|
||||
|
||||
void inquiry_block_limits(struct scsi_inquiry_block_limits *inq)
|
||||
@@ -236,7 +232,7 @@ void print_help(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
int evpd = 0, pagecode = 0;
|
||||
int show_help = 0, show_usage = 0, debug = 0;
|
||||
@@ -312,10 +308,8 @@ int main(int argc, char *argv[])
|
||||
exit(10);
|
||||
}
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -40,10 +40,6 @@ WSADATA wsaData;
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
int showluns;
|
||||
int useurls;
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-ls";
|
||||
@@ -349,7 +345,7 @@ int main(int argc, char *argv[])
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
struct client_state state;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
int i;
|
||||
static int show_help = 0, show_usage = 0, debug = 0;
|
||||
|
||||
@@ -418,10 +414,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
iscsi_url = iscsi_parse_portal_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -26,10 +26,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-readcapacity16";
|
||||
|
||||
void print_usage(void)
|
||||
@@ -59,7 +55,7 @@ void print_help(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
int show_help = 0, show_usage = 0, debug = 0, size_only=0;
|
||||
int c;
|
||||
@@ -134,10 +130,8 @@ int main(int argc, char *argv[])
|
||||
exit(10);
|
||||
}
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
if (url) {
|
||||
free(discard_const(url));
|
||||
}
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
@@ -30,10 +30,6 @@
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
#ifndef discard_const
|
||||
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
|
||||
#endif
|
||||
|
||||
const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-swp";
|
||||
|
||||
|
||||
@@ -65,7 +61,7 @@ void print_help(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
const char *url = NULL;
|
||||
char *url = NULL;
|
||||
struct iscsi_url *iscsi_url = NULL;
|
||||
int show_help = 0, show_usage = 0, debug = 0;
|
||||
int c;
|
||||
@@ -148,8 +144,8 @@ int main(int argc, char *argv[])
|
||||
goto finished;
|
||||
}
|
||||
iscsi_url = iscsi_parse_full_url(iscsi, url);
|
||||
|
||||
free(discard_const(url));
|
||||
|
||||
free(url);
|
||||
|
||||
if (iscsi_url == NULL) {
|
||||
fprintf(stderr, "Failed to parse URL: %s\n",
|
||||
|
||||
Reference in New Issue
Block a user