Re: Possible GCC optimization bug
Anubis 1101 via Gcc-help <[email protected]> Thu, 12 Feb 2026 17:28:47 +0000
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <cv4zZ4tgcwYeIum4f0Inyq4C_ZuwSorPeK6w4M-jSHPFz4zaCueC6U2IfZ_ECFf9ioKWznoVBicDVMYHfADS8Bqw0ESQzy7y-iqJVKhVZco=@pm.me> |
Ah, see, you've just outed yourself as not actually reading the original post OR the code. The problem is NOT the out-of-bounds access- that's just a symptom. The problem is that I'm checking a constant, and that constant has a changing value, which is THEN causing that out-of-bounds access. I'm not accessing past the end of the array at all, I specifically have checks to avoid that. Please properly read posts before responding to them. Using UBSan paints over the symptom, it does nothing to address the problem. On Thursday, February 12th, 2026 at 10:10 AM, Jonathan Wakely <[email protected]> wrote: > On Thu, 12 Feb 2026 at 16:35, Anubis 1101 <[email protected]> wrote: > >> That does appear to "fix" it, but it doesn't tell me what was actually wrong. > > It tells you exactly what's wrong. You have undefined behaviour due to accessing outside an array. That causes the compiler to turn the code into garbage, because it has undefined behaviour. > >> It just corrects the bad addressing and additionally prints out "runtime error: index 10 out of bounds for type 'char [10]'"... which, yea, I know that. That's half of why I'm here. > > So stop doing it then. > >> If there's something specific I'm doing that's causing it, that's what I'd like to know. As far as I can tell, there's no flaw in my code itself. > > You're accessing data[10] when that is past the end of the array. That makes the program's behaviour undefined. Anything can happen. > > So fix it. Stop accessing past the end of the array.