2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 13:08:06 +00:00

30 Commits

Author SHA1 Message Date
Ondřej Surý
33ba0057a7 Cleanup dns_message_gettemp*() functions - they cannot fail
The dns_message_gettempname(), dns_message_gettemprdata(),
dns_message_gettemprdataset(), and dns_message_gettemprdatalist() always
succeeds because the memory allocation cannot fail now.  Change the API
to return void and cleanup all the use of aforementioned functions.
2022-05-17 12:39:25 +02:00
Ondřej Surý
4dceab142d Consistenly use UNREACHABLE() instead of ISC_UNREACHABLE()
In couple places, we have missed INSIST(0) or ISC_UNREACHABLE()
replacement on some branches with UNREACHABLE().  Replace all
ISC_UNREACHABLE() or INSIST(0) calls with UNREACHABLE().
2022-03-28 23:26:08 +02:00
Ondřej Surý
584f0d7a7e Simplify way we tag unreachable code with only ISC_UNREACHABLE()
Previously, the unreachable code paths would have to be tagged with:

    INSIST(0);
    ISC_UNREACHABLE();

There was also older parts of the code that used comment annotation:

    /* NOTREACHED */

Unify the handling of unreachable code paths to just use:

    UNREACHABLE();

The UNREACHABLE() macro now asserts when reached and also uses
__builtin_unreachable(); when such builtin is available in the compiler.
2022-03-25 08:33:43 +01:00
Ondřej Surý
e6ca2a651f Refactor isc_timer_reset() use with semantic patch
Add and apply semantic patch to remove expires argument from the
isc_timer_reset() calls through the codebase.
2022-03-14 13:00:05 -07:00
Ondřej Surý
62bd5cb08c Add semantic patch to keep UV_RUNTIME_CHECK in sync
The UV_RUNTIME_CHECK() macro requires to keep the function name in sync
like this:

    r = func(...);
    UV_RUNTIME_CHECK(func, r);

Add semantic patch to keep the function name and return variable in sync
with the previous line.
2022-02-16 11:16:57 +01:00
Michal Nowak
a0d0dee4af
Fix typo in dns_name_copy-with-result.spatch
A typo introduced in f3f1cab05e05c9bdd5da91f3ab159ec6658ec7f4 prevents
execution of the dns_name_copy-with-result.spatch. The replacement
should end with semicolon not a colon:

    plus: parse error:
      File "cocci/dns_name_copy-with-result.spatch", line 28, column 23, charpos = 421
      around = ':',
      whole content = + dns_name_copy(E1, E2):
2021-11-02 19:16:41 +01:00
Ondřej Surý
e603983ec9 Stop providing branch prediction information
The __builtin_expect() can be used to provide the compiler with branch
prediction information.  The Gcc manual says[1] on the subject:

    In general, you should prefer to use actual profile feedback for
    this (-fprofile-arcs), as programmers are notoriously bad at
    predicting how their programs actually perform.

Stop using __builtin_expect() and ISC_LIKELY() and ISC_UNLIKELY() macros
to provide the branch prediction information as the performance testing
shows that named performs better when the __builtin_expect() is not
being used.

1. https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fexpect
2021-10-14 10:33:24 +02:00
Ondřej Surý
efb385ecdc Clean up isc_mempool API
- isc_mempool_get() can no longer fail; when there are no more objects
  in the pool, more are always allocated. checking for NULL return is
  no longer necessary.
- the isc_mempool_setmaxalloc() and isc_mempool_getmaxalloc() functions
  are no longer used and have been removed.
2021-07-09 15:58:02 +02:00
Evan Hunt
f3f1cab05e clean up coccinelle patches for dns_name_copy()
no need for semantic patches to use dns_name_copynf() any longer.
2021-05-22 00:37:27 -07:00
Ondřej Surý
33eefe9f85 The dns_message_create() cannot fail, change the return to void
The dns_message_create() function cannot soft fail (as all memory
allocations either succeed or cause abort), so we change the function to
return void and cleanup the calls.
2020-09-29 08:22:08 +02:00
Diego Fronza
7deaf9a93c cocci: Add semantic patch to refactor dns_message_destroy()
dns_message_t objects are now being handled using reference counting
semantics, so now dns_message_destroy() is not called directly anymore,
dns_message_detach must be called instead.
2020-09-29 08:22:08 +02:00
Ondřej Surý
bc1d4c9cb4 Clear the pointer to destroyed object early using the semantic patch
Also disable the semantic patch as the code needs tweaks here and there because
some destroy functions might not destroy the object and return early if the
object is still in use.
2020-02-09 18:00:17 -08:00
Ondřej Surý
b97d003033 Add semantic patch to NULL the destroyed pointer early
Our destroy functions usually look like this:

    void
    foo_destroy(foo_t **foop) {
        foo_t foo = *foop;
        ...destroy the contents of foo...
        *foop = NULL;
    }

nulling the pointer should be done as soon as possible which is
not always the case.  This commit adds simple semantic patch that
changes the example function to:

    void
    foo_destroy(foo_t **foop) {
        foo_t foo = *foop;
        *foop = NULL;
        ...destroy the contents of foo...
    }
2020-02-09 18:00:16 -08:00
Ondřej Surý
d5f682a00b Add semantic patch to fix isc_buffer_allocate usage, it cannot fail now 2020-02-03 08:29:00 +01:00
Ondřej Surý
33328871a7 Add semantic patch to refactor isc_mempool_create() usage 2020-02-03 08:27:12 +01:00
Ondřej Surý
9dfa33050b Add semantic patch to find void f() { ... return ((void)g())); ... }
When a function returns void, it can be used as an argument to return in
function returning also void, e.g.:

void in(void) {
  return;
}

void out(void) {
  return (in());
}

while this is legal, it should be rewritten as:

void out(void) {
  in();
  return;
}

The semantic patch just find the occurrences, and they need to be fixed
by hand.
2019-12-06 13:42:18 +01:00
Ondřej Surý
7a69ac32c9 Disable no longer useful semantic patches
Some semantic patches are meant to be run just once, as they work on
functions with changed prototypes. We keep them for reference, but
disabled them from the CI to save time.
2019-11-29 14:26:14 +01:00
Ondřej Surý
21902d0ac7 cocci: Add semantic patch to refactor dns_name_dup() usage 2019-11-29 13:59:40 +01:00
Ondřej Surý
ac26ecf540 Add semantic patch to replace RUNTIME_CHECK(dns_name_copy(..., NULL)) with dns_name_copynf 2019-10-01 10:43:26 +10:00
Ondřej Surý
406eba0c41 Add semantic patches to correctly check dns_name_copy(..., NULL) return code
The dns_name_copy() function cannot fail gracefully when the last argument
(target) is NULL.  Add RUNTIME_CHECK()s around such calls.

The first semantic patch adds RUNTIME_CHECK() around any call that ignores the
return value and is very safe to apply.

The second semantic patch attempts to properly add RUNTIME_CHECK() to places
where the return value from `dns_name_copy()` is recorded into `result`
variable.  The result of this semantic patch needs to be reviewed by hand.

Both patches misses couple places where the code surrounding the
`dns_name_copy(..., NULL)` usage is more complicated and is better suited to be
fixed by a human being that understands the surrounding code.
2019-10-01 10:43:26 +10:00
Ondřej Surý
6bd2eb06cb Add a semantic patch to make refactor the isc_mem_create() 2019-09-12 09:26:09 +02:00
Ondřej Surý
2d12def6ee isc_event_allocate() can't fail now, add spatch to remove the checks 2019-08-30 01:04:28 -04:00
Evan Hunt
a8595262f7 add a semantic patch for the API change 2019-08-29 10:07:41 -07:00
Ondřej Surý
d502569902 Add spatch to replace isc_mem_put+isc_mem_detach with isc_mem_putanddetach 2019-07-31 10:26:40 +02:00
Ondřej Surý
3c1d4298af Add spatch for isc_mem_allocate; it also cannot fail gracefully 2019-07-23 15:32:35 -04:00
Ondřej Surý
49f244406c Add spatch for isc_mem_strdup; it also cannot fail gracefully 2019-07-23 15:32:35 -04:00
Ondřej Surý
f63e696967 Add semantic patch to remove checking for isc_mem_get() return value
The isc_mem_get() cannot fail gracefully now, it either gets memory of
assert()s.  The added semantic patch cleans all the blocks checking whether
the return value of isc_mem_get() was NULL.
2019-07-23 15:32:35 -04:00
Ondřej Surý
7615e86fae Add spatch to replace memcpy usage with memmove 2019-07-12 15:27:06 +02:00
Ondřej Surý
0b9f7f8a38 Add semantic patch to remove occurences of '#include <config.h>' 2019-03-08 15:15:05 +01:00
Ondřej Surý
21db43da8e Add unreachable.spatch coccinelle recipe and run it in precheck CI phase 2018-11-22 09:28:00 -05:00