intel: Avoid aliasing violation
authorMatt Turner <mattst88@gmail.com>
Tue, 23 Aug 2022 01:36:52 +0000 (21:36 -0400)
committerMatt Turner <mattst88@gmail.com>
Tue, 23 Aug 2022 22:54:15 +0000 (22:54 +0000)
../intel/test_decode.c: In function â€˜compare_batch’:
../intel/test_decode.c:109:39: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
  109 |         out = open_memstream((char **)&ptr, &size);
      |                                       ^~~~
cc1: some warnings being treated as errors

The fix is simple: just declare `ptr` as a `char *` to begin with.

intel/test_decode.c

index b9f5b92..c47752c 100644 (file)
@@ -86,7 +86,8 @@ static void
 compare_batch(struct drm_intel_decode *ctx, const char *batch_filename)
 {
        FILE *out = NULL;
-       void *ptr, *ref_ptr, *batch_ptr;
+       char *ptr;
+       void *ref_ptr, *batch_ptr;
 #if HAVE_OPEN_MEMSTREAM
        size_t size;
 #endif
@@ -106,7 +107,7 @@ compare_batch(struct drm_intel_decode *ctx, const char *batch_filename)
         * inside of an automake project's test infrastructure.
         */
 #if HAVE_OPEN_MEMSTREAM
-       out = open_memstream((char **)&ptr, &size);
+       out = open_memstream(&ptr, &size);
 #else
        fprintf(stderr, "platform lacks open_memstream, skipping.\n");
        exit(77);