Skip to content

Commit 5f2dbe9

Browse files
committed
Update .clang-format for Clang 13.0
1 parent 778f33f commit 5f2dbe9

15 files changed

+54
-47
lines changed

.clang-format

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Configuration for clang-format automated reformatting. -*- yaml -*-
22
#
3+
# This configuration requires Clang 13.0 or later.
4+
#
35
# The canonical version of this file is maintained in the rra-c-util package,
46
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
57
#
@@ -15,7 +17,8 @@
1517
---
1618
Language: Cpp
1719
BasedOnStyle: LLVM
18-
AlignConsecutiveMacros: true
20+
AlignArrayOfStructures: Left
21+
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
1922
AlignEscapedNewlines: Left
2023
AllowShortEnumsOnASingleLine: false
2124
AlwaysBreakAfterReturnType: AllDefinitions
@@ -28,3 +31,20 @@ IndentWrappedFunctionNames: false
2831
MaxEmptyLinesToKeep: 2
2932
SpaceAfterCStyleCast: true
3033
---
34+
35+
# Additional formatting options that we would like to use but cannot (at least
36+
# yet):
37+
#
38+
# PPIndentWidth: 1
39+
# Better indentation of #if blocks, but unfortunately in Clang 13.0 this
40+
# indentation is also applied to code in #define macros, so produces:
41+
#
42+
# #define ENTRY(args, flags) \
43+
# do { \
44+
# if (args->debug) \
45+
# putil_log_entry((args), __func__, (flags)); \
46+
# } while (0)
47+
#
48+
# Should be used as soon as there is a way to distinguish between
49+
# identation of the preprocessor directives themselves and the code blocks
50+
# in #define.

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ rra-c-util 10.1 (unreleased)
99
aligned should use the magical #<<< comments. The default alignment
1010
is much too aggressive and makes the formatting unstable.
1111

12+
Update .clang-format for Clang 13.0.
13+
1214
rra-c-util 10.0 (2021-10-17)
1315

1416
Remove the RRA_SET_LIBDIR macro. I believe it was only used for PAM

pam-util/logging.c

-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static const struct {
6161
int flag;
6262
const char *name;
6363
} FLAGS[] = {
64-
/* clang-format off */
6564
{PAM_CHANGE_EXPIRED_AUTHTOK, "expired" },
6665
{PAM_DELETE_CRED, "delete" },
6766
{PAM_DISALLOW_NULL_AUTHTOK, "nonull" },
@@ -71,7 +70,6 @@ static const struct {
7170
{PAM_REINITIALIZE_CRED, "reinit" },
7271
{PAM_SILENT, "silent" },
7372
{PAM_UPDATE_AUTHTOK, "update" },
74-
/* clang-format on */
7573
};
7674

7775

pam-util/options.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ option_compare(const void *key, const void *member)
493493
if (p == NULL)
494494
return strcmp(string, option->name);
495495
else {
496-
length = (size_t)(p - string);
496+
length = (size_t) (p - string);
497497
if (length == 0)
498498
return -1;
499499
result = strncmp(string, option->name, length);

pam-util/vector.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ vector_split_multi(const char *string, const char *seps, struct vector *vector)
231231
for (start = string, p = string, i = 0; *p != '\0'; p++)
232232
if (strchr(seps, *p) != NULL) {
233233
if (start != p) {
234-
vector->strings[i] = strndup(start, (size_t)(p - start));
234+
vector->strings[i] = strndup(start, (size_t) (p - start));
235235
if (vector->strings[i] == NULL)
236236
goto fail;
237237
i++;
@@ -240,7 +240,7 @@ vector_split_multi(const char *string, const char *seps, struct vector *vector)
240240
start = p + 1;
241241
}
242242
if (start != p) {
243-
vector->strings[i] = strndup(start, (size_t)(p - start));
243+
vector->strings[i] = strndup(start, (size_t) (p - start));
244244
if (vector->strings[i] == NULL)
245245
goto fail;
246246
vector->count++;

portable/getaddrinfo.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ struct addrinfo {
6262
# define AI_ADDRCONFIG 0x0040
6363

6464
/* Error return codes from RFC 3493. */
65-
# define EAI_AGAIN 1 /* Temporary name resolution failure */
66-
# define EAI_BADFLAGS 2 /* Invalid value in ai_flags parameter */
67-
# define EAI_FAIL 3 /* Permanent name resolution failure */
68-
# define EAI_FAMILY 4 /* Address family not recognized */
69-
# define EAI_MEMORY 5 /* Memory allocation failure */
70-
# define EAI_NONAME 6 /* nodename or servname unknown */
71-
# define EAI_SERVICE 7 /* Service not recognized for socket type */
72-
# define EAI_SOCKTYPE 8 /* Socket type not recognized */
73-
# define EAI_SYSTEM 9 /* System error occurred, see errno */
74-
# define EAI_OVERFLOW 10 /* An argument buffer overflowed */
65+
# define EAI_AGAIN 1 /* Temporary name resolution failure */
66+
# define EAI_BADFLAGS 2 /* Invalid value in ai_flags parameter */
67+
# define EAI_FAIL 3 /* Permanent name resolution failure */
68+
# define EAI_FAMILY 4 /* Address family not recognized */
69+
# define EAI_MEMORY 5 /* Memory allocation failure */
70+
# define EAI_NONAME 6 /* nodename or servname unknown */
71+
# define EAI_SERVICE 7 /* Service not recognized for socket type */
72+
# define EAI_SOCKTYPE 8 /* Socket type not recognized */
73+
# define EAI_SYSTEM 9 /* System error occurred, see errno */
74+
# define EAI_OVERFLOW 10 /* An argument buffer overflowed */
7575

7676
BEGIN_DECLS
7777

portable/strndup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ strndup(const char *s, size_t n)
4444
}
4545

4646
/* Don't assume that the source string is nul-terminated. */
47-
for (p = s; (size_t)(p - s) < n && *p != '\0'; p++)
47+
for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
4848
;
4949
length = p - s;
5050
copy = malloc(length + 1);

portable/winsock.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ socket_init(void)
4545
* over sys_nerr). Try to use FormatMessage with a local static variable
4646
* instead.
4747
*/
48-
const char *socket_strerror(err)
48+
const char *
49+
socket_strerror(err)
4950
{
5051
const char *message = NULL;
5152

tests/fakepam/config.c

-12
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,19 @@ static const struct {
5959
pam_call call;
6060
enum group_type group;
6161
} CALLS[] = {
62-
/* clang-format off */
6362
{"acct_mgmt", pam_sm_acct_mgmt, GROUP_ACCOUNT },
6463
{"authenticate", pam_sm_authenticate, GROUP_AUTH },
6564
{"setcred", pam_sm_setcred, GROUP_AUTH },
6665
{"chauthtok", pam_sm_chauthtok, GROUP_PASSWORD},
6766
{"open_session", pam_sm_open_session, GROUP_SESSION },
6867
{"close_session", pam_sm_close_session, GROUP_SESSION },
69-
/* clang-format on */
7068
};
7169

7270
/* Mapping of PAM flag names without the leading PAM_ to values. */
7371
static const struct {
7472
const char *name;
7573
int value;
7674
} FLAGS[] = {
77-
/* clang-format off */
7875
{"CHANGE_EXPIRED_AUTHTOK", PAM_CHANGE_EXPIRED_AUTHTOK},
7976
{"DELETE_CRED", PAM_DELETE_CRED },
8077
{"DISALLOW_NULL_AUTHTOK", PAM_DISALLOW_NULL_AUTHTOK },
@@ -84,28 +81,24 @@ static const struct {
8481
{"REINITIALIZE_CRED", PAM_REINITIALIZE_CRED },
8582
{"SILENT", PAM_SILENT },
8683
{"UPDATE_AUTHTOK", PAM_UPDATE_AUTHTOK },
87-
/* clang-format on */
8884
};
8985

9086
/* Mapping of strings to PAM groups. */
9187
static const struct {
9288
const char *name;
9389
enum group_type group;
9490
} GROUPS[] = {
95-
/* clang-format off */
9691
{"account", GROUP_ACCOUNT },
9792
{"auth", GROUP_AUTH },
9893
{"password", GROUP_PASSWORD},
9994
{"session", GROUP_SESSION },
100-
/* clang-format on */
10195
};
10296

10397
/* Mapping of strings to PAM return values. */
10498
static const struct {
10599
const char *name;
106100
int status;
107101
} RETURNS[] = {
108-
/* clang-format off */
109102
{"PAM_AUTH_ERR", PAM_AUTH_ERR },
110103
{"PAM_AUTHINFO_UNAVAIL", PAM_AUTHINFO_UNAVAIL},
111104
{"PAM_AUTHTOK_ERR", PAM_AUTHTOK_ERR },
@@ -115,34 +108,29 @@ static const struct {
115108
{"PAM_SESSION_ERR", PAM_SESSION_ERR },
116109
{"PAM_SUCCESS", PAM_SUCCESS },
117110
{"PAM_USER_UNKNOWN", PAM_USER_UNKNOWN },
118-
/* clang-format on */
119111
};
120112

121113
/* Mapping of PAM prompt styles to their values. */
122114
static const struct {
123115
const char *name;
124116
int style;
125117
} STYLES[] = {
126-
/* clang-format off */
127118
{"echo_off", PAM_PROMPT_ECHO_OFF},
128119
{"echo_on", PAM_PROMPT_ECHO_ON },
129120
{"error_msg", PAM_ERROR_MSG },
130121
{"info", PAM_TEXT_INFO },
131-
/* clang-format on */
132122
};
133123

134124
/* Mappings of strings to syslog priorities. */
135125
static const struct {
136126
const char *name;
137127
int priority;
138128
} PRIORITIES[] = {
139-
/* clang-format off */
140129
{"DEBUG", LOG_DEBUG },
141130
{"INFO", LOG_INFO },
142131
{"NOTICE", LOG_NOTICE},
143132
{"ERR", LOG_ERR },
144133
{"CRIT", LOG_CRIT },
145-
/* clang-format on */
146134
};
147135

148136

tests/pam-util/options-t.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ struct pam_config {
6161

6262
/* The rules specifying the configuration options. */
6363
static struct option options[] = {
64-
/* clang-format off */
65-
{ K(cells), true, LIST (NULL) },
66-
{ K(debug), true, BOOL (false) },
67-
{ K(expires), true, TIME (10) },
68-
{ K(ignore_root), false, BOOL (true) },
69-
{ K(minimum_uid), true, NUMBER (0) },
70-
{ K(program), true, STRING (NULL) },
71-
/* clang-format on */
64+
{K(cells), true, LIST(NULL) },
65+
{K(debug), true, BOOL(false) },
66+
{K(expires), true, TIME(10) },
67+
{K(ignore_root), false, BOOL(true) },
68+
{K(minimum_uid), true, NUMBER(0) },
69+
{K(program), true, STRING(NULL)},
7270
};
7371
static const size_t optlen = sizeof(options) / sizeof(options[0]);
7472

tests/runtests.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ x_strndup(const char *s, size_t size, const char *file, int line)
446446
char *copy;
447447

448448
/* Don't assume that the source string is nul-terminated. */
449-
for (p = s; (size_t)(p - s) < size && *p != '\0'; p++)
449+
for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
450450
;
451-
len = (size_t)(p - s);
451+
len = (size_t) (p - s);
452452
copy = (char *) malloc(len + 1);
453453
if (copy == NULL)
454454
sysdie("failed to strndup %lu bytes at %s line %d",

tests/tap/basic.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,9 @@ bstrndup(const char *s, size_t n)
899899
size_t length;
900900

901901
/* Don't assume that the source string is nul-terminated. */
902-
for (p = s; (size_t)(p - s) < n && *p != '\0'; p++)
902+
for (p = s; (size_t) (p - s) < n && *p != '\0'; p++)
903903
;
904-
length = (size_t)(p - s);
904+
length = (size_t) (p - s);
905905
copy = (char *) malloc(length + 1);
906906
if (copy == NULL)
907907
sysbail("failed to strndup %lu bytes", (unsigned long) length);

tests/util/fakewrite.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fake_pwrite(int fd UNUSED, const void *data, size_t n, off_t offset)
102102
errno = ENOSPC;
103103
return -1;
104104
}
105-
if ((size_t)(256 - offset) < total)
105+
if ((size_t) (256 - offset) < total)
106106
total = 256 - offset;
107107
memcpy(write_buffer + offset, data, total);
108108
return total;

util/macros.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
#define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)])
3333

3434
/* Used to name the elements of the array passed to pipe. */
35-
#define PIPE_READ 0
36-
#define PIPE_WRITE 1
35+
#define PIPE_READ 0
36+
#define PIPE_WRITE 1
3737

3838
/* Used for unused parameters to silence gcc warnings. */
39-
#define UNUSED __attribute__((__unused__))
39+
#define UNUSED __attribute__((__unused__))
4040

4141
#endif /* UTIL_MACROS_H */

util/xmalloc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ x_strndup(const char *s, size_t size, const char *file, int line)
202202
char *copy;
203203

204204
/* Don't assume that the source string is nul-terminated. */
205-
for (p = s; (size_t)(p - s) < size && *p != '\0'; p++)
205+
for (p = s; (size_t) (p - s) < size && *p != '\0'; p++)
206206
;
207207
length = p - s;
208208
copy = malloc(length + 1);

0 commit comments

Comments
 (0)