On Sun, Jan 9, 2022 at 12:37 AM TK Chia <[email protected]> wrote:
>
> Hello Jim,
>
> > I think yes. It's a complete game - and since I've been playing *a lot of
> > it* in the last two weeks, I'm pretty sure it's bug-free. Let's include it
> > in FreeDOS 1.3.
>
> While trying to get Senet to build with gcc-ia16 + libi86, I came across
> a bit of a gremlin in the Senet code:
>
> for (sq = 0; (board[sq] != player) && (sq < 30); sq++); /* empty loop */
>
> with the `sq < 30' check coming after the `board[sq] != player' check.
> The problem was triggered only under gcc-ia16, not Open Watcom.
>
>
> Specifically, under gcc with optimization (e.g. -Os), the compiler
> determined that `board[sq]' with sq >= 30 would be "undefined
> behaviour".  Because of this, it decided to elide out the entire "You
> have moved all your pieces off the board" check.  (And unfortunately, it
> did not give any warning diagnostic.)  The result was that senet.exe
> would never ever declare a winner.
>

Reference:
https://sourceforge.net/p/simple-senet/code/HEAD/tree/trunk/src/senet.c#l138

That's an interesting bug. Does it still do that if you swap the
comparisons? That would make more sense anyway, because a program
should not check for a value outside the array bounds, and if sq is
not less than 30, then board[sq] is out of bounds.

Otherwise, I can add a function like count_pieces(int pl) that will
count the pieces on the board belonging to player pl, and use that in
the test on line 140 instead of
if (sq == 30) {

Jim


_______________________________________________
Freedos-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freedos-devel

Reply via email to