Bug 103248 - piglit-util.h:308:8: error: cannot initialize a variable of type 'char *' with an rvalue of type 'const char *'
Summary: piglit-util.h:308:8: error: cannot initialize a variable of type 'char *' wit...
Status: RESOLVED FIXED
Alias: None
Product: piglit
Classification: Unclassified
Component: tests (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Mac OS X (All)
: medium normal
Assignee: Piglit Mailing List
QA Contact: Piglit Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-12 21:52 UTC by Vinson Lee
Modified: 2017-10-24 22:30 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

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.