mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Use clang-tidy to add curly braces around one-line statements
The command used to reformat the files in this commit was: ./util/run-clang-tidy \ -clang-tidy-binary clang-tidy-11 -clang-apply-replacements-binary clang-apply-replacements-11 \ -checks=-*,readability-braces-around-statements \ -j 9 \ -fix \ -format \ -style=file \ -quiet clang-format -i --style=format $(git ls-files '*.c' '*.h') uncrustify -c .uncrustify.cfg --replace --no-backup $(git ls-files '*.c' '*.h') clang-format -i --style=format $(git ls-files '*.c' '*.h')
This commit is contained in:
164
lib/isc/lex.c
164
lib/isc/lex.c
@@ -69,8 +69,9 @@ grow_data(isc_lex_t *lex, size_t *remainingp, char **currp, char **prevp)
|
||||
tmp = isc_mem_get(lex->mctx, lex->max_token * 2 + 1);
|
||||
memmove(tmp, lex->data, lex->max_token + 1);
|
||||
*currp = tmp + (*currp - lex->data);
|
||||
if (*prevp != NULL)
|
||||
if (*prevp != NULL) {
|
||||
*prevp = tmp + (*prevp - lex->data);
|
||||
}
|
||||
isc_mem_put(lex->mctx, lex->data, lex->max_token + 1);
|
||||
lex->data = tmp;
|
||||
*remainingp += lex->max_token;
|
||||
@@ -88,8 +89,9 @@ isc_lex_create(isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp)
|
||||
*/
|
||||
REQUIRE(lexp != NULL && *lexp == NULL);
|
||||
|
||||
if (max_token == 0U)
|
||||
if (max_token == 0U) {
|
||||
max_token = 1;
|
||||
}
|
||||
|
||||
lex = isc_mem_get(mctx, sizeof(*lex));
|
||||
lex->data = isc_mem_get(mctx, max_token + 1);
|
||||
@@ -124,10 +126,12 @@ isc_lex_destroy(isc_lex_t **lexp)
|
||||
*lexp = NULL;
|
||||
REQUIRE(VALID_LEX(lex));
|
||||
|
||||
while (!EMPTY(lex->sources))
|
||||
while (!EMPTY(lex->sources)) {
|
||||
RUNTIME_CHECK(isc_lex_close(lex) == ISC_R_SUCCESS);
|
||||
if (lex->data != NULL)
|
||||
}
|
||||
if (lex->data != NULL) {
|
||||
isc_mem_put(lex->mctx, lex->data, lex->max_token + 1);
|
||||
}
|
||||
lex->magic = 0;
|
||||
isc_mem_put(lex->mctx, lex, sizeof(*lex));
|
||||
}
|
||||
@@ -218,12 +222,14 @@ isc_lex_openfile(isc_lex_t *lex, const char *filename)
|
||||
REQUIRE(VALID_LEX(lex));
|
||||
|
||||
result = isc_stdio_open(filename, "r", &stream);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
result = new_source(lex, true, true, stream, filename);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
(void)fclose(stream);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -271,14 +277,16 @@ isc_lex_close(isc_lex_t *lex)
|
||||
REQUIRE(VALID_LEX(lex));
|
||||
|
||||
source = HEAD(lex->sources);
|
||||
if (source == NULL)
|
||||
if (source == NULL) {
|
||||
return (ISC_R_NOMORE);
|
||||
}
|
||||
|
||||
ISC_LIST_UNLINK(lex->sources, source, link);
|
||||
lex->last_was_eol = source->last_was_eol;
|
||||
if (source->is_file) {
|
||||
if (source->need_close)
|
||||
if (source->need_close) {
|
||||
(void)fclose((FILE *)(source->input));
|
||||
}
|
||||
}
|
||||
isc_mem_free(lex->mctx, source->name);
|
||||
isc_buffer_free(&source->pushback);
|
||||
@@ -311,8 +319,9 @@ pushback(inputsource *source, int c)
|
||||
return;
|
||||
}
|
||||
source->pushback->current--;
|
||||
if (c == '\n')
|
||||
if (c == '\n') {
|
||||
source->line--;
|
||||
}
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
@@ -371,8 +380,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
return (ISC_R_NOMORE);
|
||||
}
|
||||
|
||||
if (source->result != ISC_R_SUCCESS)
|
||||
if (source->result != ISC_R_SUCCESS) {
|
||||
return (source->result);
|
||||
}
|
||||
|
||||
lex->saved_paren_count = lex->paren_count;
|
||||
source->saved_line = source->line;
|
||||
@@ -399,8 +409,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
isc_buffer_compact(source->pushback);
|
||||
|
||||
saved_options = options;
|
||||
if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 && lex->paren_count > 0)
|
||||
if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 && lex->paren_count > 0) {
|
||||
options &= ~IWSEOL;
|
||||
}
|
||||
|
||||
curr = lex->data;
|
||||
*curr = '\0';
|
||||
@@ -409,9 +420,10 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
remaining = lex->max_token;
|
||||
|
||||
#ifdef HAVE_FLOCKFILE
|
||||
if (source->is_file)
|
||||
if (source->is_file) {
|
||||
flockfile(source->input);
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_FLOCKFILE */
|
||||
|
||||
do {
|
||||
if (isc_buffer_remaininglength(source->pushback) == 0) {
|
||||
@@ -420,9 +432,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
|
||||
#if defined(HAVE_FLOCKFILE) && defined(HAVE_GETC_UNLOCKED)
|
||||
c = getc_unlocked(stream);
|
||||
#else
|
||||
#else /* if defined(HAVE_FLOCKFILE) && defined(HAVE_GETC_UNLOCKED) */
|
||||
c = getc(stream);
|
||||
#endif
|
||||
#endif /* if defined(HAVE_FLOCKFILE) && defined(HAVE_GETC_UNLOCKED) */
|
||||
if (c == EOF) {
|
||||
if (ferror(stream)) {
|
||||
source->result = ISC_R_IOERROR;
|
||||
@@ -453,17 +465,19 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
}
|
||||
|
||||
if (!source->at_eof) {
|
||||
if (state == lexstate_start)
|
||||
if (state == lexstate_start) {
|
||||
/* Token has not started yet. */
|
||||
source->ignored = isc_buffer_consumedlength(
|
||||
source->pushback);
|
||||
}
|
||||
c = isc_buffer_getuint8(source->pushback);
|
||||
} else {
|
||||
c = EOF;
|
||||
}
|
||||
|
||||
if (c == '\n')
|
||||
if (c == '\n') {
|
||||
source->line++;
|
||||
}
|
||||
|
||||
if (lex->comment_ok && !no_comments) {
|
||||
if (!escaped && c == ';' &&
|
||||
@@ -529,8 +543,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
}
|
||||
lex->last_was_eol = true;
|
||||
} else if (c == '\r') {
|
||||
if ((options & ISC_LEXOPT_EOL) != 0)
|
||||
if ((options & ISC_LEXOPT_EOL) != 0) {
|
||||
state = lexstate_crlf;
|
||||
}
|
||||
} else if (c == '"' &&
|
||||
(options & ISC_LEXOPT_QSTRING) != 0) {
|
||||
lex->last_was_eol = false;
|
||||
@@ -541,8 +556,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
if ((c == '(' || c == ')') &&
|
||||
(options & ISC_LEXOPT_DNSMULTILINE) != 0) {
|
||||
if (c == '(') {
|
||||
if (lex->paren_count == 0)
|
||||
if (lex->paren_count == 0) {
|
||||
options &= ~IWSEOL;
|
||||
}
|
||||
lex->paren_count++;
|
||||
} else {
|
||||
if (lex->paren_count == 0) {
|
||||
@@ -551,8 +567,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
goto done;
|
||||
}
|
||||
lex->paren_count--;
|
||||
if (lex->paren_count == 0)
|
||||
if (lex->paren_count == 0) {
|
||||
options = saved_options;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
} else if (c == '{' &&
|
||||
@@ -574,10 +591,11 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
(options & ISC_LEXOPT_NUMBER) != 0) {
|
||||
lex->last_was_eol = false;
|
||||
if ((options & ISC_LEXOPT_OCTAL) != 0 &&
|
||||
(c == '8' || c == '9'))
|
||||
(c == '8' || c == '9')) {
|
||||
state = lexstate_string;
|
||||
else
|
||||
} else {
|
||||
state = lexstate_number;
|
||||
}
|
||||
goto no_read;
|
||||
} else {
|
||||
lex->last_was_eol = false;
|
||||
@@ -586,8 +604,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
}
|
||||
break;
|
||||
case lexstate_crlf:
|
||||
if (c != '\n')
|
||||
if (c != '\n') {
|
||||
pushback(source, c);
|
||||
}
|
||||
tokenp->type = isc_tokentype_eol;
|
||||
done = true;
|
||||
lex->last_was_eol = true;
|
||||
@@ -597,13 +616,14 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
if (c == ' ' || c == '\t' || c == '\r' ||
|
||||
c == '\n' || c == EOF || lex->specials[c]) {
|
||||
int base;
|
||||
if ((options & ISC_LEXOPT_OCTAL) != 0)
|
||||
if ((options & ISC_LEXOPT_OCTAL) != 0) {
|
||||
base = 8;
|
||||
else if ((options &
|
||||
ISC_LEXOPT_CNUMBER) != 0)
|
||||
} else if ((options &
|
||||
ISC_LEXOPT_CNUMBER) != 0) {
|
||||
base = 0;
|
||||
else
|
||||
} else {
|
||||
base = 10;
|
||||
}
|
||||
pushback(source, c);
|
||||
|
||||
result = isc_parse_uint32(
|
||||
@@ -624,8 +644,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
v->as_textregion.length =
|
||||
(unsigned int)(lex->max_token -
|
||||
remaining);
|
||||
} else
|
||||
} else {
|
||||
goto done;
|
||||
}
|
||||
done = true;
|
||||
continue;
|
||||
} else if ((options & ISC_LEXOPT_CNUMBER) ==
|
||||
@@ -643,8 +664,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
if (remaining == 0U) {
|
||||
result = grow_data(lex, &remaining, &curr,
|
||||
&prev);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
INSIST(remaining > 0U);
|
||||
*curr++ = c;
|
||||
@@ -672,14 +694,16 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
done = true;
|
||||
continue;
|
||||
}
|
||||
if ((options & ISC_LEXOPT_ESCAPE) != 0)
|
||||
if ((options & ISC_LEXOPT_ESCAPE) != 0) {
|
||||
escaped = (!escaped && c == '\\') ? true
|
||||
: false;
|
||||
}
|
||||
if (remaining == 0U) {
|
||||
result = grow_data(lex, &remaining, &curr,
|
||||
&prev);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
INSIST(remaining > 0U);
|
||||
*curr++ = c;
|
||||
@@ -707,8 +731,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
result = ISC_R_UNEXPECTEDEND;
|
||||
goto done;
|
||||
}
|
||||
if (c == '*')
|
||||
if (c == '*') {
|
||||
state = lexstate_ccommentend;
|
||||
}
|
||||
break;
|
||||
case lexstate_ccommentend:
|
||||
if (c == EOF) {
|
||||
@@ -726,8 +751,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
no_comments = false;
|
||||
state = saved_state;
|
||||
goto no_read;
|
||||
} else if (c != '*')
|
||||
} else if (c != '*') {
|
||||
state = lexstate_ccomment;
|
||||
}
|
||||
break;
|
||||
case lexstate_eatline:
|
||||
if ((c == '\n') || (c == EOF)) {
|
||||
@@ -767,15 +793,17 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
result = ISC_R_UNBALANCEDQUOTES;
|
||||
goto done;
|
||||
}
|
||||
if (c == '\\' && !escaped)
|
||||
if (c == '\\' && !escaped) {
|
||||
escaped = true;
|
||||
else
|
||||
} else {
|
||||
escaped = false;
|
||||
}
|
||||
if (remaining == 0U) {
|
||||
result = grow_data(lex, &remaining,
|
||||
&curr, &prev);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
INSIST(remaining > 0U);
|
||||
prev = curr;
|
||||
@@ -816,16 +844,18 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
}
|
||||
}
|
||||
|
||||
if (c == '\\' && !escaped)
|
||||
if (c == '\\' && !escaped) {
|
||||
escaped = true;
|
||||
else
|
||||
} else {
|
||||
escaped = false;
|
||||
}
|
||||
|
||||
if (remaining == 0U) {
|
||||
result = grow_data(lex, &remaining, &curr,
|
||||
&prev);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
INSIST(remaining > 0U);
|
||||
prev = curr;
|
||||
@@ -837,15 +867,15 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
|
||||
FATAL_ERROR(__FILE__, __LINE__, "Unexpected state %d",
|
||||
state);
|
||||
}
|
||||
|
||||
} while (!done);
|
||||
|
||||
result = ISC_R_SUCCESS;
|
||||
done:
|
||||
#ifdef HAVE_FLOCKFILE
|
||||
if (source->is_file)
|
||||
if (source->is_file) {
|
||||
funlockfile(source->input);
|
||||
#endif
|
||||
}
|
||||
#endif /* ifdef HAVE_FLOCKFILE */
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -857,29 +887,36 @@ isc_lex_getmastertoken(isc_lex_t *lex, isc_token_t *token,
|
||||
ISC_LEXOPT_DNSMULTILINE | ISC_LEXOPT_ESCAPE;
|
||||
isc_result_t result;
|
||||
|
||||
if (expect == isc_tokentype_qstring)
|
||||
if (expect == isc_tokentype_qstring) {
|
||||
options |= ISC_LEXOPT_QSTRING;
|
||||
else if (expect == isc_tokentype_number)
|
||||
} else if (expect == isc_tokentype_number) {
|
||||
options |= ISC_LEXOPT_NUMBER;
|
||||
}
|
||||
result = isc_lex_gettoken(lex, options, token);
|
||||
if (result == ISC_R_RANGE)
|
||||
if (result == ISC_R_RANGE) {
|
||||
isc_lex_ungettoken(lex, token);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
}
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
if (eol && ((token->type == isc_tokentype_eol) ||
|
||||
(token->type == isc_tokentype_eof)))
|
||||
(token->type == isc_tokentype_eof))) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
if (token->type == isc_tokentype_string &&
|
||||
expect == isc_tokentype_qstring)
|
||||
expect == isc_tokentype_qstring) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
if (token->type != expect) {
|
||||
isc_lex_ungettoken(lex, token);
|
||||
if (token->type == isc_tokentype_eol ||
|
||||
token->type == isc_tokentype_eof)
|
||||
token->type == isc_tokentype_eof) {
|
||||
return (ISC_R_UNEXPECTEDEND);
|
||||
if (expect == isc_tokentype_number)
|
||||
}
|
||||
if (expect == isc_tokentype_number) {
|
||||
return (ISC_R_BADNUMBER);
|
||||
}
|
||||
return (ISC_R_UNEXPECTEDTOKEN);
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
@@ -894,19 +931,23 @@ isc_lex_getoctaltoken(isc_lex_t *lex, isc_token_t *token, bool eol)
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_lex_gettoken(lex, options, token);
|
||||
if (result == ISC_R_RANGE)
|
||||
if (result == ISC_R_RANGE) {
|
||||
isc_lex_ungettoken(lex, token);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
}
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
if (eol && ((token->type == isc_tokentype_eol) ||
|
||||
(token->type == isc_tokentype_eof)))
|
||||
(token->type == isc_tokentype_eof))) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
if (token->type != isc_tokentype_number) {
|
||||
isc_lex_ungettoken(lex, token);
|
||||
if (token->type == isc_tokentype_eol ||
|
||||
token->type == isc_tokentype_eof)
|
||||
token->type == isc_tokentype_eof) {
|
||||
return (ISC_R_UNEXPECTEDEND);
|
||||
}
|
||||
return (ISC_R_BADNUMBER);
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
@@ -964,8 +1005,9 @@ isc_lex_getsourcename(isc_lex_t *lex)
|
||||
REQUIRE(VALID_LEX(lex));
|
||||
source = HEAD(lex->sources);
|
||||
|
||||
if (source == NULL)
|
||||
if (source == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (source->name);
|
||||
}
|
||||
@@ -978,8 +1020,9 @@ isc_lex_getsourceline(isc_lex_t *lex)
|
||||
REQUIRE(VALID_LEX(lex));
|
||||
source = HEAD(lex->sources);
|
||||
|
||||
if (source == NULL)
|
||||
if (source == NULL) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (source->line);
|
||||
}
|
||||
@@ -993,8 +1036,9 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name)
|
||||
REQUIRE(VALID_LEX(lex));
|
||||
source = HEAD(lex->sources);
|
||||
|
||||
if (source == NULL)
|
||||
if (source == NULL) {
|
||||
return (ISC_R_NOTFOUND);
|
||||
}
|
||||
newname = isc_mem_strdup(lex->mctx, name);
|
||||
isc_mem_free(lex->mctx, source->name);
|
||||
source->name = newname;
|
||||
@@ -1009,8 +1053,9 @@ isc_lex_setsourceline(isc_lex_t *lex, unsigned long line)
|
||||
REQUIRE(VALID_LEX(lex));
|
||||
source = HEAD(lex->sources);
|
||||
|
||||
if (source == NULL)
|
||||
if (source == NULL) {
|
||||
return (ISC_R_NOTFOUND);
|
||||
}
|
||||
|
||||
source->line = line;
|
||||
return (ISC_R_SUCCESS);
|
||||
@@ -1025,8 +1070,9 @@ isc_lex_isfile(isc_lex_t *lex)
|
||||
|
||||
source = HEAD(lex->sources);
|
||||
|
||||
if (source == NULL)
|
||||
if (source == NULL) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
return (source->is_file);
|
||||
}
|
||||
|
Reference in New Issue
Block a user