Skip to content

Commit a1da171

Browse files
committed
Consistently use const char * for read-only strings.
1 parent 19fda31 commit a1da171

12 files changed

+21
-18
lines changed

Diff for: mdata_delete.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ main(int argc, char **argv)
5757
mdata_proto_t *mdp;
5858
mdata_response_t mdr;
5959
string_t *data;
60-
char *errmsg = NULL;
60+
const char *errmsg = NULL;
6161

6262
if (argc < 2) {
6363
errx(MDEC_USAGE_ERROR, "Usage: %s <keyname>", argv[0]);

Diff for: mdata_get.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ main(int argc, char **argv)
6363
mdata_proto_t *mdp;
6464
mdata_response_t mdr;
6565
string_t *data;
66-
char *errmsg = NULL;
66+
const char *errmsg = NULL;
6767

6868
if (argc < 2) {
6969
errx(MDEC_USAGE_ERROR, "Usage: %s <keyname>", argv[0]);

Diff for: mdata_list.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ main(int argc __UNUSED, char **argv __UNUSED)
6060
mdata_proto_t *mdp;
6161
mdata_response_t mdr;
6262
string_t *data;
63-
char *errmsg = NULL;
63+
const char *errmsg = NULL;
6464

6565
if (proto_init(&mdp, &errmsg) != 0) {
6666
fprintf(stderr, "ERROR: could not initialise protocol: %s\n",

Diff for: mdata_put.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ main(int argc, char **argv)
5858
mdata_proto_t *mdp;
5959
mdata_response_t mdr;
6060
string_t *data;
61-
char *errmsg = NULL;
61+
const char *errmsg = NULL;
6262
string_t *req = dynstr_new();
6363

6464
if (argc < 2) {

Diff for: plat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef struct mdata_plat mdata_plat_t;
1717
int plat_is_interactive(void);
1818

1919
/*int open_metadata_stream(FILE **fp, char **err);*/
20-
int plat_init(mdata_plat_t **, char **er, int *);
20+
int plat_init(mdata_plat_t **, const char **er, int *);
2121
int plat_recv(mdata_plat_t *, string_t *, int);
2222
int plat_send(mdata_plat_t *, string_t *);
2323
void plat_fini(mdata_plat_t *);

Diff for: plat/bsd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ plat_is_interactive(void)
145145
}
146146

147147
int
148-
plat_init(mdata_plat_t **mplout, char **errmsg, int *permfail)
148+
plat_init(mdata_plat_t **mplout, const char **errmsg, int *permfail)
149149
{
150150
mdata_plat_t *mpl = NULL;
151151

Diff for: plat/linux.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ plat_is_interactive(void)
132132
}
133133

134134
int
135-
plat_init(mdata_plat_t **mplout, char **errmsg, int *permfail)
135+
plat_init(mdata_plat_t **mplout, const char **errmsg, int *permfail)
136136
{
137137
mdata_plat_t *mpl = NULL;
138138
struct epoll_event event;

Diff for: plat/sunos.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ plat_is_interactive(void)
281281
}
282282

283283
int
284-
plat_init(mdata_plat_t **mplout, char **errmsg, int *permfail)
284+
plat_init(mdata_plat_t **mplout, const char **errmsg, int *permfail)
285285
{
286286
char *product;
287287
boolean_t smartdc_hvm_guest = B_FALSE;

Diff for: plat/unix_common.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "common.h"
2020
#include "plat.h"
2121
#include "dynstr.h"
22+
#include "unix_common.h"
2223

2324
int
2425
unix_is_interactive(void)
@@ -27,7 +28,7 @@ unix_is_interactive(void)
2728
}
2829

2930
static int
30-
unix_raw_mode(int fd, char **errmsg)
31+
unix_raw_mode(int fd, const char **errmsg)
3132
{
3233
struct termios tios;
3334

@@ -58,7 +59,7 @@ unix_raw_mode(int fd, char **errmsg)
5859
}
5960

6061
int
61-
unix_open_serial(char *devpath, int *outfd, char **errmsg, int *permfail)
62+
unix_open_serial(const char *devpath, int *outfd, const char **errmsg, int *permfail)
6263
{
6364
int fd;
6465
char scrap[100];

Diff for: plat/unix_common.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ extern "C" {
1313
#include "plat.h"
1414
#include "dynstr.h"
1515

16-
/*int unix_raw_mode(int fd, char **errmsg);*/
17-
int unix_open_serial(char *devpath, int *outfd, char **errmsg, int *permfail);
16+
int unix_open_serial(const char *devpath, int *outfd, const char **errmsg, int *permfail);
1817
int unix_send_reset(mdata_plat_t *mpl);
1918
int unix_is_interactive(void);
2019

Diff for: proto.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ struct mdata_proto {
6060
mdata_proto_state_t mdp_state;
6161
mdata_proto_version_t mdp_version;
6262
boolean_t mdp_in_reset;
63-
char *mdp_errmsg;
64-
char *mdp_parse_errmsg;
63+
const char *mdp_errmsg;
64+
const char *mdp_parse_errmsg;
6565
};
6666

6767
static int proto_send(mdata_proto_t *mdp);
@@ -151,6 +151,7 @@ proto_parse_v2(mdata_proto_t *mdp, string_t *input, string_t *request_id,
151151
string_t *command, string_t *response_data)
152152
{
153153
const char *endp = dynstr_cstr(input);
154+
char *endp2;
154155
unsigned long clen;
155156
uint32_t crc32;
156157

@@ -165,10 +166,11 @@ proto_parse_v2(mdata_proto_t *mdp, string_t *input, string_t *request_id,
165166
/*
166167
* Read Content Length:
167168
*/
168-
if ((clen = strtoul(endp, (char **) &endp, 10)) == 0) {
169+
if ((clen = strtoul(endp, &endp2, 10)) == 0) {
169170
mdp->mdp_parse_errmsg = "invalid content length";
170171
return (-1);
171172
}
173+
endp = endp2;
172174

173175
/*
174176
* Skip whitespace:
@@ -179,10 +181,11 @@ proto_parse_v2(mdata_proto_t *mdp, string_t *input, string_t *request_id,
179181
/*
180182
* Read CRC32 checksum:
181183
*/
182-
if ((crc32 = strtoul(endp, (char **) &endp, 16)) == 0) {
184+
if ((crc32 = strtoul(endp, &endp2, 16)) == 0) {
183185
mdp->mdp_parse_errmsg = "invalid crc32 in frame";
184186
return (-1);
185187
}
188+
endp = endp2;
186189

187190
/*
188191
* Skip whitespace:
@@ -571,7 +574,7 @@ proto_version(mdata_proto_t *mdp)
571574
}
572575

573576
int
574-
proto_init(mdata_proto_t **out, char **errmsg)
577+
proto_init(mdata_proto_t **out, const char **errmsg)
575578
{
576579
mdata_proto_t *mdp;
577580

Diff for: proto.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef enum mdata_response {
2121

2222
typedef struct mdata_proto mdata_proto_t;
2323

24-
int proto_init(mdata_proto_t **, char **);
24+
int proto_init(mdata_proto_t **, const char **);
2525
int proto_version(mdata_proto_t *);
2626
int proto_execute(mdata_proto_t *, const char *, const char *, mdata_response_t *,
2727
string_t **);

0 commit comments

Comments
 (0)