summaryrefslogtreecommitdiffstats
path: root/coccinelle (follow)
Commit message (Collapse)AuthorAgeFilesLines
* coccinelle: add a transformation for GNU conditionalsFrantisek Sumsal2023-03-181-0/+7
| | | | i.e. x ? x : y => x ?: y
* coccinelle: respect spacing from the semantic patchFrantisek Sumsal2023-03-181-1/+1
|
* coccinelle: skip the empty-to-null transformation on the macro itselfFrantisek Sumsal2023-01-251-2/+6
| | | | | | | | Since the empty_to_null() function was "macrofied", we need to use a bit of black magic to make Coccinelle avoid running the transformation on the macro itself. Follow-up to ef2409cbde3.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-3/+3
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* treewide: drop "RUN_" from "RUN_WITH_UMASK"Zbigniew Jędrzejewski-Szmek2022-12-131-1/+1
| | | | | | RUN_WITH_UMASK was initially conceived for spawning externals progs with the umask set. But nowadays we use it various syscalls and stuff that doesn't "run" anything, so the "RUN_" prefix has outlived its usefulness.
* basic/list: drop LIST_IS_EMPTYZbigniew Jędrzejewski-Szmek2022-07-021-2/+0
| | | | | | | | | | This was a trivial wrapper that didn't provide any added value. With more complicated structures like strvs, hashmaps, sets, and arrays, it is possible to have an empty container. But in case of a list, the list is empty only when the head is missing. Also, we generally want the positive condition, so we replace many if (!LIST_IS_EMPTY(x)) with just if (x).
* coccinelle: don't try to use IN_SET() in assert_cc()Frantisek Sumsal2022-05-301-5/+17
| | | | Since assert_cc() requires an integral constant expression.
* coccinelle: automatically look for timestamp_is_set candidatesLennart Poettering2022-02-221-0/+73
| | | | | | Based on @mrc0mmand's Coccinelle skills, not mine. All credit is his. Co-authored-by: Frantisek Sumsal <frantisek@sumsal.cz>
* coccinelle: automatically switch some uses of memcpy() → mempcpy()Lennart Poettering2022-02-161-0/+13
| | | | | Inspired by #22520, let's add a coccinelle script that converts this automatically.
* list: drop unnecessary line continuationYu Watanabe2021-12-241-1/+1
| | | | Fixes #21886.
* Change all fixed-path bash shebangs to /u/b/env bash outside test/наб2021-12-121-1/+2
|
* alloc-util: add strdupa_safe() + strndupa_safe() and use it everywhereLennart Poettering2021-10-141-0/+11
| | | | | | | | | | | | | Let's define two helpers strdupa_safe() + strndupa_safe() which do the same as their non-safe counterparts, except that they abort if called with allocations larger than ALLOCA_MAX. This should ensure that all our alloca() based allocations are subject to this limit. afaics glibc offers three alloca() based APIs: alloca() itself, strndupa() + strdupa(). With this we have now replacements for all of them, that take the limit into account.
* licensing: add spdx to our .cocci filesZbigniew Jędrzejewski-Szmek2021-10-0152-1/+54
| | | | | Since those are chunks of code based on our codebase, it's easiest to use the same license.
* ci: use LGPLv2+ for all our ci configurationZbigniew Jędrzejewski-Szmek2021-10-011-0/+1
|
* ci: shellcheck-ify CI scriptsFrantisek Sumsal2021-09-291-11/+14
|
* coccinelle: filter out a couple of 'false-positive' transformationsFrantisek Sumsal2021-03-183-2/+5
| | | | | | | | | | * flag-set.cocci: perform the transformation only if the second argument is a constant * sd-journal/lookup3.c: skip the cocci completely for this file, since it's not "ours" * strjoina.cocci: skip the transformation on the "test_strjoina" test, since it intentionally tests the "incorrect" expression we're trying to transform (the same thing was already done in strjoin.cocci)
* coccinelle: ignore specific cases to use SYNTHETIC_ERRNO() macroYu Watanabe2020-11-271-0/+6
|
* coccinelle: add rules for log_unit_error_errno() or friendsYu Watanabe2020-11-272-0/+269
|
* coccinelle: always use SYNTHETIC_ERRNO() macroYu Watanabe2020-11-191-2/+2
|
* coccinelle: add one more rule to use return value of log_xxx_errno()Yu Watanabe2020-11-191-0/+9
|
* coccinelle: introduce drop-braces transformationFrantisek Sumsal2020-10-091-0/+27
| | | | | | to drop braces around single-line if statements. Also, prefix it with zz- so it runs as the last one, so it's able to fix stuff tweaked by previous transformations.
* coccinelle: check for invalid errno comparisonsFrantisek Sumsal2020-10-091-0/+10
| | | | Prompted by #15868
* coccinelle: correctly resolve our own macrosFrantisek Sumsal2020-10-092-2/+233
| | | | | | | | Coccinelle can't do this automagically and requires we supply it respective header files. Unfortunately, the option for this (--macro-file=) can be used only once, so let's create our own macro file by collecting macros needed for the semantic parser to be happy.
* coccinelle: skip strjoin transformation in test_strjoin()Frantisek Sumsal2020-10-041-10/+9
|
* coccinelle: limit the # of expressions in in_set/not_in_setFrantisek Sumsal2020-10-042-27/+4
| | | | | | transformations. Otherwise the time and resources to generate all possible permutations is simply unreasonable for running on local machines.
* coccinelle: skip the xsprintf transformation on man pagesFrantisek Sumsal2020-10-041-1/+2
| | | | since we don't expose xsprintf to users.
* coccinelle: disable flags-set where it doesn't make senseFrantisek Sumsal2020-10-041-3/+9
|
* coccinelle: fix the equals-null transformationFrantisek Sumsal2020-10-041-6/+21
| | | | | | | | | | The original issue with this transformation was that we were replacing the whole if statement instead of just the expression inside. That caused the code to be weirdly formatted, as Coccinelle put a new block around each replaced if statement. This version replaces just the inner expression if it's in its incorrect form, otherwise it just accepts it (to avoid recursion).
* coccinelle: drop the custom isomorphismsFrantisek Sumsal2020-10-042-22/+1
| | | | | | | | My former dumb me didn't read the documentation properly, so with the introduction of custom isomorphisms I caused two issues: 1) Masked all standard isomorphisms defined by Coccinelle 2) Replace the original issue with a completely new one
* execute: use empty_to_root() a bit moreLennart Poettering2020-10-011-0/+5
|
* tree-wide: use set_ensure_put()Zbigniew Jędrzejewski-Szmek2020-06-221-0/+18
| | | | | | | | | Patch contains a coccinelle script, but it only works in some cases. Many parts were converted by hand. Note: I did not fix errors in return value handing. This will be done separate to keep the patch comprehensible. No functional change is intended in this patch.
* tree-wide: formatting tweaks reported by CoccinelleFrantisek Sumsal2020-04-211-2/+14
|
* tree-wide: use empty-to-root a bit moreLennart Poettering2019-07-161-0/+11
|
* Use sd_event_source_disable_unref()Zbigniew Jędrzejewski-Szmek2019-05-101-0/+36
|
* coccinelle: further restrict certain transformationsFrantisek Sumsal2019-04-305-55/+46
| | | | | | | | | Some transformations generate results we don't want to keep, so let's disable such transformations for specific files. Also, disable const-strlen.cocci everywhere, as the STRLEN macro has a pretty limited scope, so the transformation generates false positives in most cases.
* coccinelle: exclude JsonVariant* from the IN_SET transformationFrantisek Sumsal2019-04-302-67/+30
| | | | | JsonVariant* doesn't work with the current IN_SET implementation, so let's exclude it from the transformation altogether
* coccinelle: exclude certain paths from the transformationsFrantisek Sumsal2019-04-291-2/+17
| | | | | | There's no point in running these transformation for certain files, mainly anything from src/boot/efi and src/shared/linux, as this code doesn't have access to our internal utility functions
* coccinelle: ignore function transformations causing recursionFrantisek Sumsal2019-04-293-22/+39
| | | | | | | | | | | | | | | | | | | | | | For example, following transformation: - isempty(s) ? NULL : s + empty_to_null(s) would get applied to the empty_to_null function itself as well, causing an infinite recursion, like: --- src/basic/string-util.h +++ /tmp/cocci-output-307-9f76e6-string-util.h @@ -50,11 +50,11 @@ static inline bool isempty(const char *p } static inline const char *empty_to_null(const char *p) { - return isempty(p) ? NULL : p; + return empty_to_null(p); } Let's avoid that by checking the current match position
* coccinelle: ignore macro transformations in the macros themselvesFrantisek Sumsal2019-04-283-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | For example, the following transformation: - sizeof(s)-1 + STRLEN(s) would replace sizeof by STRLEN even in the STRLEN macro definition itself, which generates following nonsensical patch: --- src/basic/macro.h +++ /tmp/cocci-output-8753-b50773-macro.h @@ -182,7 +182,7 @@ static inline unsigned long ALIGN_POWER2 * Contrary to strlen(), this is a constant expression. * @x: a string literal. */ -#define STRLEN(x) (sizeof(""x"") - 1) +#define STRLEN(x) (STRLEN("" x "")) /* * container_of - cast a member of a structure out to the containing structure Let's exclude the macro itself from the transformation to avoid this
* coccinelle: avoid matching 'errno' as a file descriptorFrantisek Sumsal2019-04-271-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `coccinelle/take-fd.cocci` transformation file attempts to rewrite r = fd; fd = -1; to r = TAKE_FD(fd); Unfortunately, using `identifier` or `idexpression` as a metavariable type in this case wouldn't match more complex location descriptions, like: x->fd = fd fd = -1; Using 'expression' metavariable type generates false positives, as you can't specify scope of such expression. The only real example from the current codebase is the global 'errno' variable, which results in following patch generated by `spatch`: --- src/basic/errno-util.h +++ /tmp/cocci-output-28263-971baa-errno-util.h @@ -15,8 +15,7 @@ static inline void _reset_errno_(int *sa #define UNPROTECT_ERRNO \ do { \ - errno = _saved_errno_; \ - _saved_errno_ = -1; \ + errno = TAKE_FD(_saved_errno_); \ } while (false) static inline int negative_errno(void) { Let's explicitly state that the matched expression should not equal 'errno' to avoid this. It's not particularly nice, but it should be enough, at least for now.
* coccinelle: add explicit statement isomorphismsFrantisek Sumsal2019-04-272-1/+22
| | | | | | | | | | | | | | | | | | | | | | | | Coccinelle needs a custom isomorphism file with rules (isomorphisms) how to correctly rewrite conditions with explicit NULL checks (i.e. if (ptr == NULL)) to their shorter form (i.e. if (!ptr)). Coccinelle already contains such isomorphisms in its default .iso file, however, they're in the opposite direction, which results in useless output from coccinelle/equals-null.cocci. With this fix, `spatch` should no longer report patches like: @@ -628,8 +628,9 @@ static int path_deserialize_item(Unit *u f = path_result_from_string(value); if (f < 0) log_unit_debug(u, "Failed to parse result value: %s", value); - else if (f != PATH_SUCCESS) - p->result = f; + else {if (f != PATH_SUCCESS) + p->result = f; + } } else log_unit_debug(u, "Unknown serialization key: %s", key);
* Merge pull request #12217 from keszybz/unlocked-operationsLennart Poettering2019-04-121-0/+71
|\ | | | | Refactor how we do unlocked file operations
| * Add open_memstream_unlocked() wrapperZbigniew Jędrzejewski-Szmek2019-04-121-0/+8
| |
| * Add fdopen_unlocked() wrapperZbigniew Jędrzejewski-Szmek2019-04-121-0/+12
| |
| * Make fopen_temporary and fopen_temporary_label unlockedZbigniew Jędrzejewski-Szmek2019-04-121-0/+14
| | | | | | | | | | | | | | | | This is partially a refactoring, but also makes many more places use unlocked operations implicitly, i.e. all users of fopen_temporary(). AFAICT, the uses are always for short-lived files which are not shared externally, and are just used within the same context. Locking is not necessary.
| * Add fopen_unlocked() wrapperZbigniew Jędrzejewski-Szmek2019-04-121-0/+37
| |
* | scripts: use 4 space indentationZbigniew Jędrzejewski-Szmek2019-04-121-13/+13
|/ | | | | | | | | | | | | | | | | | We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed. 4 sp was the most common, in particular the majority of scripts under test/ used that. Let's standarize on 4 sp, because many commandlines are long and there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp also seems to be the default indentation, so this will make it less likely that people will mess up if they don't load the editor config. (I think people often use vi, and vi has no support to load project-wide configuration automatically. We distribute a .vimrc file, but it is not loaded by default, and even the instructions in it seem to discourage its use for security reasons.) Also remove the few vim config lines that were left. We should either have them on all files, or none. Also remove some strange stuff like '#!/bin/env bash', yikes.
* coccinelle: add coccinelle script for empty_or_dash() useLennart Poettering2019-04-081-0/+5
|
* nspawn-oci: use SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2019-03-211-0/+8
|
* tree-wide: more IOVEC_MAKE() conversionsLennart Poettering2018-11-281-0/+5
|