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-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",
|
||||
|
||||
Reference in New Issue
Block a user