1
0
mirror of https://github.com/systemd/systemd synced 2026-03-28 09:44:50 +01:00

Compare commits

..

No commits in common. "940e26c19c84c8b4fb01edb3439196cc53234b2b" and "53405835a2aa6e360863660f1e0e4d9a9688085f" have entirely different histories.

29 changed files with 91 additions and 111 deletions

View File

@ -23,7 +23,7 @@
#include "virt.h" #include "virt.h"
static int parse_chid_type(const char *s, size_t *ret) { static int parse_chid_type(const char *s, size_t *ret) {
const char *e; char *e;
unsigned u; unsigned u;
int r; int r;

View File

@ -163,7 +163,9 @@ int proc_cmdline_strv(char ***ret) {
} }
static char *mangle_word(const char *word, ProcCmdlineFlags flags) { static char *mangle_word(const char *word, ProcCmdlineFlags flags) {
char *c = (char*) startswith(word, "rd."); char *c;
c = startswith(word, "rd.");
if (c) { if (c) {
/* Filter out arguments that are intended only for the initrd */ /* Filter out arguments that are intended only for the initrd */
@ -180,8 +182,6 @@ static char *mangle_word(const char *word, ProcCmdlineFlags flags) {
return (char*) word; return (char*) word;
} }
#define mangle_word(word, flags) const_generic(word, mangle_word(word, flags))
static int proc_cmdline_parse_strv(char **args, proc_cmdline_parse_t parse_item, void *data, ProcCmdlineFlags flags) { static int proc_cmdline_parse_strv(char **args, proc_cmdline_parse_t parse_item, void *data, ProcCmdlineFlags flags) {
int r; int r;

View File

@ -1869,7 +1869,7 @@ int vsock_parse_cid(const char *s, unsigned *ret) {
int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) { int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) {
/* AF_VSOCK socket in vsock:cid:port notation */ /* AF_VSOCK socket in vsock:cid:port notation */
_cleanup_free_ char *n = NULL; _cleanup_free_ char *n = NULL;
const char *e, *cid_start; char *e, *cid_start;
unsigned port, cid; unsigned port, cid;
int type, r; int type, r;

View File

@ -30,7 +30,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
return NULL; return NULL;
} }
void* bsearch_safe_internal(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar) { void* bsearch_safe(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
/** /**
* Normal bsearch requires base to be nonnull. Here were require * Normal bsearch requires base to be nonnull. Here were require
* that only if nmemb > 0. * that only if nmemb > 0.
@ -40,7 +40,7 @@ void* bsearch_safe_internal(const void *key, const void *base, size_t nmemb, siz
return NULL; return NULL;
assert(base); assert(base);
return (void*) bsearch(key, base, nmemb, size, compar); return bsearch(key, base, nmemb, size, compar);
} }
void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) { void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {

View File

@ -13,9 +13,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
(typeof((b)[0])*) xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \ (typeof((b)[0])*) xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
}) })
void* bsearch_safe_internal(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar); void* bsearch_safe(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar);
#define bsearch_safe(key, base, nmemb, size, compar) \
const_generic((base), bsearch_safe_internal(key, base, nmemb, size, compar))
#define typesafe_bsearch(k, b, n, func) \ #define typesafe_bsearch(k, b, n, func) \
({ \ ({ \

View File

@ -1339,14 +1339,16 @@ char* strdupcspn(const char *a, const char *reject) {
return strndup(a, strcspn(a, reject)); return strndup(a, strcspn(a, reject));
} }
char* find_line_startswith_internal(const char *haystack, const char *needle) { char* find_line_startswith(const char *haystack, const char *needle) {
char *p;
assert(haystack); assert(haystack);
assert(needle); assert(needle);
/* Finds the first line in 'haystack' that starts with the specified string. Returns a pointer to the /* Finds the first line in 'haystack' that starts with the specified string. Returns a pointer to the
* first character after it */ * first character after it */
char *p = (char*) strstr(haystack, needle); p = strstr(haystack, needle);
if (!p) if (!p)
return NULL; return NULL;
@ -1360,14 +1362,16 @@ char* find_line_startswith_internal(const char *haystack, const char *needle) {
return p + strlen(needle); return p + strlen(needle);
} }
char* find_line_internal(const char *haystack, const char *needle) { char* find_line(const char *haystack, const char *needle) {
char *p;
assert(haystack); assert(haystack);
assert(needle); assert(needle);
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the /* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
* beginning of the line */ * beginning of the line */
char *p = (char*) find_line_startswith(haystack, needle); p = find_line_startswith(haystack, needle);
if (!p) if (!p)
return NULL; return NULL;
@ -1377,14 +1381,16 @@ char* find_line_internal(const char *haystack, const char *needle) {
return NULL; return NULL;
} }
char* find_line_after_internal(const char *haystack, const char *needle) { char* find_line_after(const char *haystack, const char *needle) {
char *p;
assert(haystack); assert(haystack);
assert(needle); assert(needle);
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the /* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
* next line after it */ * next line after it */
char *p = (char*) find_line_startswith(haystack, needle); p = find_line_startswith(haystack, needle);
if (!p) if (!p)
return NULL; return NULL;
@ -1484,7 +1490,7 @@ ssize_t strlevenshtein(const char *x, const char *y) {
return t1[yl]; return t1[yl];
} }
char* strrstr_internal(const char *haystack, const char *needle) { char* strrstr(const char *haystack, const char *needle) {
/* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */ /* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */
if (!haystack || !needle) if (!haystack || !needle)
@ -1493,7 +1499,7 @@ char* strrstr_internal(const char *haystack, const char *needle) {
/* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the /* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
* last char, not before. */ * last char, not before. */
if (*needle == 0) if (*needle == 0)
return (char*) strchr(haystack, 0); return strchr(haystack, 0);
for (const char *p = strstr(haystack, needle), *q; p; p = q) { for (const char *p = strstr(haystack, needle), *q; p; p = q) {
q = strstr(p + 1, needle); q = strstr(p + 1, needle);

View File

@ -7,28 +7,24 @@
#include "forward.h" #include "forward.h"
#include "string-util-fundamental.h" /* IWYU pragma: export */ #include "string-util-fundamental.h" /* IWYU pragma: export */
static inline char* strstr_ptr_internal(const char *haystack, const char *needle) { static inline char* strstr_ptr(const char *haystack, const char *needle) {
if (!haystack || !needle) if (!haystack || !needle)
return NULL; return NULL;
return (char*) strstr(haystack, needle); return strstr(haystack, needle);
} }
#define strstr_ptr(haystack, needle) \ static inline char* strstrafter(const char *haystack, const char *needle) {
const_generic(haystack, strstr_ptr_internal(haystack, needle)) char *p;
static inline char* strstrafter_internal(const char *haystack, const char *needle) {
/* Returns NULL if not found, or pointer to first character after needle if found */ /* Returns NULL if not found, or pointer to first character after needle if found */
char *p = (char*) strstr_ptr(haystack, needle); p = strstr_ptr(haystack, needle);
if (!p) if (!p)
return NULL; return NULL;
return p + strlen(needle); return p + strlen(needle);
} }
#define strstrafter(haystack, needle) \
const_generic(haystack, strstrafter_internal(haystack, needle))
static inline const char* strnull(const char *s) { static inline const char* strnull(const char *s) {
return s ?: "(null)"; return s ?: "(null)";
} }
@ -290,25 +286,15 @@ char* strdupcspn(const char *a, const char *reject);
(char*) memdupa_suffix0(_t, strnlen(_t, n)); \ (char*) memdupa_suffix0(_t, strnlen(_t, n)); \
}) })
char* find_line_startswith_internal(const char *haystack, const char *needle); char* find_line_startswith(const char *haystack, const char *needle);
#define find_line_startswith(haystack, needle) \ char* find_line(const char *haystack, const char *needle);
const_generic(haystack, find_line_startswith_internal(haystack, needle)) char* find_line_after(const char *haystack, const char *needle);
char* find_line_internal(const char *haystack, const char *needle);
#define find_line(haystack, needle) \
const_generic(haystack, find_line_internal(haystack, needle))
char* find_line_after_internal(const char *haystack, const char *needle);
#define find_line_after(haystack, needle) \
const_generic(haystack, find_line_after_internal(haystack, needle))
bool version_is_valid(const char *s) _pure_; bool version_is_valid(const char *s) _pure_;
bool version_is_valid_versionspec(const char *s) _pure_; bool version_is_valid_versionspec(const char *s) _pure_;
ssize_t strlevenshtein(const char *x, const char *y); ssize_t strlevenshtein(const char *x, const char *y);
char* strrstr_internal(const char *haystack, const char *needle) _pure_; char* strrstr(const char *haystack, const char *needle) _pure_;
#define strrstr(haystack, needle) \
const_generic(haystack, strrstr_internal(haystack, needle))
size_t str_common_prefix(const char *a, const char *b) _pure_; size_t str_common_prefix(const char *a, const char *b) _pure_;

View File

@ -921,9 +921,9 @@ int strv_extendf(char ***l, const char *format, ...) {
return strv_consume(l, x); return strv_consume(l, x);
} }
char* startswith_strv_internal(const char *s, char * const *l) { char* startswith_strv(const char *s, char * const *l) {
STRV_FOREACH(i, l) { STRV_FOREACH(i, l) {
char *found = (char*) startswith(s, *i); char *found = startswith(s, *i);
if (found) if (found)
return found; return found;
} }
@ -931,9 +931,9 @@ char* startswith_strv_internal(const char *s, char * const *l) {
return NULL; return NULL;
} }
char* endswith_strv_internal(const char *s, char * const *l) { char* endswith_strv(const char *s, char * const *l) {
STRV_FOREACH(i, l) { STRV_FOREACH(i, l) {
char *found = (char*) endswith(s, *i); char *found = endswith(s, *i);
if (found) if (found)
return found; return found;
} }

View File

@ -150,14 +150,12 @@ static inline void strv_print(char * const *l) {
strv_print_full(l, NULL); strv_print_full(l, NULL);
} }
char* startswith_strv_internal(const char *s, char * const *l); char* startswith_strv(const char *s, char * const *l);
#define startswith_strv(s, l) const_generic(s, startswith_strv_internal(s, l))
#define STARTSWITH_SET(p, ...) \ #define STARTSWITH_SET(p, ...) \
startswith_strv(p, STRV_MAKE(__VA_ARGS__)) startswith_strv(p, STRV_MAKE(__VA_ARGS__))
char* endswith_strv_internal(const char *s, char * const *l); char* endswith_strv(const char *s, char * const *l);
#define endswith_strv(s, l) const_generic(s, endswith_strv_internal(s, l))
#define ENDSWITH_SET(p, ...) \ #define ENDSWITH_SET(p, ...) \
endswith_strv(p, STRV_MAKE(__VA_ARGS__)) endswith_strv(p, STRV_MAKE(__VA_ARGS__))

View File

@ -1119,7 +1119,9 @@ static const char* extract_multiplier(const char *p, usec_t *ret) {
assert(ret); assert(ret);
FOREACH_ELEMENT(i, table) { FOREACH_ELEMENT(i, table) {
const char *e = startswith(p, i->suffix); char *e;
e = startswith(p, i->suffix);
if (e) { if (e) {
*ret = i->usec; *ret = i->usec;
return e; return e;
@ -1295,7 +1297,9 @@ static const char* extract_nsec_multiplier(const char *p, nsec_t *ret) {
assert(ret); assert(ret);
FOREACH_ELEMENT(i, table) { FOREACH_ELEMENT(i, table) {
const char *e = startswith(p, i->suffix); char *e;
e = startswith(p, i->suffix);
if (e) { if (e) {
*ret = i->nsec; *ret = i->nsec;
return e; return e;

View File

@ -213,7 +213,7 @@ UnitType unit_name_to_type(const char *n) {
int unit_name_change_suffix(const char *n, const char *suffix, char **ret) { int unit_name_change_suffix(const char *n, const char *suffix, char **ret) {
_cleanup_free_ char *s = NULL; _cleanup_free_ char *s = NULL;
size_t a, b; size_t a, b;
const char *e; char *e;
assert(n); assert(n);
assert(suffix); assert(suffix);
@ -521,7 +521,7 @@ int unit_name_template(const char *f, char **ret) {
} }
bool unit_name_is_hashed(const char *name) { bool unit_name_is_hashed(const char *name) {
const char *s; char *s;
if (!unit_name_is_valid(name, UNIT_NAME_PLAIN)) if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
return false; return false;
@ -544,7 +544,7 @@ bool unit_name_is_hashed(const char *name) {
int unit_name_hash_long(const char *name, char **ret) { int unit_name_hash_long(const char *name, char **ret) {
_cleanup_free_ char *n = NULL, *hash = NULL; _cleanup_free_ char *n = NULL, *hash = NULL;
const char *suffix; char *suffix;
le64_t h; le64_t h;
size_t len; size_t len;
@ -834,7 +834,7 @@ int slice_build_subslice(const char *slice, const char *name, char **ret) {
if (streq(slice, SPECIAL_ROOT_SLICE)) if (streq(slice, SPECIAL_ROOT_SLICE))
subslice = strjoin(name, ".slice"); subslice = strjoin(name, ".slice");
else { else {
const char *e; char *e;
assert_se(e = endswith(slice, ".slice")); assert_se(e = endswith(slice, ".slice"));

View File

@ -1024,7 +1024,6 @@ _used_ void *memcpy(void * restrict dest, const void * restrict src, size_t n);
_used_ void *memset(void *p, int c, size_t n); _used_ void *memset(void *p, int c, size_t n);
#else #else
/* And for userspace unit testing we need to give them an efi_ prefix. */ /* And for userspace unit testing we need to give them an efi_ prefix. */
# undef memchr
# define memchr efi_memchr # define memchr efi_memchr
# define memcmp efi_memcmp # define memcmp efi_memcmp
# define memcpy efi_memcpy # define memcpy efi_memcpy

View File

@ -2116,7 +2116,7 @@ static int build_environment(
} }
if (!sd_id128_is_null(p->invocation_id)) { if (!sd_id128_is_null(p->invocation_id)) {
assert(!isempty(p->invocation_id_string)); assert(p->invocation_id_string);
x = strjoin("INVOCATION_ID=", p->invocation_id_string); x = strjoin("INVOCATION_ID=", p->invocation_id_string);
if (!x) if (!x)

View File

@ -1778,7 +1778,7 @@ int config_parse_exec_root_hash_sig(
void *userdata) { void *userdata) {
_cleanup_free_ void *roothash_sig_decoded = NULL; _cleanup_free_ void *roothash_sig_decoded = NULL;
const char *value; char *value;
ExecContext *c = ASSERT_PTR(data); ExecContext *c = ASSERT_PTR(data);
size_t roothash_sig_decoded_size = 0; size_t roothash_sig_decoded_size = 0;
int r; int r;

View File

@ -798,9 +798,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
static int add_crypttab_device(const char *name, const char *device, const char *keyspec, const char *options) { static int add_crypttab_device(const char *name, const char *device, const char *keyspec, const char *options) {
_cleanup_free_ char *keyfile = NULL, *keydev = NULL, *headerdev = NULL, *filtered_header = NULL; _cleanup_free_ char *keyfile = NULL, *keydev = NULL, *headerdev = NULL, *filtered_header = NULL;
crypto_device *d = NULL; crypto_device *d = NULL;
char *uuid;
int r; int r;
const char *uuid = startswith(device, "UUID="); uuid = startswith(device, "UUID=");
if (!uuid) if (!uuid)
uuid = path_startswith(device, "/dev/disk/by-uuid/"); uuid = path_startswith(device, "/dev/disk/by-uuid/");
if (!uuid) if (!uuid)

View File

@ -482,10 +482,3 @@ assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1);
#else #else
# define ENUM_TYPE_S64(id) id # define ENUM_TYPE_S64(id) id
#endif #endif
/* This macro is used to have a const-returning and non-const returning version of a function based on
* whether its first argument is const or not (e.g. strstr()). */
#define const_generic(ptr, call) \
_Generic(0 ? (ptr) : (void*) 1, \
const void*: (const typeof(*call)*) (call), \
void*: (call))

View File

@ -3,7 +3,7 @@
#include "macro-fundamental.h" #include "macro-fundamental.h"
#include "string-util-fundamental.h" #include "string-util-fundamental.h"
sd_char *startswith_internal(const sd_char *s, const sd_char *prefix) { sd_char *startswith(const sd_char *s, const sd_char *prefix) {
size_t l; size_t l;
assert(s); assert(s);
@ -16,7 +16,7 @@ sd_char *startswith_internal(const sd_char *s, const sd_char *prefix) {
return (sd_char*) s + l; return (sd_char*) s + l;
} }
sd_char *startswith_no_case_internal(const sd_char *s, const sd_char *prefix) { sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
size_t l; size_t l;
assert(s); assert(s);
@ -29,7 +29,7 @@ sd_char *startswith_no_case_internal(const sd_char *s, const sd_char *prefix) {
return (sd_char*) s + l; return (sd_char*) s + l;
} }
sd_char* endswith_internal(const sd_char *s, const sd_char *suffix) { sd_char* endswith(const sd_char *s, const sd_char *suffix) {
size_t sl, pl; size_t sl, pl;
assert(s); assert(s);
@ -50,7 +50,7 @@ sd_char* endswith_internal(const sd_char *s, const sd_char *suffix) {
return (sd_char*) s + sl - pl; return (sd_char*) s + sl - pl;
} }
sd_char* endswith_no_case_internal(const sd_char *s, const sd_char *suffix) { sd_char* endswith_no_case(const sd_char *s, const sd_char *suffix) {
size_t sl, pl; size_t sl, pl;
assert(s); assert(s);

View File

@ -77,17 +77,10 @@ static inline size_t strlen_ptr(const sd_char *s) {
return strlen(s); return strlen(s);
} }
sd_char *startswith_internal(const sd_char *s, const sd_char *prefix) _pure_; sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_;
#define startswith(s, prefix) const_generic(s, startswith_internal(s, prefix)) sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
sd_char *endswith(const sd_char *s, const sd_char *suffix) _pure_;
sd_char *startswith_no_case_internal(const sd_char *s, const sd_char *prefix) _pure_; sd_char *endswith_no_case(const sd_char *s, const sd_char *suffix) _pure_;
#define startswith_no_case(s, prefix) const_generic(s, startswith_no_case_internal(s, prefix))
sd_char *endswith_internal(const sd_char *s, const sd_char *suffix) _pure_;
#define endswith(s, suffix) const_generic(s, endswith_internal(s, suffix))
sd_char *endswith_no_case_internal(const sd_char *s, const sd_char *suffix) _pure_;
#define endswith_no_case(s, suffix) const_generic(s, endswith_no_case_internal(s, suffix))
static inline bool isempty(const sd_char *a) { static inline bool isempty(const sd_char *a) {
return !a || a[0] == '\0'; return !a || a[0] == '\0';

View File

@ -861,7 +861,7 @@ static int manager_assess_image(
const char *dir_path, const char *dir_path,
const char *dentry_name) { const char *dentry_name) {
const char *luks_suffix, *directory_suffix; char *luks_suffix, *directory_suffix;
_cleanup_free_ char *path = NULL; _cleanup_free_ char *path = NULL;
struct stat st; struct stat st;
int r; int r;

View File

@ -151,8 +151,9 @@ int get_possible_units(
SD_JOURNAL_FOREACH_UNIQUE(j, data, size) { SD_JOURNAL_FOREACH_UNIQUE(j, data, size) {
_cleanup_free_ char *u = NULL; _cleanup_free_ char *u = NULL;
char *eq;
const char *eq = memchr(data, '=', size); eq = memchr(data, '=', size);
if (eq) { if (eq) {
size -= eq - (char*) data + 1; size -= eq - (char*) data + 1;
data = ++eq; data = ++eq;

View File

@ -1437,7 +1437,7 @@ _public_ int sd_bus_open_user(sd_bus **ret) {
int bus_set_address_system_remote(sd_bus *b, const char *host) { int bus_set_address_system_remote(sd_bus *b, const char *host) {
_cleanup_free_ char *e = NULL; _cleanup_free_ char *e = NULL;
const char *m = NULL, *c = NULL, *a, *rbracket = NULL, *p = NULL; char *m = NULL, *c = NULL, *a, *rbracket = NULL, *p = NULL;
assert(b); assert(b);
assert(host); assert(host);
@ -1475,7 +1475,7 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) {
/* Let's see if a port was given */ /* Let's see if a port was given */
m = strchr(rbracket ? rbracket + 1 : host, ':'); m = strchr(rbracket ? rbracket + 1 : host, ':');
if (m) { if (m) {
const char *t; char *t;
bool got_forward_slash = false; bool got_forward_slash = false;
p = m + 1; p = m + 1;
@ -1521,15 +1521,14 @@ interpret_port_as_machine_old_syntax:
if (!ssh_escaped) if (!ssh_escaped)
return -ENOMEM; return -ENOMEM;
char *address = strjoin( a = strjoin("unixexec:path=", ssh_escaped, ",argv1=-xT",
"unixexec:path=", ssh_escaped, ",argv1=-xT", p ? ",argv2=-p,argv3=" : "", strempty(p),
p ? ",argv2=-p,argv3=" : "", strempty(p), ",argv", p ? "4" : "2", "=--,argv", p ? "5" : "3", "=", e,
",argv", p ? "4" : "2", "=--,argv", p ? "5" : "3", "=", e, ",argv", p ? "6" : "4", "=systemd-stdio-bridge", c);
",argv", p ? "6" : "4", "=systemd-stdio-bridge", c); if (!a)
if (!address)
return -ENOMEM; return -ENOMEM;
return free_and_replace(b->address, address); return free_and_replace(b->address, a);
} }
_public_ int sd_bus_open_system_remote(sd_bus **ret, const char *host) { _public_ int sd_bus_open_system_remote(sd_bus **ret, const char *host) {

View File

@ -95,7 +95,7 @@ static int trie_children_cmp_f(const void *v1, const void *v2) {
} }
static const struct trie_node_f *node_lookup_f(sd_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) { static const struct trie_node_f *node_lookup_f(sd_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) {
const struct trie_child_entry_f *child; struct trie_child_entry_f *child;
struct trie_child_entry_f search; struct trie_child_entry_f search;
search.c = c; search.c = c;

View File

@ -210,21 +210,23 @@ static int finish_item(
} }
int catalog_file_lang(const char *filename, char **ret) { int catalog_file_lang(const char *filename, char **ret) {
char *beg, *end, *lang;
assert(filename); assert(filename);
assert(ret); assert(ret);
const char *end = endswith(filename, ".catalog"); end = endswith(filename, ".catalog");
if (!end) if (!end)
return 0; return 0;
const char *beg = end - 1; beg = end - 1;
while (beg > filename && !IN_SET(*beg, '.', '/') && end - beg < 32) while (beg > filename && !IN_SET(*beg, '.', '/') && end - beg < 32)
beg--; beg--;
if (*beg != '.' || end <= beg + 1) if (*beg != '.' || end <= beg + 1)
return 0; return 0;
char *lang = strndup(beg + 1, end - beg - 1); lang = strndup(beg + 1, end - beg - 1);
if (!lang) if (!lang)
return -ENOMEM; return -ENOMEM;
@ -551,8 +553,7 @@ static int open_mmap(const char *database, int *ret_fd, struct stat *ret_st, voi
} }
static const char* find_id(const void *p, sd_id128_t id) { static const char* find_id(const void *p, sd_id128_t id) {
CatalogItem key = { .id = id }; CatalogItem *f = NULL, key = { .id = id };
const CatalogItem *f = NULL;
const CatalogHeader *h = ASSERT_PTR(p); const CatalogHeader *h = ASSERT_PTR(p);
const char *loc; const char *loc;

View File

@ -786,6 +786,7 @@ int config_parse_dhcp_server_relay_agent_suboption(
void *userdata) { void *userdata) {
char **suboption_value = data; char **suboption_value = data;
char* p;
assert(filename); assert(filename);
assert(lvalue); assert(lvalue);
@ -796,7 +797,7 @@ int config_parse_dhcp_server_relay_agent_suboption(
return 0; return 0;
} }
const char *p = startswith(rvalue, "string:"); p = startswith(rvalue, "string:");
if (!p) { if (!p) {
log_syntax(unit, LOG_WARNING, filename, line, 0, log_syntax(unit, LOG_WARNING, filename, line, 0,
"Failed to parse %s=%s'. Invalid format, ignoring.", lvalue, rvalue); "Failed to parse %s=%s'. Invalid format, ignoring.", lvalue, rvalue);

View File

@ -1639,6 +1639,7 @@ static int bus_append_root_hash(sd_bus_message *m, const char *field, const char
} }
static int bus_append_root_hash_signature(sd_bus_message *m, const char *field, const char *eq) { static int bus_append_root_hash_signature(sd_bus_message *m, const char *field, const char *eq) {
char *value;
_cleanup_free_ void *roothash_sig_decoded = NULL; _cleanup_free_ void *roothash_sig_decoded = NULL;
size_t roothash_sig_decoded_size = 0; size_t roothash_sig_decoded_size = 0;
int r; int r;
@ -1647,8 +1648,7 @@ static int bus_append_root_hash_signature(sd_bus_message *m, const char *field,
if (path_is_absolute(eq)) if (path_is_absolute(eq))
return bus_append_string(m, "RootHashSignaturePath", eq); return bus_append_string(m, "RootHashSignaturePath", eq);
const char *value = startswith(eq, "base64:"); if (!(value = startswith(eq, "base64:")))
if (!value)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to decode %s value '%s': neither a path nor starts with 'base64:'.", "Failed to decode %s value '%s': neither a path nor starts with 'base64:'.",
field, eq); field, eq);

View File

@ -298,7 +298,7 @@ bool pager_have(void) {
int show_man_page(const char *desc, bool null_stdio) { int show_man_page(const char *desc, bool null_stdio) {
const char *args[4] = { "man", NULL, NULL, NULL }; const char *args[4] = { "man", NULL, NULL, NULL };
const char *e = NULL; char *e = NULL;
pid_t pid; pid_t pid;
size_t k; size_t k;
int r; int r;

View File

@ -2391,7 +2391,7 @@ uint32_t scmp_act_kill_process(void) {
int parse_syscall_and_errno(const char *in, char **name, int *error) { int parse_syscall_and_errno(const char *in, char **name, int *error) {
_cleanup_free_ char *n = NULL; _cleanup_free_ char *n = NULL;
const char *p; char *p;
int e = -1; int e = -1;
assert(in); assert(in);

View File

@ -343,7 +343,7 @@ static int make_choice(
unsigned found_tries_done = UINT_MAX, found_tries_left = UINT_MAX; unsigned found_tries_done = UINT_MAX, found_tries_left = UINT_MAX;
_cleanup_free_ char *dname = NULL; _cleanup_free_ char *dname = NULL;
size_t found_architecture_index = SIZE_MAX; size_t found_architecture_index = SIZE_MAX;
char *e; const char *e;
dname = strdup((*entry)->d_name); dname = strdup((*entry)->d_name);
if (!dname) if (!dname)

View File

@ -922,7 +922,7 @@ static int names_pci(UdevEvent *event, const char *prefix) {
} }
static int get_usb_specifier(sd_device *dev, char **ret) { static int get_usb_specifier(sd_device *dev, char **ret) {
char *ports, *config, *interf, *buf; char *ports, *config, *interf, *s, *buf;
const char *sysname; const char *sysname;
int r; int r;
@ -934,26 +934,26 @@ static int get_usb_specifier(sd_device *dev, char **ret) {
return log_device_debug_errno(dev, r, "Failed to get sysname: %m"); return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
/* get USB port number chain, configuration, interface */ /* get USB port number chain, configuration, interface */
const char *s = strchr(sysname, '-'); s = strchr(sysname, '-');
if (!s) if (!s)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
"sysname \"%s\" does not have '-' in the expected place.", sysname); "sysname \"%s\" does not have '-' in the expected place.", sysname);
ports = strdupa_safe(s + 1); ports = strdupa_safe(s + 1);
char *t = strchr(ports, ':'); s = strchr(ports, ':');
if (!s) if (!s)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
"sysname \"%s\" does not have ':' in the expected place.", sysname); "sysname \"%s\" does not have ':' in the expected place.", sysname);
*t = '\0'; *s = '\0';
config = t + 1; config = s + 1;
s = strchr(config, '.'); s = strchr(config, '.');
if (!s) if (!s)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
"sysname \"%s\" does not have '.' in the expected place.", sysname); "sysname \"%s\" does not have '.' in the expected place.", sysname);
*t = '\0'; *s = '\0';
interf = t + 1; interf = s + 1;
/* prefix every port number in the chain with "u" */ /* prefix every port number in the chain with "u" */
string_replace_char(ports, '.', 'u'); string_replace_char(ports, '.', 'u');