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:
Bart Van Assche
2020-02-28 21:32:30 -08:00
parent aff4b7600b
commit 3804f3c2e0
18 changed files with 50 additions and 141 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",