Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change .clang-format to apply linebreaks before open-braces #1423

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jonesmz
Copy link
Contributor

@jonesmz jonesmz commented Feb 1, 2024

This pull request changes the .clang-format file so that a newline is inserted before opening braces in the code.

This changes, for example

if (bool) {
} else {
}

to

if (bool)
{
}
else
{
}

This has multiple benefits.

  1. To find the matching brace for a particular line, you merely need to find the next brace that is indented to the same indentation level.
  2. Parameter lists that are currently broken into two lines can sometimes be kept to a single line.
  3. Provides a significant visual indicator about a scope beginning or ending, which for people with less than steller eyesight is a significant readability enhancement
  4. Provides consistency with scopes that are not attached to a conditional, which is used in several places related to goto labels.

AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting is to control whether the brace itself follows indentation, which i don't think anyone wants.

@@ -80,10 +80,11 @@ IncludeCategories:
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentGotoLabels: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto labels are important to be able to quickly identify. Having them left-aligned in the text helps provide that visual indication.

IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
IndentExternBlock: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many headers are wrapped with extern "C" blocks, don't indent the code found inside those.

extern int LLVMFuzzerTestOneInput(const uint8_t *Data,
size_t Size) { // rfc5769check
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{ // rfc5769check
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example of parameters previously on two lines being able to be on one line. Helps with readability of the function.

@@ -976,22 +1166,28 @@
* \param pnOutSize: size of char string
* \return
*/
wchar_t *_ATW(__in char *pszInBuf, __in int nInSize, __out wchar_t **pszOutBuf, __out int *pnOutSize) {
if (!pszInBuf || !pszOutBuf || !pnOutSize || nInSize <= 0) {
wchar_t *_ATW(__in char *pszInBuf, __in int nInSize, __out wchar_t **pszOutBuf, __out int *pnOutSize)

Check warning

Code scanning / PREfast

Returning uninitialized memory '*pszOutBuf'. A successful path through the function does not set the named Out parameter. Warning

Returning uninitialized memory '*pszOutBuf'. A successful path through the function does not set the named _Out_ parameter.
@@ -976,22 +1166,28 @@
* \param pnOutSize: size of char string
* \return
*/
wchar_t *_ATW(__in char *pszInBuf, __in int nInSize, __out wchar_t **pszOutBuf, __out int *pnOutSize) {
if (!pszInBuf || !pszOutBuf || !pnOutSize || nInSize <= 0) {
wchar_t *_ATW(__in char *pszInBuf, __in int nInSize, __out wchar_t **pszOutBuf, __out int *pnOutSize)

Check warning

Code scanning / PREfast

Returning uninitialized memory '*pnOutSize'. A successful path through the function does not set the named Out parameter. Warning

Returning uninitialized memory '*pnOutSize'. A successful path through the function does not set the named _Out_ parameter.
@@ -1005,21 +1201,27 @@
* \param pnOutSize: size of wchar string
* \return
*/
char *_WTA(__in wchar_t *pszInBuf, __in int nInSize, __out char **pszOutBuf, __out int *pnOutSize) {
if (!pszInBuf || !pszOutBuf || !pnOutSize || nInSize <= 0) {
char *_WTA(__in wchar_t *pszInBuf, __in int nInSize, __out char **pszOutBuf, __out int *pnOutSize)

Check warning

Code scanning / PREfast

Returning uninitialized memory '*pszOutBuf'. A successful path through the function does not set the named Out parameter. Warning

Returning uninitialized memory '*pszOutBuf'. A successful path through the function does not set the named _Out_ parameter.
@@ -1005,21 +1201,27 @@
* \param pnOutSize: size of wchar string
* \return
*/
char *_WTA(__in wchar_t *pszInBuf, __in int nInSize, __out char **pszOutBuf, __out int *pnOutSize) {
if (!pszInBuf || !pszOutBuf || !pnOutSize || nInSize <= 0) {
char *_WTA(__in wchar_t *pszInBuf, __in int nInSize, __out char **pszOutBuf, __out int *pnOutSize)

Check warning

Code scanning / PREfast

Returning uninitialized memory '*pnOutSize'. A successful path through the function does not set the named Out parameter. Warning

Returning uninitialized memory '*pnOutSize'. A successful path through the function does not set the named _Out_ parameter.
strncpy(fn + fnlen, config_file, fnsz - fnlen);
}
}
}
fn[fnsz] = 0;
if (strstr(fn, "//") != fn) {
if (strstr(fn, "//") != fn)

Check warning

Code scanning / PREfast

'fn' could be '0': this does not adhere to the specification for the function 'strstr'. See line 1394 for an earlier location where this can occur Warning

'fn' could be '0': this does not adhere to the specification for the function 'strstr'. See line 1394 for an earlier location where this can occur
@@ -34,9 +34,11 @@

/////////////// io handlers ///////////////////

static void udp_server_input_handler(evutil_socket_t fd, short what, void *arg) {
static void udp_server_input_handler(evutil_socket_t fd, short what, void *arg)

Check warning

Code scanning / PREfast

Function uses '65592' bytes of stack. Consider moving some data to heap. Warning

Function uses '65592' bytes of stack. Consider moving some data to heap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant