c++/7209: Faulty array dereferencing

jdbuiso@cs.vu.nl jdbuiso@cs.vu.nl
Thu Jul 4 13:36:00 GMT 2002


>Number:         7209
>Category:       c++
>Synopsis:       Faulty array dereferencing
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 04 13:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jornand de Buisonjé
>Release:        3.1
>Organization:
>Environment:
DOS (DJGPP) and Linux, both x86.
>Description:
Dereferencing an array using a ternary operation (?:) and a function return value as indices can give faulty (and variable) results. In the example code one or more of the asserts can fail (depending on the optimization level), but only when compiling as C++.
>How-To-Repeat:

>Fix:
Doing the ternary operation and/or function call before the array indexing solves (avoids) the problem.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="Bug.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Bug.cpp"

I2luY2x1ZGUgPGFzc2VydC5oPg0KDQp1bnNpZ25lZCBjaGFyIGFbMl1bMV1bMTZdPXsNCiAge3sw
eDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgw
MCwweDAwLDB4MDAsMHgwMCwweDAwfX0sDQogIHt7MHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4
MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMH19fTsN
Cg0KaW50IGYoKQ0Kew0KICByZXR1cm4gMDsNCn0NCg0KaW50IG1haW4oKQ0Kew0KICBpbnQgZD0w
Ow0KICB1bnNpZ25lZCBjaGFyKiBjMSwqIGMyOw0KICBjMT1hW2Q9PTAgPyAwIDogMV1bZigpXTsN
CiAgYzI9YVtkPT0wID8gMCA6IDFdW2YoKV07DQogIGFzc2VydCgoaW50KWE9PShpbnQpYzEpOw0K
ICBhc3NlcnQoYzE9PWMyKTsNCiAgcmV0dXJuIDA7DQp9DQo=



More information about the Gcc-bugs mailing list