chiark / gitweb /
shared/extract-word: replace enum with unsigned int to avoid undefined behaviour
[elogind.git] / src / basic / extract-word.c
index 9d33c7f6314cbd3a8f88ae2b5421f9789f002231..6f2959efdea9f71d9c32c9066a16b179f2962847 100644 (file)
@@ -242,7 +242,12 @@ int extract_first_word_and_warn(
         return log_syntax(unit, LOG_ERR, filename, line, r, "Unable to decode word \"%s\", ignoring: %m", rvalue);
 }
 
-int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) {
+/* We pass ExtractFlags as unsigned int (to avoid undefined behaviour when passing
+ * an object that undergoes default argument promotion as an argument to va_start).
+ * Let's make sure that ExtractFlags fits into an unsigned int. */
+assert_cc(sizeof(enum ExtractFlags) <= sizeof(unsigned));
+
+int extract_many_words(const char **p, const char *separators, unsigned flags, ...) {
         va_list ap;
         char **l;
         int n = 0, i, c, r;