summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/CODING_STYLE.md8
-rw-r--r--meson.build6
-rw-r--r--src/basic/escape.c6
-rw-r--r--src/basic/hexdecoct.c3
-rw-r--r--src/basic/missing_threads.h2
-rw-r--r--src/test/test-escape.c2
-rw-r--r--src/test/test-hexdecoct.c4
7 files changed, 20 insertions, 11 deletions
diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md
index 48fa4b093d..b8b420c142 100644
--- a/docs/CODING_STYLE.md
+++ b/docs/CODING_STYLE.md
@@ -151,16 +151,16 @@ SPDX-License-Identifier: LGPL-2.1-or-later
## Code Organization and Semantics
-- For our codebase we intend to use ISO C11 *with* GNU extensions (aka
- "gnu11"). Public APIs (i.e. those we expose via `libsystemd.so`
+- For our codebase we intend to use ISO C17 *with* GNU extensions (aka
+ "gnu17"). Public APIs (i.e. those we expose via `libsystemd.so`
i.e. `systemd/sd-*.h`) should only use ISO C89 however (with a very limited
set of conservative and common extensions, such as fixed size integer types
- from `<inttypes.h>`), so that we don't force consuming programs into C11
+ from `<inttypes.h>`), so that we don't force consuming programs into C17
mode. (This discrepancy in particular means one thing: internally we use C99
`bool` booleans, externally C89-compatible `int` booleans which generally
have different size in memory and slightly different semantics, also see
below.) Both for internal and external code it's OK to use even newer
- features and GCC extension than "gnu11", as long as there's reasonable
+ features and GCC extension than "gnu17", as long as there's reasonable
fallback #ifdeffery in place to ensure compatibility is retained with older
compilers.
diff --git a/meson.build b/meson.build
index 617d6d2452..d567f25566 100644
--- a/meson.build
+++ b/meson.build
@@ -4,7 +4,7 @@ project('systemd', 'c',
version : files('meson.version'),
license : 'LGPLv2+',
default_options: [
- 'c_std=gnu11',
+ 'c_std=gnu17',
'prefix=/usr',
'sysconfdir=/etc',
'localstatedir=/var',
@@ -1761,7 +1761,7 @@ python_39 = python.language_version().version_compare('>=3.9')
if conf.get('BPF_FRAMEWORK') == 1
bpf_clang_flags = [
- '-std=gnu11',
+ '-std=gnu17',
'-Wno-compare-distinct-pointer-types',
'-fno-stack-protector',
'-O2',
@@ -1772,7 +1772,7 @@ if conf.get('BPF_FRAMEWORK') == 1
]
bpf_gcc_flags = [
- '-std=gnu11',
+ '-std=gnu17',
'-fno-stack-protector',
'-fno-ssa-phiopt',
'-O2',
diff --git a/src/basic/escape.c b/src/basic/escape.c
index 2067be4092..e50ae68cc6 100644
--- a/src/basic/escape.c
+++ b/src/basic/escape.c
@@ -365,6 +365,8 @@ char* xescape_full(const char *s, const char *bad, size_t console_width, XEscape
char *ans, *t, *prev, *prev2;
const char *f;
+ assert(s);
+
/* Escapes all chars in bad, in addition to \ and all special chars, in \xFF style escaping. May be
* reversed with cunescape(). If XESCAPE_8_BIT is specified, characters >= 127 are let through
* unchanged. This corresponds to non-ASCII printable characters in pre-unicode encodings.
@@ -397,7 +399,7 @@ char* xescape_full(const char *s, const char *bad, size_t console_width, XEscape
if ((unsigned char) *f < ' ' ||
(!FLAGS_SET(flags, XESCAPE_8_BIT) && (unsigned char) *f >= 127) ||
- *f == '\\' || strchr(bad, *f)) {
+ *f == '\\' || (bad && strchr(bad, *f))) {
if ((size_t) (t - ans) + 4 + 3 * force_ellipsis > console_width)
break;
@@ -437,7 +439,7 @@ char* xescape_full(const char *s, const char *bad, size_t console_width, XEscape
char* escape_non_printable_full(const char *str, size_t console_width, XEscapeFlags flags) {
if (FLAGS_SET(flags, XESCAPE_8_BIT))
- return xescape_full(str, "", console_width, flags);
+ return xescape_full(str, /* bad= */ NULL, console_width, flags);
else
return utf8_escape_non_printable_full(str,
console_width,
diff --git a/src/basic/hexdecoct.c b/src/basic/hexdecoct.c
index 79e4959be7..1d8e60330c 100644
--- a/src/basic/hexdecoct.c
+++ b/src/basic/hexdecoct.c
@@ -866,6 +866,9 @@ void hexdump(FILE *f, const void *p, size_t s) {
assert(b || s == 0);
+ if (s == SIZE_MAX)
+ s = strlen(p);
+
if (!f)
f = stdout;
diff --git a/src/basic/missing_threads.h b/src/basic/missing_threads.h
index d48e05d586..c7da1dbd5e 100644
--- a/src/basic/missing_threads.h
+++ b/src/basic/missing_threads.h
@@ -5,7 +5,7 @@
#if HAVE_THREADS_H
# include <threads.h>
#elif !(defined(thread_local))
-# if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__))
+# ifndef __STDC_NO_THREADS__
# define thread_local _Thread_local
# else
# define thread_local __thread
diff --git a/src/test/test-escape.c b/src/test/test-escape.c
index 89a25febb4..7021ff54d2 100644
--- a/src/test/test-escape.c
+++ b/src/test/test-escape.c
@@ -15,7 +15,7 @@ TEST(cescape) {
TEST(xescape) {
_cleanup_free_ char *t = NULL;
- assert_se(t = xescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313", ""));
+ assert_se(t = xescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313", /* bad= */ NULL));
ASSERT_STREQ(t, "abc\\x5c\"\\x08\\x0c\\x0a\\x0d\\x09\\x0b\\x07\\x03\\x7f\\x9c\\xcb");
}
diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c
index 5c39fc7cc2..e5121d148e 100644
--- a/src/test/test-hexdecoct.c
+++ b/src/test/test-hexdecoct.c
@@ -503,11 +503,15 @@ TEST(hexdump) {
hexdump(stdout, NULL, 0);
hexdump(stdout, "", 0);
+ hexdump(stdout, "", SIZE_MAX);
hexdump(stdout, "", 1);
hexdump(stdout, "x", 1);
+ hexdump(stdout, "x", SIZE_MAX);
hexdump(stdout, "x", 2);
hexdump(stdout, "foobar", 7);
+ hexdump(stdout, "foobar", SIZE_MAX);
hexdump(stdout, "f\nobar", 7);
+ hexdump(stdout, "f\nobar", SIZE_MAX);
hexdump(stdout, "xxxxxxxxxxxxxxxxxxxxyz", 23);
for (i = 0; i < ELEMENTSOF(data); i++)