b3f028da2f
If the last element in the range being sorted has the smallest value, rsort can be called with last set to first-1, i.e. pointing to (what would be) the element before the first one. But with large enough element sizes and appropriate address values, this address computation can wrap around and produce a negative value for last. We need to treat such a value as being less than first, so it terminates that branch of the recursive computation. Previously, we were doing an unsigned comparison, so such a last value would be treated as greater than first and would lead to improper behavior including memory trashing. Here is an example program that can show this (depending on memory layout): #pragma memorymodel 1 #include <stdlib.h> #include <stdio.h> #define PADSIZE 2000000 /* may need to adjust based on memory size/layout */ #define N 2 struct big { int i; char pad[PADSIZE]; }; int cmp(const void *p1, const void *p2) { int a = ((struct big *)p1)->i; int b = ((struct big *)p2)->i; return (a < b) ? -1 : (a > b); } int main(void) { int j; struct big *p = malloc(sizeof(struct big) * N); if (!p) return 0; for (j = 0; j < N; j++) { p[j].i = N-j; } qsort(p, N, sizeof(struct big), cmp); for (j = 0; j < N; j++) { printf("%i\n", p[j].i); } } |
||
---|---|---|
obj | ||
LICENSE | ||
README.md | ||
assert.asm | ||
assert.macros | ||
backup | ||
cc.asm | ||
cc.macros | ||
ctype.asm | ||
equates.asm | ||
fcntl.asm | ||
fcntl.macros | ||
fenv.asm | ||
fenv.macros | ||
fpextra.asm | ||
fpextra.macros | ||
int64.asm | ||
int64.macros | ||
locale.asm | ||
locale.macros | ||
m16.int64 | ||
make | ||
math2.asm | ||
math2.macros | ||
orca.asm | ||
orca.macros | ||
setjmp.asm | ||
signal.asm | ||
signal.macros | ||
smac | ||
stdio.asm | ||
stdio.macros | ||
stdlib.asm | ||
stdlib.macros | ||
string.asm | ||
string.macros | ||
time.asm | ||
time.macros | ||
toolglue.asm | ||
toolglue.macros | ||
uchar.asm | ||
uchar.macros | ||
vars.asm | ||
vars.macros |
README.md
ORCALib
Libraries for the ORCA language suite (ORCA/C, ORCA/M, ORCA/Pascal) for the Apple IIGS
If you would like to make changes to this compiler and distribute them to others, feel free to submit them here. If the changes apply to the Apple IIGS, they will generally be approved for distribution on the master branch. For changes that retarget the library to generate code for a different platform, the project will either be forked or a new repository will be created, as appropriate.
The general conditions that must be met before a change is released on master are:
-
The modified library must compile under the currently released version of ORCA/M.
-
The various languages that make use of the library mush still pass their respective test suites, or changes to those test suites must also be submitted.
Contact support@byteworks.us if you need contributor access.
A complete distribution of the ORCA languages, including installers and documentation, is available from the Juiced GS store at https://juiced.gs/store/category/software/. It is distributed as part of the Opus ][ package.