GeezerVison is showing github.com — Compiler warnings on string comparisons in _testcapi · Issue #109469 · python/cpython
Compiler warnings on string comparisons in _testcapi #109469Description./Modules/_testcapimodule.c:226:18: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(v != UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
^
./Modules/_testcapimodule.c:238:14: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(k == UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
^
./Modules/_testcapimodule.c:239:14: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(v == UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
^
4 warnings generated.
./Modules/_testcapi/dict.c:289:16: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(key == UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
^
./Modules/_testcapi/dict.c:290:18: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(value == UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
^
2 warnings generated.
./Modules/_testcapi/exceptions.c:129:17: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(type != UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
^
./Modules/_testcapi/exceptions.c:130:18: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(value != UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
^
./Modules/_testcapi/exceptions.c:131:15: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare]
assert(tb != UNINITIALIZED_PTR);
^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
Linked PRs
Activitysunmy2019 commented on Sep 16, 2023 Changing UNINITIALIZED_PTR to an invalid address literal should resolve this.
such as #define UNINITIALIZED_PTR 0xcdcdcdcdcdcdcdcd on x64. erlend-aasland commented on Sep 18, 2023 serhiy-storchaka commented on Sep 18, 2023 The point was to use valid address. On some platforms, not all bit combinations can be interpreted as address, and interpreting them as address can even lead to crash.
Does the following change help with warning?
-#define UNINITIALIZED_PTR ((void *)"uninitialized")
+static const char uninitialized[] = "uninitialized";
+#define UNINITIALIZED_PTR ((void *)uninitialized) iritkatriel commented on Sep 18, 2023
Does the following change help with warning?
-#define UNINITIALIZED_PTR ((void *)"uninitialized")
+static const char uninitialized[] = "uninitialized";
+#define UNINITIALIZED_PTR ((void *)uninitialized)
Yes. added 2 commits that reference this issue on Sep 18, 2023gh-109469: Silence compiler warnings on string comparisons in _testca… hugovk commented on Nov 9, 2023
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|