Re: Wired binary behavior



Ark Khasin <akhasin@xxxxxxxxxxxxxxxxxxxx> wrote:

Walter Roberson wrote:
In article <slrnfd401v.4br.spamoff@xxxxxxxxxxxxxx>,
Kris Garrett <kg@xxxxxxxxxx> wrote:
On AIX-4.3.3 using xlc v5.0, I observe the following madness:

Results in "Illegal instruction(coredump)" upon exiting (via return 0).
The program does run to completion, but looks as if it somehow returns
to a non-valid address. The wired part is that if the above code is
changed to:

The program runs to completion without coredumping on an illegal
instruction.

My question is why would the order of declarations effect the stability
of an executable? Non-deterministic behavior == a bad day.

The order of declarations affects, on most implementations, the
order in which variables are allocated on a stack. Some implementations
bother to sort by size or by alignment (in hopes of packing better),
but some just put the variables on a stack either in the order
declared or in the reverse of the ordered declared.

Therefore, if you happen to be overwriting an array or before the end
of an array or writing into free memory, whether you have allocated
a variable or not in a certain relative location in the code can
affect exactly what happens to be at the place being overwritten,
and thus can affect whether you see an obvious crash or not.

In fact, I would say - as a first, not completely informed guess - that
somewhere in the OP's [..snipped..] code he scribbles past the end of
ifxsrv[], the array in question.

If your assessment is correct, so is my claim that arrays on stack are
evil.

No, that claim is not correct. Writing past the end of an array is evil,
regardless of where and how that array is declared.

Richard
.



Relevant Pages

  • Re: how to use 1D array as a multidimensional array
    ... Do you mean those declarations literally? ... If the array size is actually fixed, as it is in your example, ... of the details of pointers and dummy arguments are quite tricky, ... you don't need the complications and side issues of this method. ...
    (comp.lang.fortran)
  • Re: Design orientated C question
    ... F1(HDC hdc,struct tagIdRoomIndex RIndex) ... when I am passing the array of structures by the calling function: ... The only things that should go in header files are structure definitions and function declarations. ... Every .cpp file that uses structure/class definitions or function declarations from a header must include that header. ...
    (microsoft.public.vc.language)
  • Re: specialized array slower than unspecialized?
    ... If the array is specialized, then every time you extract an element from ... pointers to the objects, and extracting from the array just involves ... Boxing can be avoided if you provide enough declarations that the ...
    (comp.lang.lisp)
  • Re: garbage collector pauses, help?
    ... Very heavy on floating point computations. ... Once I add declarations, I feel like ... > about no consing at all once the population of genomes is initialized ... processing step generate a new copy of the array. ...
    (comp.lang.lisp)
  • Re: NetHack SOURCE help
    ... Basic is evil. ... This being Nethack, ... could have been done with either array indexes ... Both the monster and object structures can have more than ...
    (rec.games.roguelike.nethack)