Fix: Error out when passing an argument to long option that takes no argument
[argpar.git] / argpar / argpar.c
index b8b7c6307d82ead3741bffe4bfc003282981aee3..b110f18a90e2432a7f9469b71851af90e834aa2c 100644 (file)
 
 #define ARGPAR_ASSERT(_cond) assert(_cond)
 
-static
+#ifdef __MINGW_PRINTF_FORMAT
+# define ARGPAR_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
+#else
+# define ARGPAR_PRINTF_FORMAT printf
+#endif
+
+static __attribute__((format(ARGPAR_PRINTF_FORMAT, 1, 0)))
 char *argpar_vasprintf(const char *fmt, va_list args)
 {
        int len1, len2;
@@ -65,7 +71,7 @@ end:
 }
 
 
-static
+static __attribute__((format(ARGPAR_PRINTF_FORMAT, 1, 2)))
 char *argpar_asprintf(const char *fmt, ...)
 {
        va_list args;
@@ -78,7 +84,7 @@ char *argpar_asprintf(const char *fmt, ...)
        return str;
 }
 
-static
+static __attribute__((format(ARGPAR_PRINTF_FORMAT, 2, 3)))
 bool argpar_string_append_printf(char **str, const char *fmt, ...)
 {
        char *new_str = NULL;
@@ -447,6 +453,15 @@ enum parse_orig_arg_opt_ret parse_long_opt(const char * const long_opt_arg,
                        opt_arg = next_orig_arg;
                        *used_next_orig_arg = true;
                }
+       } else if (eq_pos) {
+               /*
+                * Unexpected `--opt=arg` style for a long option which
+                * doesn't accept an argument.
+                */
+               argpar_string_append_printf(&parse_ret->error,
+                       "Unexpected argument for option `--%s`",
+                       long_opt_name);
+               goto error;
        }
 
        /* Create and append option argument */
This page took 0.023174 seconds and 4 git commands to generate.