Bug 103248

Summary: piglit-util.h:308:8: error: cannot initialize a variable of type 'char *' with an rvalue of type 'const char *'
Product: piglit Reporter: Vinson Lee <vlee>
Component: testsAssignee: Piglit Mailing List <piglit>
Status: RESOLVED FIXED QA Contact: Piglit Mailing List <piglit>
Severity: normal    
Priority: medium CC: emil.l.velikov
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: Mac OS X (All)   
Whiteboard:
i915 platform: i915 features:

Description Vinson Lee 2017-10-12 21:52:16 UTC
piglit: 2ed689c10431b0732e795b9497726d3da8c88f4c (master)

[  0%] Building CXX object target_api/gl/tests/util/CMakeFiles/piglitutil_gl.dir/piglit-fbo.cpp.o
In file included from piglit/tests/util/piglit-fbo.cpp:31:
In file included from piglit/tests/util/piglit-fbo.h:29:
In file included from piglit/tests/util/piglit-util-gl.h:35:
piglit/tests/util/piglit-util.h:308:8: error: cannot initialize a variable of type 'char *' with an rvalue of type 'const char *'
        char *t = strchr(s, c);
              ^   ~~~~~~~~~~~~
Comment 1 Brian Paul 2017-10-12 22:18:13 UTC
If you change the declaration to this, does that help?

const char *t = strchr(s, c);
Comment 2 Vinson Lee 2017-10-12 22:24:25 UTC
(In reply to Brian Paul from comment #1)
> If you change the declaration to this, does that help?
> 
> const char *t = strchr(s, c);

No, I get this error with that change.

piglit-util.h:310:9: error: cannot initialize return object of type 'char *' with an rvalue of type 'const char *'
        return (t == NULL) ? ((char *) s + strlen(s)) : t;
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment 3 Brian Paul 2017-10-12 22:32:12 UTC
How about this?

	return (t == NULL) ? ((char *) s + strlen(s)) : (char *) t;
Comment 4 Vinson Lee 2017-10-12 22:48:03 UTC
(In reply to Brian Paul from comment #3)
> How about this?
> 
> 	return (t == NULL) ? ((char *) s + strlen(s)) : (char *) t;

Yes, the combined two changes fixes the build error for me.

diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index c4e7818088a7..3d2fd7e0c575 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -305,9 +305,9 @@ strtol_hex(const char *nptr, char **endptr)
 static inline char *
 strchrnul(const char *s, int c)
 {
-       char *t = strchr(s, c);
+       const char *t = strchr(s, c);
 
-       return (t == NULL) ? ((char *) s + strlen(s)) : t;
+       return (t == NULL) ? ((char *) s + strlen(s)) : (char *) t;
 }
 #endif
Comment 5 Brian Paul 2017-10-13 16:31:42 UTC
Patch posted to piglit mailing list for review.
Comment 6 Brian Paul 2017-10-23 22:23:10 UTC
Vinson, I think your Reviewed-by or Tested-by would be enough for this patch.
Comment 7 Brian Paul 2017-10-24 22:30:29 UTC
Fixed with commit 3ccf44531852a2d4bf0ea0d9f5e41e2c515d3e5d

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.