45a166
From e705cd1476f04a918aae34f638b502116cb12eba Mon Sep 17 00:00:00 2001
45a166
From: Jon Dufresne <jon.dufresne@gmail.com>
45a166
Date: Tue, 3 Apr 2018 20:36:09 -0700
45a166
Subject: [PATCH] Fix dereferencing type-punned pointer will break
45a166
 strict-aliasing
45a166
45a166
Compiler warning appeared as:
45a166
45a166
src/path.c:574:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
45a166
                      Py_TYPE(&item)->tp_name);
45a166
                      ^~~~~~~
45a166
45a166
As item is already of type PyObject*, and the Py_TYPE macro is
45a166
equivalent to (((PyObject*)(o))->ob_type), no need for the dereference.
45a166
45a166
https://docs.python.org/3/c-api/structures.html#c.Py_TYPE
45a166
---
45a166
 Tests/test_imagepath.py | 5 +++++
45a166
 src/path.c              | 2 +-
45a166
 2 files changed, 6 insertions(+), 1 deletion(-)
45a166
45a166
diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py
45a166
index 14cc4d14b..98a6d3416 100644
45a166
--- a/Tests/test_imagepath.py
45a166
+++ b/Tests/test_imagepath.py
45a166
@@ -17,6 +17,11 @@ def test_path(self):
45a166
         self.assertEqual(p[0], (0.0, 1.0))
45a166
         self.assertEqual(p[-1], (8.0, 9.0))
45a166
         self.assertEqual(list(p[:1]), [(0.0, 1.0)])
45a166
+        with self.assertRaises(TypeError) as cm:
45a166
+            p['foo']
45a166
+        self.assertEqual(
45a166
+            str(cm.exception),
45a166
+            "Path indices must be integers, not str")
45a166
         self.assertEqual(
45a166
             list(p),
45a166
             [(0.0, 1.0), (2.0, 3.0), (4.0, 5.0), (6.0, 7.0), (8.0, 9.0)])
45a166
diff --git a/src/path.c b/src/path.c
45a166
index b56ea838e..d1c18c8ed 100644
45a166
--- a/src/path.c
45a166
+++ b/src/path.c
45a166
@@ -571,7 +571,7 @@ path_subscript(PyPathObject* self, PyObject* item) {
45a166
     else {
45a166
         PyErr_Format(PyExc_TypeError,
45a166
                      "Path indices must be integers, not %.200s",
45a166
-                     Py_TYPE(&item)->tp_name);
45a166
+                     Py_TYPE(item)->tp_name);
45a166
         return NULL;
45a166
     }
45a166
 }