Article View: comp.lang.misc
Article #23OOB references (Was: Robots...)
From: Mike Meyer
Date: Sat, 31 Oct 1992 05:10
Date: Sat, 31 Oct 1992 05:10
77 lines
3393 bytes
3393 bytes
In <1992Oct30.174207.22464@texhrc.uucp>, pyeatt@Texaco.com (Larry D. Pyeatt) wrote:
> In article <mwm.2gwf@contessa.palo-alto.ca.us>, mwm@contessa.palo-alto.ca.us (Mike Meyer) writes:
[Discussing OOB array references, ala:]
>
> oops, I got to thinking in Pascal mode and didn't quite make the switch.
>
> #include <stdlib.h>
> #include <stdio.h>
> typedef float mytype[26];
> main()
> { mytype mine;
> printf("%f\n",mine['a']);
> }
>
> |> You need to get a better compiler. Mine responds to the above with the
> |> message:
> |>
> |> test.c 7 Warning 83: reference beyond object size
> |>
> |> <mike
>
> What compiler are you using?
SAS/C, any version. The earlier ones tended to incorrectly flag
calculations that resulted in OOB addresses, even though they didn't
dereference them.
> I just tried it on 6 different C compilers. None of them gave any sort of
> warning. C does not do range checking. If your C compiler complains, then
> it is not a standard C compiler.
Nope, it _is_ standard C. It just isn't standard Unix C behavior. The
ANSI standard tags references to invalid addresses as having
"undefined behavior". This means poor compilers can ignore them, and
let you take your chances with your computers run-time system. Good
ones are allowed to issue compile-time warnings.
> Not only does it compile, it also runs
> without reporting a run time error.
Again, the ANSI standard allows compilers to catch such things at run
time, and "[behave in] a documented manner characteristic of the
environment." For Unix, this would be dumping core or giving wrong
answers.
With my compiler, I can get anything from the wrong answers to a
run-time requester reporting the problem and offering to take dump the
process image before terminating the process.
> No language of the Pascal family would
> let such an obvious error slip by unless the programmer specifically requested
> it.
I've played with Pascal implementation that were poor enoungh to do
so. Your average Pascal implementation wouldn't do that, though. And
yes, your average C implementation would.
> See if you get a warning on this piece of code:
>
> #include <stdlib.h>
> #include <stdio.h>
> typedef float mytype[26];
> main()
> { mytype mine;
> char tm = `a`;
> printf("%f\n",mine[tm]);
> }
Well, I get two errors for the "`"'s (they should be "'"'s). After
fixing that, I get a warning that mine is uninitialized. That's an
error your average Pascal compiler probably won't catch (at least,
they wouldn't when I was using them).
These are all questions of "quality of implementation". You need to
get a better compiler.
<mike
Technical Details
Message-ID:
<mwm.2h7x@contessa.palo-alto.ca.us>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!wupost!darwin.sura.net!haven.umd.edu!decuac!pa.dec.com!decwrl!contessa!mwmReferences:
<1992Oct18.131021.1165@kth.se> <SPACKMAN.92Oct28142448@disco-sol.dfki.uni-sb.de> <1992Oct29.163702.9849@texhrc.uucp> <mwm.2gwf@contessa.palo-alto.ca.us> <1992Oct30.174207.22464@texhrc.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!wupost!darwin.sura.net!haven.umd.edu!decuac!pa.dec.com!decwrl!contessa!mwm From: mwm@contessa.palo-alto.ca.us (Mike Meyer) Subject: OOB references (Was: Robots...) Newsgroups: comp.lang.misc Distribution: world References: <1992Oct18.131021.1165@kth.se> <SPACKMAN.92Oct28142448@disco-sol.dfki.uni-sb.de> <1992Oct29.163702.9849@texhrc.uucp> <mwm.2gwf@contessa.palo-alto.ca.us> <1992Oct30.174207.22464@texhrc.uucp> X-NewsSoftware: Amiga Yarn 3.4, 1992/08/12 15:49:52 Message-ID: <mwm.2h7x@contessa.palo-alto.ca.us> Date: 30 Oct 92 21:10:05 PST Organization: Missionaria Phonibalonica Lines: 77