This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c/503: local (stack) array corrupted after initialization



>Number:         503
>Category:       c
>Synopsis:       local (stack) array corrupted after initialization
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 02 09:16:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Pedro G. Gonnet
>Release:        gcc version 2.9.5
>Organization:
>Environment:
redhat 6.2 on a pentium3
also happened on an amdk6, redhat 6.0, gcc version ???
>Description:
three arrays of int are created on the stack and initialized with 0s. after going through a loop wich only affects two of the arrays, some of the positions in the third array are no longer 0.

i have had similar errors before - always with arrays on the stack - where the program usualy segfaults and the resulting corefile is unreadable because the stack (procedure activation frame) is corrupted. the attached file is the only time i caught this without crashing.

the attached program takes a file as input and returns to arrays. the second one should be all 0s since it was never modified - and there's the bug.
>How-To-Repeat:
gcc lastpos.c -o lastpos
lastpos lastpos.c

if the second column is not all zeros, you've got the bug.
>Fix:
if i only knew...
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="lastpos.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="lastpos.c"

I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvdHlwZXMuaD4KI2luY2x1ZGUgPHN5cy9z
dGF0Lmg+CiNpbmNsdWRlIDxzeXMvZmNudGwuaD4KCgppbnQgbWFpbiAoIGludCBhcmdjICwgY2hh
ciAqYXJndltdICkgewoKCWludCBsYXN0WzI1Nl07CglpbnQgZGlzdFsyNTZdOwoJaW50IGRpZmZb
MjU2XTsKCWludCBwb3MgPSAwOwoJaW50IGZkLCBpOwoJdW5zaWduZWQgY2hhciBjLCBsYzsKCQoJ
aWYgKGFyZ2MgPCAyKSB7CgkJcHJpbnRmKCJsYXN0cG9zOiB1c2FnZTogbGFzdHBvcyA8aW5wdXQt
ZmlsZT5cbiIpOwoJCXJldHVybiAxOwoJCX0KCQkKCWlmICgoZmQgPSBvcGVuKGFyZ3ZbMV0sT19S
RE9OTFkpKSA8IDApIHsKCQlwcmludGYoImxhc3Rwb3M6IGVycm9yIG9wZW5pbmcgZmlsZSAlcy5c
biIsYXJndlsxXSk7CgkJcmV0dXJuIDE7CgkJfQoJCQoJZm9yIChpID0gMDsgaSA8IDI1NjsgaSsr
KSB7CgkJbGFzdFtpXSA9IGk7CgkJZGlzdFtpXSA9IDA7CgkJZGlmZltpXSA9IDA7CgkJfQoJCQov
LwlsYyA9IDA7Cgl3aGlsZSAocmVhZChmZCwmYywxKSA+IDApIHsKCQlpZiAoKHBvcyAtIGxhc3Rb
Y10pID4gMjU1KQoJCQlkaXN0WzI1NV0rKzsKCQllbHNlCgkJCWRpc3RbcG9zIC0gbGFzdFtjXSAt
IDFdKys7CgkJbGFzdFtjXSA9IHBvcysrOwovLwkJZGlmZlsobGMgLSBjICsgMjU2KSAlIDI1Nl0r
KzsKLy8JCWxjID0gYzsKCQl9CgkJCgljbG9zZShmZCk7CgkJCglwcmludGYoImxhc3Rwb3M6IGdv
dCAlaSBjaGFyczpcbiIscG9zKTsKCWZvciAoaSA9IDA7IGkgPCAyNTY7IGkrKykKCQlwcmludGYo
Imxhc3Rwb3M6IGRpc3RbJTNpXSAlM2kgICBkaWZmWyUzaV0gJTNpXG4iLGksZGlzdFtpXSxpLGRp
ZmZbaV0pOwoJCQoJcmV0dXJuIDA7CgoJfQo=

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]