Originally posted by pal666
View Post
Announcement
Collapse
No announcement yet.
GCC 12 Adds Stack Variable Auto-Initialization, Other Security Improvements Forthcoming
Collapse
X
-
Originally posted by bluescarni View PostI am dismayed that I cannot make GCC or Clang emit a warning for this code. I was sure that any compiler would complain about mixed unsigned/signed arithmetic, but apparently I was wrong.
Comment
-
Originally posted by pal666 View Postyes, you are wrong. result wouldn't change if you replace 1 with 1u. compilers warn on mixed signedness comparison, but obviously only when it could matter(not when positive signed literal is promoted to unsigned)Last edited by bluescarni; 25 September 2021, 04:22 PM.
Comment
-
Originally posted by bluescarni View PostI am just surprised that this option is not available.Last edited by pal666; 25 September 2021, 04:30 PM.
Comment
-
Originally posted by carewolf View Post
People using unsigned integers for buffer lengths. But yeah I do wonder how that would work with all the other stuff unsigned ints needs to do that does require overflow acting as prescribed.
- Likes 1
Comment
-
Originally posted by pal666 View Postand proper solution [...] ssize(vec) - 1
The only proper way is `if (vec.size() == 0) { /* just don't do this (and any subsequent code that would depends on any particular 'result' */ } else { result = vec.size() - 1; }`
Comment
-
Originally posted by uxmkt View PostThat's not a proper solution, if vec has more than SSIZE_MAX (but less than SIZE_MAX) elements.
The only proper way is `if (vec.size() == 0) { /* just don't do this (and any subsequent code that would depends on any particular 'result' */ } else { result = vec.size() - 1; }`
Comment
Comment