pam_wrapper: Use a constant string format specifier in test
authorUri Simchoni <uri@samba.org>
Wed, 22 Nov 2017 20:48:23 +0000 (20:48 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 24 Nov 2017 00:13:15 +0000 (01:13 +0100)
This fixes a warning about non-constant format specifier.
clang 4.0.0 warns against non-constant format specifier since
it cannot validate the format against the parameters.

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(ported from pam_wrapper 9265da3857e9cfa7a00d1ab35aae1e0b0286efad)

lib/pam_wrapper/python/pypamtest.c

index c52e1bce685c04477124f4196e4d42696e049b54..e25900f001b8e014f738fc9864d10954df0a05e0 100644 (file)
@@ -67,9 +67,9 @@ static PyObject *PyExc_PamTestError;
  *** helper functions
  **********************************************************/
 
-static const char *repr_fmt = "{ pam_operation [%d] "
-                             "expected_rv [%d] "
-                             "flags [%d] }";
+#define REPR_FMT "{ pam_operation [%d] " \
+                             "expected_rv [%d] " \
+                             "flags [%d] }"
 
 static char *py_strdup(const char *string)
 {
@@ -267,7 +267,7 @@ set_pypamtest_exception(PyObject *exc,
                        size_t num_tests)
 {
        PyObject *obj = NULL;
-       /* repr_fmt is fixed and contains just %d expansions, so this is safe */
+       /* REPR_FMT contains just %d expansions, so this is safe */
        char test_repr[256] = { '\0' };
        union {
                char *str;
@@ -286,7 +286,7 @@ set_pypamtest_exception(PyObject *exc,
        if (perr == PAMTEST_ERR_CASE) {
                failed = _pamtest_failed_case(tests, num_tests);
                if (failed) {
-                       snprintf(test_repr, sizeof(test_repr), repr_fmt,
+                       snprintf(test_repr, sizeof(test_repr), REPR_FMT,
                                 failed->pam_operation,
                                 failed->expected_rv,
                                 failed->flags);
@@ -422,7 +422,7 @@ static int TestCase_init(TestCaseObject *self,
  */
 static PyObject *TestCase_repr(TestCaseObject *self)
 {
-       return PyUnicode_FromFormat(repr_fmt,
+       return PyUnicode_FromFormat(REPR_FMT,
                                    self->pam_operation,
                                    self->expected_rv,
                                    self->flags);