Skip to content

Commit 9fd068d

Browse files
committed
Fix: add const to tmp in parse_port_of_addr
This is required because addr is const and addr is being assigned to tmp via strrchr. As a result parse_port_of_addr also needs to return a const, and the test vars need to be const.
1 parent 848bc46 commit 9fd068d

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

util/kb.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ redis_release_db (struct kb_redis *kbr)
246246
return rc;
247247
}
248248

249-
static inline char *
249+
static inline const char *
250250
parse_port_of_addr (const char *addr, int tcp_indicator_len)
251251
{
252-
char *tmp;
252+
const char *tmp;
253253
int is_ip_v6;
254254
tmp = strrchr (addr + tcp_indicator_len, ':');
255255
if (tmp == NULL)
@@ -268,7 +268,8 @@ connect_redis (const char *addr, int len)
268268
const int redis_default_port = 6379;
269269

270270
int port, host_len;
271-
char *tmp, *host;
271+
const char *tmp;
272+
char *host;
272273
redisContext *result;
273274
static int warn_flag = 0;
274275

util/kb_tests.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AfterEach (kb)
2626

2727
Ensure (kb, parse_port_of_addr)
2828
{
29-
char *addr, *port;
29+
const char *addr, *port;
3030

3131
addr = TCP "xxx:5";
3232
port = parse_port_of_addr (addr, strlen (TCP));
@@ -35,7 +35,7 @@ Ensure (kb, parse_port_of_addr)
3535

3636
Ensure (kb, parse_port_of_addr_missing)
3737
{
38-
char *addr, *port;
38+
const char *addr, *port;
3939

4040
addr = TCP "xxx";
4141
port = parse_port_of_addr (addr, strlen (TCP));
@@ -44,7 +44,7 @@ Ensure (kb, parse_port_of_addr_missing)
4444

4545
Ensure (kb, parse_port_of_addr_v6)
4646
{
47-
char *addr, *port;
47+
const char *addr, *port;
4848

4949
addr = TCP "[2001:db8::1]:8080";
5050
port = parse_port_of_addr (addr, strlen (TCP));

0 commit comments

Comments
 (0)