Skip to content

Commit 3a7daca

Browse files
authored
Merge pull request #172 from keszybz/silence-warning
Silence warnings
2 parents 4982d8d + e528de6 commit 3a7daca

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/systemd/pyutil.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
#pragma once
44

55
#define PY_SSIZE_T_CLEAN
6-
#include <Python.h>
6+
/* Work around bug in Python.h:
7+
* it tries to redefine defines already defined by /usr/include/features.h,
8+
* without calling #undef first, causing a warning to be emitted.
9+
* (https://github.com/python/cpython/issues/61322). */
10+
#undef _POSIX_C_SOURCE
11+
#undef _XOPEN_SOURCE
12+
# include <Python.h>
13+
#undef _POSIX_C_SOURCE
14+
#undef _XOPEN_SOURCE
15+
#define _XOPEN_SOURCE 800
16+
#define _POSIX_C_SOURCE 202405L
717

818
void cleanup_Py_DECREFp(PyObject **p);
919
PyObject* absolute_timeout(uint64_t t);

src/systemd/util.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,16 @@ static int assign_address(const char *s,
9494

9595
int parse_sockaddr(const char *s,
9696
union sockaddr_union *addr, unsigned *addr_len) {
97-
98-
char *e, *n;
99-
unsigned u;
10097
int r;
10198

10299
if (*s == '[') {
103100
/* IPv6 in [x:.....:z]:p notation */
104101

105-
e = strchr(s+1, ']');
102+
const char *e = strchr(s + 1, ']');
106103
if (!e)
107104
return -EINVAL;
108105

109-
n = strndupa(s+1, e-s-1);
106+
char *n = strndupa(s+1, e-s-1);
110107

111108
errno = 0;
112109
if (inet_pton(AF_INET6, n, &addr->in6.sin6_addr) <= 0)
@@ -116,8 +113,9 @@ int parse_sockaddr(const char *s,
116113
if (*e) {
117114
if (*e != ':')
118115
return -EINVAL;
119-
120116
e++;
117+
118+
unsigned u;
121119
r = safe_atou(e, &u);
122120
if (r < 0)
123121
return r;
@@ -132,19 +130,21 @@ int parse_sockaddr(const char *s,
132130
*addr_len = sizeof(struct sockaddr_in6);
133131

134132
} else {
135-
e = strchr(s, ':');
133+
const char *e = strchr(s, ':');
136134
if (e) {
137-
r = safe_atou(e+1, &u);
135+
unsigned u;
136+
r = safe_atou(e + 1, &u);
138137
if (r < 0)
139138
return r;
140139

141140
if (u <= 0 || u > 0xFFFF)
142141
return -EINVAL;
143142

144-
n = strndupa(s, e-s);
143+
char *n = strndupa(s, e-s);
145144
return assign_address(n, u, addr, addr_len);
146145

147146
} else {
147+
unsigned u;
148148
r = safe_atou(s, &u);
149149
if (r < 0)
150150
return assign_address(s, 0, addr, addr_len);

0 commit comments

Comments
 (0)