summaryrefslogtreecommitdiff
path: root/src/basic/extract-word.c
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-10-041-1/+1
|
* shared/extract-word: replace enum with unsigned int to avoid undefined behaviourZbigniew Jędrzejewski-Szmek2017-04-251-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ../src/basic/extract-word.c:255:22: warning: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior [-Wvarargs] va_start(ap, flags); ^ ../src/basic/extract-word.c:244:77: note: parameter of type 'ExtractFlags' (aka 'enum ExtractFlags') is declared here int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) { ^ ../src/basic/extract-word.c:286:22: warning: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior [-Wvarargs] va_start(ap, flags); ^ ../src/basic/extract-word.c:244:77: note: parameter of type 'ExtractFlags' (aka 'enum ExtractFlags') is declared here int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) { ^ 2 warnings generated. I think the relevant part of C99 is 6.7.2.2 Enumeration specifiers: Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration. and 7.16.1.4: The parameter parmN is the identifier of the rightmost parameter in the variable parameter list in the function definition (the one just before the ...). If the parameter parmN is declared with the register storage class, with a function or array type, or with a type that is not compatible with the type that results after application of the default argument promotions, the behavior is undefined. This might cause a real issue if the compiler chooses something that is not an integer for ExtractFlags. Rework the code to avoid the warning, but add an assert_cc in a large-valued ExtractFlags element is ever defined and the type is bumped to something wider than an int.
* basic/extract-word,man: clarify "correction" of invalid escapesZbigniew Jędrzejewski-Szmek2016-12-111-2/+2
| | | | | | | | | | Our warning message was misleading, because we wouldn't "correct" anything, we'd just ignore unkown escapes. Update the message. Also, print just the extracted word (which contains the offending sequences) in the message, instead of the whole line. Fixes #4697.
* tree-wide: make invocations of extract_first_word more uniform (#4627)Zbigniew Jędrzejewski-Szmek2016-11-111-1/+1
| | | | extract_first_words deals fine with the string being NULL, so drop the upfront check for that.
* tree-wide: make ++/-- usage consistent WRT spacingVito Caputo2016-02-221-7/+7
| | | | | | Throughout the tree there's spurious use of spaces separating ++ and -- operators from their respective operands. Make ++ and -- operator consistent with the majority of existing uses; discard the spaces.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* utf8.[ch] et al: use char32_t and char16_t instead of int, int32_t, int16_tShawn Landden2016-01-271-1/+1
| | | | | | | | | | | | rework C11 utf8.[ch] to use char32_t instead of uint32_t when referring to unicode chars, to make things more expressive. [ @zonque: * rebased to current master * use AC_CHECK_DECLS to detect availibility of char{16,32}_t * make utf8_encoded_to_unichar() return int ]
* basic/escape: merge utf8 and non-utf8 paths in cunescape_oneZbigniew Jędrzejewski-Szmek2016-01-181-4/+5
| | | | | | | | | | | | | | | | | | | Not every byte sequence is valid utf8. We allow escaping of non-utf8 sequences in strings by using octal and hexadecimal escape sequences (\123 and \0xAB) for bytes at or above 128. Users of cunescape_one could infer whether such use occured when they received an answer between 128 and 256 in *ret (a non-ascii one byte character). But this is subtle and misleading: the comments were wrong, because ascii is a subset of unicode, so c != 0 did not mean non-unicode, but rather ascii-subset-of-unicode-or-raw-byte. This was all rather confusing, so make the "single byte" condition explicit. I'm not convinced that allowing non-utf8 sequences to be produced is useful in all cases where we allow it (e.g. in config files), but that behaviour is unchanged, just made more explicit. This also fixes an (invalid) gcc warning about unitialized variable (*ret_unicode) in callers of cunescape_one.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-1/+11
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* core: fix dependency parsingLennart Poettering2015-11-111-2/+2
| | | | | | | | 3d793d29059a7ddf5282efa6b32b953c183d7a4d broke parsing of unit file names that include backslashes, as extract_first_word() strips those. Fix this, by introducing a new EXTRACT_RETAIN_ESCAPE flag which disables looking at any flags, thus being compatible with the classic FOREACH_WORD() behaviour.
* extract-word: Skip coalesced separators in placeFilipe Brandenburger2015-11-051-11/+9
| | | | | | | | | | | Just skip them in place, instead of setting separator=true. We only do that in a single place (while finding a separator outside of quote or backslash states) so we don't really need a separate state for it. Tested that no regressions were introduced in test-extract-word. Ran a full `make check` and also installed the binaries on a test system and did not see any issues related to parsing unit files or starting units after a reboot.
* extract-word: Do not re-evaluate the state on each parsed characterFilipe Brandenburger2015-11-051-32/+43
| | | | | | | | Use inner loops to keep processing the same state, except when there is a state change, then break back to the outer loop so that the correct branch can be selected again. Tested that no regressions were introduced in test-extract-word.
* extract-word: increment pointer p and keep c in sync in for loopFilipe Brandenburger2015-11-051-9/+6
| | | | | | | This will make it easier to use inner loops to keep looping in the same state, by just updating p and c in the same way in the inner loops. Tested that no regressions were created in test-extract-word.
* extract-word: Check for early bail out before inspecting separatorsFilipe Brandenburger2015-11-051-3/+3
| | | | | | It's a pretty small optimization but doesn't hurt... Tested with test-extract-word.
* extract-word: replace an use of `goto` with structured codeFilipe Brandenburger2015-11-051-11/+9
| | | | | | | | | Using `goto` might be appropriate for the "finish" cases but it was really not necessary at this point of the code... Just use if/else blocks to accomplish the same. Confirmed that the test cases in test-extract-word keep working as expected.
* extract-word: move start block outside the for loopFilipe Brandenburger2015-11-051-18/+17
| | | | | | | | | | This block runs once before all the other handling, so move it outside the main loop and put it in its own loop until it's finished doing its job. Tested by confirming `make check` (and particularly test-extract-word) still passes and by booting a system with binaries including this commit.
* util-lib: move character class definitions to string-util.hLennart Poettering2015-11-031-1/+2
|
* Revert "utf8.[ch]: use char32_t and char16_t instead of int, int32_t, int16_t"revert-1740-masterLennart Poettering2015-11-021-1/+1
|
* utf8.[ch]: use char32_t and char16_t instead of int, int32_t, int16_tShawn Landden2015-10-311-1/+1
| | | | | rework C11 utf8.[ch] to use char32_t instead of uint32_t when referring to unicode chars, to make things more expressive.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-1/+0
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* util: split out escaping code into escape.[ch]Lennart Poettering2015-10-241-0/+1
| | | | This really deserves its own file, given how much code this is now.
* util-lib: rework extract_first_word_and_warn() a bitLennart Poettering2015-10-241-9/+19
| | | | | | | | - Really warn in all error cases, not just some. We need to make sure that all errors are logged to not confuse the user. - Explicitly check for EINVAL error code before claiming anything about invalid escapes, could be ENOMEM after all.
* util: split out extract_first_word() and related calls into extract-word.[ch]Lennart Poettering2015-10-241-0/+274
This is quite a lot of code these days, hence move it to its own source file.